@@ -69,7 +69,24 @@ describe(addComment, () => {
6969 eventName : 'workflow_run' ,
7070 payload : {
7171 workflow_run : {
72- pull_requests : [ { number : 2 } ]
72+ head_branch : 'master' ,
73+ head_sha : '3484a3fb816e0859fd6e1cea078d76385ff50625' ,
74+ pull_requests : [
75+ {
76+ number : 2 ,
77+ head : {
78+ ref : 'other-branch' ,
79+ sha : 'different-sha'
80+ }
81+ } ,
82+ {
83+ number : 3 ,
84+ head : {
85+ ref : 'master' ,
86+ sha : '3484a3fb816e0859fd6e1cea078d76385ff50625'
87+ }
88+ }
89+ ]
7390 }
7491 }
7592 } as Readonly < WorkflowEventExtract < 'workflow_run' > > )
@@ -96,7 +113,7 @@ describe(addComment, () => {
96113 variables : {
97114 owner : 'andykenward' ,
98115 repo : 'github-actions-cloudflare-pages' ,
99- number : 2
116+ number : 3
100117 }
101118 } ,
102119 {
@@ -143,13 +160,49 @@ describe(addComment, () => {
143160 eventName : 'workflow_run' ,
144161 payload : {
145162 workflow_run : {
163+ head_branch : 'master' ,
164+ head_sha : '3484a3fb816e0859fd6e1cea078d76385ff50625' ,
146165 pull_requests : [ ]
147166 }
148167 }
149168 } as unknown as Readonly < WorkflowEventExtract < 'workflow_run' > > )
150169
151170 await expect ( addComment ( mockData , 'success' ) ) . rejects . toThrow (
152- 'No pull request number found in workflow_run event'
171+ 'No pull request found in workflow_run event matching head branch and sha'
172+ )
173+ } )
174+
175+ test ( 'should throw when workflow_run has multiple matching pull requests' , async ( ) => {
176+ expect . assertions ( 1 )
177+
178+ vi . spyOn ( Context , 'useContextEvent' ) . mockReturnValue ( {
179+ eventName : 'workflow_run' ,
180+ payload : {
181+ workflow_run : {
182+ head_branch : 'master' ,
183+ head_sha : '3484a3fb816e0859fd6e1cea078d76385ff50625' ,
184+ pull_requests : [
185+ {
186+ number : 2 ,
187+ head : {
188+ ref : 'master' ,
189+ sha : '3484a3fb816e0859fd6e1cea078d76385ff50625'
190+ }
191+ } ,
192+ {
193+ number : 3 ,
194+ head : {
195+ ref : 'master' ,
196+ sha : '3484a3fb816e0859fd6e1cea078d76385ff50625'
197+ }
198+ }
199+ ]
200+ }
201+ }
202+ } as unknown as Readonly < WorkflowEventExtract < 'workflow_run' > > )
203+
204+ await expect ( addComment ( mockData , 'success' ) ) . rejects . toThrow (
205+ 'Multiple pull requests found in workflow_run event matching head branch and sha'
153206 )
154207 } )
155208 } )
0 commit comments