@@ -67,6 +67,9 @@ let mockGitHubApiRequest = jest.fn((_context, _token, method, requestPath, paylo
6767 id : 0 ,
6868 html_url : `appended-comment-body-${ payload . body } `
6969 }
70+ if ( method === 'GET' && requestPath . endsWith ( '/comments/654321' ) ) return {
71+ body : 'The `release-git` workflow run [was started](https://github.com/git-for-windows/git-for-windows-automation/actions/runs/54321)'
72+ }
7073 if ( method === 'POST' && requestPath . endsWith ( '/reactions' ) ) return {
7174 id : `new-reaction-${ payload . content } `
7275 }
@@ -75,7 +78,7 @@ let mockGitHubApiRequest = jest.fn((_context, _token, method, requestPath, paylo
7578 data : {
7679 repository :{
7780 collaborators : {
78- edges : [ { permission : 'WRITE' } ]
81+ edges : [ { permission : 'WRITE' } ]
7982 }
8083 }
8184 }
@@ -130,6 +133,14 @@ let mockGitHubApiRequest = jest.fn((_context, _token, method, requestPath, paylo
130133 if ( method === 'GET' && requestPath . endsWith ( '/pulls/4323' ) ) return {
131134 head : { sha : 'dee501d15' }
132135 }
136+ if ( method === 'GET' && requestPath . endsWith ( '/pulls/765' ) ) return {
137+ head : { sha : 'c0ffee1ab7e' }
138+ }
139+ if ( method === 'PATCH' && requestPath . endsWith ( '/git/refs/heads/main' ) ) {
140+ if ( payload . sha !== 'c0ffee1ab7e' ) throw new Error ( `Unexpected sha: ${ payload . sha } ` )
141+ if ( payload . force !== false ) throw new Error ( `Unexpected force value: ${ payload . force } ` )
142+ return { }
143+ }
133144 if ( method === 'GET' && requestPath === '/search/issues?q=repo:git-for-windows/git+c8edb521bdabec14b07e9142e48cab77a40ba339+type:pr+%22git-artifacts%22' ) return {
134145 items : [ {
135146 text_matches : [ {
@@ -263,7 +274,16 @@ jest.mock('../GitForWindowsHelper/get-installation-id-for-repo', () => {
263274 return mockGetInstallationIDForRepo
264275} )
265276
266- let mockSearchIssues = jest . fn ( ( ) => [ ] )
277+ let mockSearchIssues = jest . fn ( ( _context , searchTerms ) => {
278+ if ( searchTerms . indexOf ( 'release-git' ) > 0 ) return [ {
279+ number : 765 ,
280+ author_association : 'MEMBER' ,
281+ text_matches : [ {
282+ object_url : 'https://api.github.com/repos/git-for-windows/git/issues/comments/654321'
283+ } ]
284+ } ]
285+ return [ ]
286+ } )
267287jest . mock ( '../GitForWindowsHelper/search' , ( ) => {
268288 return {
269289 searchIssues : mockSearchIssues
@@ -753,3 +773,43 @@ The \`release-git\` workflow run [was started](dispatched-workflow-release-git.y
753773 git_artifacts_i686_workflow_run_id : "686"
754774 } )
755775} )
776+
777+ test ( 'a completed `release-git` run updates the `main` branch in git-for-windows/git' , async ( ) => {
778+ const context = makeContext ( {
779+ action : 'completed' ,
780+ repository : {
781+ full_name : 'git-for-windows/git-for-windows-automation'
782+ } ,
783+ sender : {
784+ login : 'a-member'
785+ } ,
786+ workflow_run : {
787+ id : 54321 ,
788+ path : '.github/workflows/release-git.yml' ,
789+ conclusion : 'success'
790+ }
791+ } , {
792+ 'x-github-event' : 'workflow_run'
793+ } )
794+
795+ try {
796+ expect ( await index ( context , context . req ) ) . toBeUndefined ( )
797+ expect ( context . res ) . toEqual ( {
798+ body : `Took care of pushing the \`main\` branch to close PR 765` ,
799+ headers : undefined ,
800+ status : undefined
801+ } )
802+ expect ( mockGitHubApiRequest ) . toHaveBeenCalledTimes ( 4 )
803+ expect ( mockGitHubApiRequest . mock . calls [ 3 ] . slice ( 1 ) ) . toEqual ( [
804+ 'installation-access-token' ,
805+ 'PATCH' ,
806+ '/repos/git-for-windows/git/git/refs/heads/main' , {
807+ sha : 'c0ffee1ab7e' ,
808+ force : false
809+ }
810+ ] )
811+ } catch ( e ) {
812+ context . log . mock . calls . forEach ( e => console . log ( e [ 0 ] ) )
813+ throw e ;
814+ }
815+ } )
0 commit comments