Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions GitForWindowsHelper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ module.exports = async function (context, req) {
return withStatus(500, undefined, e.message || JSON.stringify(e, null, 2))
}

try {
const {renameCurrentAndCreateNextMilestone} = require('./update-milestones')
if (req.headers['x-github-event'] === 'pull_request'
&& req.body.repository.full_name === 'git-for-windows/git'
&& req.body.action === 'opened'
&& req.body.pull_request.merged === 'true') return ok(await renameCurrentAndCreateNextMilestone(context, req))
} catch (e) {
context.log(e)
return withStatus(500, undefined, e.message || JSON.stringify(e, null, 2))
}

Comment on lines +75 to +85
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather do that when publishing the final release, i.e. at the same time as the current milestone is closed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would prevent issues with late component updates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it the other way round? When a final rebase PR is opened, and /git-artifacts produces an installer that has issues that require a component-update ticket to be addressed, we'd still want that in the same milestone, right?

try {
const { cascadingRuns, handlePush } = require('./cascading-runs.js')
if (req.headers['x-github-event'] === 'check_run'
Expand Down
38 changes: 38 additions & 0 deletions GitForWindowsHelper/update-milestones.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,45 @@ const addIssueToCurrentMilestone= async (context, req) => {
throw new Error(`Issue ${issueNumber} isn't a component update`)
}

const renameCurrentAndCreateNextMilestone = async (context, req) => {
const gitVersionMatch = req.body.pull_request.title.match(/^Rebase to (v\d+\.\d+\.\d+)$/)
if (!gitVersionMatch) throw new Error(`Not a new Git version: ${req.body.pull_request.title}`)
const gitVersion = gitVersionMatch[1]

const owner = 'git-for-windows'
const repo = 'git'
const sender = req.body.sender.login

const getToken = (() => {
let token

const get = async () => {
const getInstallationIdForRepo = require('./get-installation-id-for-repo')
const installationId = await getInstallationIdForRepo(context, owner, repo)
const getInstallationAccessToken = require('./get-installation-access-token')
return await getInstallationAccessToken(context, installationId)
}

return async () => token || (token = await get())
})()

const isAllowed = async (login) => {
if (login === 'gitforwindowshelper[bot]') return true
const getCollaboratorPermissions = require('./get-collaborator-permissions')
const token = await getToken()
const permission = await getCollaboratorPermissions(context, token, owner, repo, login)
return ['ADMIN', 'MAINTAIN', 'WRITE'].includes(permission.toString())
}

if (!await isAllowed(sender)) throw new Error(`${sender} is not allowed to do that`)

const { getCurrentMilestone, renameMilestone, openNextReleaseMilestone } = require('./milestones')
const current = await getCurrentMilestone(console, await getToken(), owner, repo)
await renameMilestone(context, await getToken(), owner, repo,current.id, gitVersion)
await openNextReleaseMilestone(context, await getToken(), owner, repo)
}

module.exports = {
addIssueToCurrentMilestone,
renameCurrentAndCreateNextMilestone
}