@@ -56,7 +56,45 @@ const addIssueToCurrentMilestone= async (context, req) => {
5656 throw new Error ( `Issue ${ issueNumber } isn't a component update` )
5757}
5858
59+ const renameCurrentAndCreateNextMilestone = async ( context , req ) => {
60+ const gitVersionMatch = req . body . pull_request . title . match ( / ^ R e b a s e t o ( v \d + \. \d + \. \d + ) $ / )
61+ if ( ! gitVersionMatch ) throw new Error ( `Not a new Git version: ${ req . body . pull_request . title } ` )
62+ const gitVersion = gitVersionMatch [ 1 ]
63+
64+ const owner = 'git-for-windows'
65+ const repo = 'git'
66+ const sender = req . body . sender . login
67+
68+ const getToken = ( ( ) => {
69+ let token
70+
71+ const get = async ( ) => {
72+ const getInstallationIdForRepo = require ( './get-installation-id-for-repo' )
73+ const installationId = await getInstallationIdForRepo ( context , owner , repo )
74+ const getInstallationAccessToken = require ( './get-installation-access-token' )
75+ return await getInstallationAccessToken ( context , installationId )
76+ }
77+
78+ return async ( ) => token || ( token = await get ( ) )
79+ } ) ( )
80+
81+ const isAllowed = async ( login ) => {
82+ if ( login === 'gitforwindowshelper[bot]' ) return true
83+ const getCollaboratorPermissions = require ( './get-collaborator-permissions' )
84+ const token = await getToken ( )
85+ const permission = await getCollaboratorPermissions ( context , token , owner , repo , login )
86+ return [ 'ADMIN' , 'MAINTAIN' , 'WRITE' ] . includes ( permission . toString ( ) )
87+ }
88+
89+ if ( ! await isAllowed ( sender ) ) throw new Error ( `${ sender } is not allowed to do that` )
90+
91+ const { getCurrentMilestone, renameMilestone, openNextReleaseMilestone } = require ( './milestones' )
92+ const current = await getCurrentMilestone ( console , await getToken ( ) , owner , repo )
93+ await renameMilestone ( context , await getToken ( ) , owner , repo , current . id , gitVersion )
94+ await openNextReleaseMilestone ( context , await getToken ( ) , owner , repo )
95+ }
5996
6097module . exports = {
6198 addIssueToCurrentMilestone,
99+ renameCurrentAndCreateNextMilestone
62100}
0 commit comments