@@ -94,7 +94,47 @@ const renameCurrentAndCreateNextMilestone = async (context, req) => {
9494 await openNextReleaseMilestone ( context , await getToken ( ) , owner , repo )
9595}
9696
97+ const closeReleaseMilestone = async ( context , req ) => {
98+ const gitVersionMatch = req . body . pull_request . title . match ( / ^ R e b a s e t o ( v \d + \. \d + \. \d + ) $ / )
99+ if ( ! gitVersionMatch ) throw new Error ( `Not a new Git version: ${ req . body . pull_request . title } ` )
100+ const gitVersion = gitVersionMatch [ 1 ]
101+
102+ const owner = 'git-for-windows'
103+ const repo = 'git'
104+ const sender = req . body . sender . login
105+
106+ const getToken = ( ( ) => {
107+ let token
108+
109+ const get = async ( ) => {
110+ const getInstallationIdForRepo = require ( './get-installation-id-for-repo' )
111+ const installationId = await getInstallationIdForRepo ( context , owner , repo )
112+ const getInstallationAccessToken = require ( './get-installation-access-token' )
113+ return await getInstallationAccessToken ( context , installationId )
114+ }
115+
116+ return async ( ) => token || ( token = await get ( ) )
117+ } ) ( )
118+
119+ const isAllowed = async ( login ) => {
120+ if ( login === 'gitforwindowshelper[bot]' ) return true
121+ const getCollaboratorPermissions = require ( './get-collaborator-permissions' )
122+ const token = await getToken ( )
123+ const permission = await getCollaboratorPermissions ( context , token , owner , repo , login )
124+ return [ 'ADMIN' , 'MAINTAIN' , 'WRITE' ] . includes ( permission . toString ( ) )
125+ }
126+
127+ if ( ! await isAllowed ( sender ) ) throw new Error ( `${ sender } is not allowed to do that` )
128+
129+ const { getMilestoneByName, closeMilestone } = require ( './milestones' )
130+ const current = await getMilestoneByName ( console , await getToken ( ) , owner , repo , gitVersion )
131+ if ( current . open_issues > 0 ) throw new Error ( `Milestone ${ current . title } has ${ current . open_issues } open issue(s)!` )
132+ if ( current . closed_issues == 0 ) throw new Error ( `Milestone ${ current . title } has no closed issue(s)!` )
133+ await closeMilestone ( context , await getToken ( ) , owner , repo , current . id )
134+ }
135+
97136module . exports = {
98137 addIssueToCurrentMilestone,
99- renameCurrentAndCreateNextMilestone
138+ renameCurrentAndCreateNextMilestone,
139+ closeReleaseMilestone
100140}
0 commit comments