Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Automatically close Git for Windows' milestones after a release #67

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions GitForWindowsHelper/milestones.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const getCurrentMilestone = async (context, token, owner, repo) => {
const githubApiRequest = require('./github-api-request')
const milestones = await githubApiRequest(context, token, 'GET', `/repos/${owner}/${repo}/milestones?state=open`)
if (milestones.length === 2) {
const filtered = milestones.filter(m => m.title !== 'Next release')
if (filtered.length === 1) milestones.splice(0, 2, filtered)
}
if (milestones.length !== 1) throw new Error(`Expected one milestone, got ${milestones.length}`)
return milestones[0]
}

const closeMilestone = async (context, token, owner, repo, milestoneNumber, dueOn) => {
const githubApiRequest = require('./github-api-request')
const payload = {
state: 'closed'
}
if (dueOn) payload.due_on = dueOn
await githubApiRequest(context, token, 'PATCH', `/repos/${owner}/${repo}/milestones/${milestoneNumber}`, payload)
}

const openNextReleaseMilestone = async (context, token, owner, repo) => {
const githubApiRequest = require('./github-api-request')
const milestones = await githubApiRequest(context, token, 'GET', `/repos/${owner}/${repo}/milestones?state=open`)
const filtered = milestones.filter(m => m.title === 'Next release')
if (filtered.length === 1) return filtered[0]

return await githubApiRequest(context, token, 'POST', `/repos/${owner}/${repo}/milestones`, {
title: 'Next release'
})
}

module.exports = {
getCurrentMilestone,
closeMilestone,
openNextReleaseMilestone
}
20 changes: 20 additions & 0 deletions test-close-and-open-milestone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(async () => {
const owner = 'git-for-windows'
const repo = 'git'

const fs = require('fs')
const localSettings = JSON.parse(fs.readFileSync('local.settings.json'))
Object.entries(localSettings.Values).forEach(([key, value]) => process.env[key] = value)

const getInstallationIdForRepo = require('./GitForWindowsHelper/get-installation-id-for-repo')
const installationId = await getInstallationIdForRepo(console, owner, repo)

const getInstallationAccessToken = require('./GitForWindowsHelper/get-installation-access-token')
const token = await getInstallationAccessToken(console, installationId)

const { getCurrentMilestone, closeMilestone, openNextReleaseMilestone } = require('./GitForWindowsHelper/milestones')
const current = await getCurrentMilestone(console, token, owner, repo)
if (current.open_issues > 0) throw new Error(`Milestone ${current.title} has ${current.open_issues} open issue(s)!`)
await closeMilestone(console, token, owner, repo, current.number, current.due_on ? false : (new Date()).toISOString())
await openNextReleaseMilestone(console, token, owner, repo)
})().catch(console.log)