@@ -28,7 +28,9 @@ describe("check-commit-format", async () => {
2828 } )
2929
3030 afterEach ( ( ) => {
31- fs . rmSync ( path . dirname ( process . env . GITHUB_EVENT_PATH ) , { recursive : true } )
31+ if ( process . env . GITHUB_EVENT_PATH ) {
32+ fs . rmSync ( path . dirname ( process . env . GITHUB_EVENT_PATH ) , { recursive : true } )
33+ }
3234 } )
3335
3436 describe ( "on a correct commit" , async ( ) => {
@@ -132,6 +134,177 @@ describe("check-commit-format", async () => {
132134 } )
133135 } )
134136
137+ describe ( "on a merge commit" , async ( ) => {
138+ beforeEach ( ( ) => {
139+ const mockPool = githubMockPool ( )
140+
141+ mockPool . intercept ( {
142+ method : "GET" ,
143+ path : `/repos/${ GITHUB_REPOSITORY } /pulls/${ pr } /commits` ,
144+ headers : {
145+ Authorization : `token ${ token } ` ,
146+ } ,
147+ } ) . defaultReplyHeaders ( {
148+ "Content-Type" : "application/json" ,
149+ } ) . reply ( 200 , [
150+ {
151+ sha : sha ,
152+ } ,
153+ ] )
154+
155+ mockPool . intercept ( {
156+ method : "GET" ,
157+ path : `/repos/${ GITHUB_REPOSITORY } /commits/${ sha } ` ,
158+ headers : {
159+ Authorization : `token ${ token } ` ,
160+ } ,
161+ } ) . defaultReplyHeaders ( {
162+ "Content-Type" : "application/json" ,
163+ } ) . reply ( 200 , {
164+ sha : sha ,
165+ parents : [
166+ { sha : "abcdef1234567890abcdef1234567890abcdef11" } ,
167+ { sha : "abcdef1234567890abcdef1234567890abcdef12" }
168+ ] ,
169+ files : [ ] ,
170+ commit : {
171+ message : "Merge commit" ,
172+ }
173+ } )
174+
175+ mockPool . intercept ( {
176+ method : "POST" ,
177+ path : `/repos/${ GITHUB_REPOSITORY } /statuses/${ sha } ` ,
178+ headers : {
179+ Authorization : `token ${ token } ` ,
180+ } ,
181+ body : ( body ) => util . isDeepStrictEqual ( JSON . parse ( body ) , {
182+ state : "failure" ,
183+ description : `${ sha . substring ( 0 , 10 ) } has 2 parents. Please rebase against origin/HEAD.` ,
184+ context : "Commit style" ,
185+ target_url : "https://docs.brew.sh/Formula-Cookbook#commit"
186+ } ) ,
187+ } ) . defaultReplyHeaders ( {
188+ "Content-Type" : "application/json" ,
189+ } ) . reply ( 200 , { } )
190+ } )
191+
192+ it ( "fails and adds a failure label" , async ( ) => {
193+ const mockPool = githubMockPool ( )
194+
195+ mockPool . intercept ( {
196+ method : "GET" ,
197+ path : `/repos/${ GITHUB_REPOSITORY } /issues/${ pr } /labels` ,
198+ headers : {
199+ Authorization : `token ${ token } ` ,
200+ } ,
201+ } ) . defaultReplyHeaders ( {
202+ "Content-Type" : "application/json" ,
203+ } ) . reply ( 200 , [
204+ { name : "other-label" } ,
205+ ] )
206+
207+ mockPool . intercept ( {
208+ method : "PATCH" ,
209+ path : `/repos/${ GITHUB_REPOSITORY } /issues/${ pr } ` ,
210+ headers : {
211+ Authorization : `token ${ token } ` ,
212+ } ,
213+ body : ( body ) => util . isDeepStrictEqual ( JSON . parse ( body ) , {
214+ labels : [ "other-label" , failureLabel ] ,
215+ } ) ,
216+ } ) . defaultReplyHeaders ( {
217+ "Content-Type" : "application/json" ,
218+ } ) . reply ( 200 , { } )
219+
220+ await loadMain ( )
221+ } )
222+ } )
223+
224+ describe ( "on an empty commit" , async ( ) => {
225+ beforeEach ( ( ) => {
226+ const mockPool = githubMockPool ( )
227+
228+ mockPool . intercept ( {
229+ method : "GET" ,
230+ path : `/repos/${ GITHUB_REPOSITORY } /pulls/${ pr } /commits` ,
231+ headers : {
232+ Authorization : `token ${ token } ` ,
233+ } ,
234+ } ) . defaultReplyHeaders ( {
235+ "Content-Type" : "application/json" ,
236+ } ) . reply ( 200 , [
237+ {
238+ sha : sha ,
239+ } ,
240+ ] )
241+
242+ mockPool . intercept ( {
243+ method : "GET" ,
244+ path : `/repos/${ GITHUB_REPOSITORY } /commits/${ sha } ` ,
245+ headers : {
246+ Authorization : `token ${ token } ` ,
247+ } ,
248+ } ) . defaultReplyHeaders ( {
249+ "Content-Type" : "application/json" ,
250+ } ) . reply ( 200 , {
251+ sha : sha ,
252+ parents : [ { sha : "abcdef1234567890abcdef1234567890abcdef11" } ] ,
253+ files : [ ] ,
254+ commit : {
255+ message : "Empty commit" ,
256+ }
257+ } )
258+
259+ mockPool . intercept ( {
260+ method : "POST" ,
261+ path : `/repos/${ GITHUB_REPOSITORY } /statuses/${ sha } ` ,
262+ headers : {
263+ Authorization : `token ${ token } ` ,
264+ } ,
265+ body : ( body ) => util . isDeepStrictEqual ( JSON . parse ( body ) , {
266+ state : "failure" ,
267+ description : `${ sha . substring ( 0 , 10 ) } is an empty commit.` ,
268+ context : "Commit style" ,
269+ target_url : "https://docs.brew.sh/Formula-Cookbook#commit"
270+ } ) ,
271+ } ) . defaultReplyHeaders ( {
272+ "Content-Type" : "application/json" ,
273+ } ) . reply ( 200 , { } )
274+ } )
275+
276+ it ( "fails and adds a failure label" , async ( ) => {
277+ const mockPool = githubMockPool ( )
278+
279+ mockPool . intercept ( {
280+ method : "GET" ,
281+ path : `/repos/${ GITHUB_REPOSITORY } /issues/${ pr } /labels` ,
282+ headers : {
283+ Authorization : `token ${ token } ` ,
284+ } ,
285+ } ) . defaultReplyHeaders ( {
286+ "Content-Type" : "application/json" ,
287+ } ) . reply ( 200 , [
288+ { name : "other-label" } ,
289+ ] )
290+
291+ mockPool . intercept ( {
292+ method : "PATCH" ,
293+ path : `/repos/${ GITHUB_REPOSITORY } /issues/${ pr } ` ,
294+ headers : {
295+ Authorization : `token ${ token } ` ,
296+ } ,
297+ body : ( body ) => util . isDeepStrictEqual ( JSON . parse ( body ) , {
298+ labels : [ "other-label" , failureLabel ] ,
299+ } ) ,
300+ } ) . defaultReplyHeaders ( {
301+ "Content-Type" : "application/json" ,
302+ } ) . reply ( 200 , { } )
303+
304+ await loadMain ( )
305+ } )
306+ } )
307+
135308 describe ( "on an autosquashable incorrect commit" , async ( ) => {
136309 beforeEach ( ( ) => {
137310 const mockPool = githubMockPool ( )
0 commit comments