Skip to content

Commit 125d095

Browse files
committed
Implement #24
1 parent 53bea73 commit 125d095

File tree

8 files changed

+73
-1
lines changed

8 files changed

+73
-1
lines changed

api/api.ts

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export interface GitHubIssue extends GitHub {
3333
unlockIssue(): Promise<void>;
3434

3535
setMilestone(milestoneId: number): Promise<void>;
36+
/**
37+
* Returns what we think the current milestone for the repo is based on the due on date.
38+
* @returns The milestone id if one is found, else undefined
39+
*/
40+
getCurrentRepoMilestone(): Promise<number | undefined>;
3641

3742
addLabel(label: string): Promise<void>;
3843
removeLabel(label: string): Promise<void>;

api/octokit.js

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/octokit.ts

+23
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,29 @@ export class OctoKitIssue extends OctoKit implements GitHubIssue {
313313
});
314314
}
315315

316+
async getCurrentRepoMilestone(): Promise<number | undefined> {
317+
safeLog(`Getting repo milestone for ${this.issueData.number}`);
318+
// Fetch all milestones open for this repo
319+
const allMilestones = (
320+
await this.octokit.issues.listMilestonesForRepo({
321+
owner: this.params.owner,
322+
repo: this.params.repo,
323+
state: 'open',
324+
sort: 'due_on',
325+
direction: 'asc',
326+
})
327+
).data;
328+
const currentDate = new Date();
329+
const possibleMilestones = allMilestones.filter(
330+
(milestone) =>
331+
new Date(milestone.due_on) > currentDate && currentDate > new Date(milestone.created_at),
332+
);
333+
if (possibleMilestones.length === 0) {
334+
return undefined;
335+
}
336+
return possibleMilestones[0].id;
337+
}
338+
316339
async *getComments(last?: boolean): AsyncIterableIterator<Comment[]> {
317340
safeLog('Fetching comments for ' + this.issueData.number);
318341

api/testbed.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/testbed.ts

+7
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ export class TestbedIssue extends Testbed implements GitHubIssue {
147147
}
148148
}
149149

150+
async getCurrentRepoMilestone(): Promise<number | undefined> {
151+
if (this.issueConfig.issue.milestone) {
152+
return this.issueConfig.issue.milestone.milestoneId;
153+
}
154+
return undefined;
155+
}
156+
150157
async getIssue(): Promise<Issue> {
151158
const labels = [...this.issueConfig.labels];
152159
return { ...this.issueConfig.issue, labels };

release-pipeline/ReleasePipeline.js

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release-pipeline/ReleasePipeline.ts

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export const enrollIssue = async (issue: GitHubIssue, notYetReleasedLabel: strin
8484
const closingHash = (await issue.getClosingInfo())?.hash;
8585
if (closingHash) {
8686
await issue.addLabel(notYetReleasedLabel);
87+
// Get the milestone linked to the current release and set it if the issue doesn't have one
88+
const releaseMilestone = (await issue.getIssue()).milestone
89+
? undefined
90+
: await issue.getCurrentRepoMilestone();
91+
if (releaseMilestone !== undefined) {
92+
await issue.setMilestone(releaseMilestone);
93+
}
8794
await trackEvent(issue, 'insiders-released:unreleased');
8895
} else {
8996
await trackEvent(issue, 'insiders-released:skipped');

release-pipeline/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ class ReleasePipelineAction extends Action {
3333
}
3434
}
3535

36-
new ReleasePipelineAction().run() // eslint-disable-line
36+
new ReleasePipelineAction().run(); // eslint-disable-line

0 commit comments

Comments
 (0)