Skip to content

Commit 43fe8b7

Browse files
committed
WIP: Automatically close Git for Windows' milestones after a release
This is a work in progress! The idea is that as part of closing a `[New git release]` ticket that is associated with a Git for Windows release, we will close the current milestone and open the next one. The current work-in-progress script was used to successfully close the v2.44.0 milestone and open the `Next release` one. So what's missing? This: - The current script needs to be replaced by a proper route in `index.js` - More validations are needed, so that we do not close, say, a milestone that does not even have any issues assigned to it. Or a milestone that is for another version. - Tests. This will address git-for-windows#7. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 0896eab commit 43fe8b7

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

GitForWindowsHelper/milestones.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const getCurrentMilestone = async (context, token, owner, repo) => {
2+
const githubApiRequest = require('./github-api-request')
3+
const milestones = await githubApiRequest(context, token, 'GET', `/repos/${owner}/${repo}/milestones?state=open`)
4+
if (milestones.length === 2) {
5+
const filtered = milestones.filter(m => m.title !== 'Next release')
6+
if (filtered.length === 1) milestones.splice(0, 2, filtered)
7+
}
8+
if (milestones.length !== 1) throw new Error(`Expected one milestone, got ${milestones.length}`)
9+
return milestones[0]
10+
}
11+
12+
const closeMilestone = async (context, token, owner, repo, milestoneNumber, dueOn) => {
13+
const githubApiRequest = require('./github-api-request')
14+
const payload = {
15+
state: 'closed'
16+
}
17+
if (dueOn) payload.due_on = dueOn
18+
await githubApiRequest(context, token, 'PATCH', `/repos/${owner}/${repo}/milestones/${milestoneNumber}`, payload)
19+
}
20+
21+
const openNextReleaseMilestone = async (context, token, owner, repo) => {
22+
const githubApiRequest = require('./github-api-request')
23+
const milestones = await githubApiRequest(context, token, 'GET', `/repos/${owner}/${repo}/milestones?state=open`)
24+
const filtered = milestones.filter(m => m.title === 'Next release')
25+
if (filtered.length === 1) return filtered[0]
26+
27+
return await githubApiRequest(context, token, 'POST', `/repos/${owner}/${repo}/milestones`, {
28+
title: 'Next release'
29+
})
30+
}
31+
32+
module.exports = {
33+
getCurrentMilestone,
34+
closeMilestone,
35+
openNextReleaseMilestone
36+
}

test-close-and-open-milestone.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(async () => {
2+
const owner = 'git-for-windows'
3+
const repo = 'git'
4+
5+
const fs = require('fs')
6+
const localSettings = JSON.parse(fs.readFileSync('local.settings.json'))
7+
Object.entries(localSettings.Values).forEach(([key, value]) => process.env[key] = value)
8+
9+
const getInstallationIdForRepo = require('./GitForWindowsHelper/get-installation-id-for-repo')
10+
const installationId = await getInstallationIdForRepo(console, owner, repo)
11+
12+
const getInstallationAccessToken = require('./GitForWindowsHelper/get-installation-access-token')
13+
const token = await getInstallationAccessToken(console, installationId)
14+
15+
const { getCurrentMilestone, closeMilestone, openNextReleaseMilestone } = require('./GitForWindowsHelper/milestones')
16+
const current = await getCurrentMilestone(console, token, owner, repo)
17+
if (current.open_issues > 0) throw new Error(`Milestone ${current.title} has ${current.open_issues} open issue(s)!`)
18+
await closeMilestone(console, token, owner, repo, current.number, current.due_on ? false : (new Date()).toISOString())
19+
await openNextReleaseMilestone(console, token, owner, repo)
20+
})().catch(console.log)

0 commit comments

Comments
 (0)