@@ -258,7 +258,7 @@ func TestCreateStatus(t *testing.T) {
258258 },
259259 },
260260 {
261- name : "commit status fails on both projects but continues " ,
261+ name : "commit status fails on both projects with non-permission error skips MR comment " ,
262262 wantClient : true ,
263263 wantErr : false ,
264264 fields : fields {
@@ -270,10 +270,50 @@ func TestCreateStatus(t *testing.T) {
270270 },
271271 event : & info.Event {
272272 TriggerTarget : "pull_request" ,
273- SourceProjectID : 404 , // Will fail
274- TargetProjectID : 405 , // Will fail
273+ SourceProjectID : 400 , // Will fail with 400 (not permission error)
274+ TargetProjectID : 405 , // Will fail with 400 (not permission error)
275275 SHA : "abc123" ,
276276 },
277+ postStr : "" , // No MR comment expected for non-permission errors
278+ },
279+ },
280+ {
281+ name : "permission error 403 on source creates MR comment" ,
282+ wantClient : true ,
283+ wantErr : false ,
284+ fields : fields {
285+ targetProjectID : 100 ,
286+ },
287+ args : args {
288+ statusOpts : provider.StatusOpts {
289+ Conclusion : "success" ,
290+ },
291+ event : & info.Event {
292+ TriggerTarget : "pull_request" ,
293+ SourceProjectID : 403 , // Will fail with 403 Forbidden
294+ TargetProjectID : 400 , // Will fail with 400 (not permission error)
295+ SHA : "abc123def" ,
296+ },
297+ postStr : "has successfully" ,
298+ },
299+ },
300+ {
301+ name : "permission error 401 on source creates MR comment" ,
302+ wantClient : true ,
303+ wantErr : false ,
304+ fields : fields {
305+ targetProjectID : 100 ,
306+ },
307+ args : args {
308+ statusOpts : provider.StatusOpts {
309+ Conclusion : "success" ,
310+ },
311+ event : & info.Event {
312+ TriggerTarget : "pull_request" ,
313+ SourceProjectID : 401 , // Will fail with 401 Unauthorized
314+ TargetProjectID : 400 , // Will fail with 400 (not permission error)
315+ SHA : "abc123ghi" ,
316+ },
277317 postStr : "has successfully" ,
278318 },
279319 },
@@ -315,31 +355,47 @@ func TestCreateStatus(t *testing.T) {
315355 // Mock source project commit status endpoint
316356 sourceStatusPath := fmt .Sprintf ("/projects/%d/statuses/%s" , tt .args .event .SourceProjectID , tt .args .event .SHA )
317357 mux .HandleFunc (sourceStatusPath , func (rw http.ResponseWriter , _ * http.Request ) {
318- if tt .args .event .SourceProjectID == 404 {
319- // Simulate failure on source project
358+ switch tt .args .event .SourceProjectID {
359+ case 400 :
360+ rw .WriteHeader (http .StatusBadRequest )
361+ fmt .Fprint (rw , `{"message": "400 Bad Request"}` )
362+ case 401 :
363+ rw .WriteHeader (http .StatusUnauthorized )
364+ fmt .Fprint (rw , `{"message": "401 Unauthorized"}` )
365+ case 403 :
366+ rw .WriteHeader (http .StatusForbidden )
367+ fmt .Fprint (rw , `{"message": "403 Forbidden"}` )
368+ case 404 :
320369 rw .WriteHeader (http .StatusNotFound )
321370 fmt .Fprint (rw , `{"message": "404 Project Not Found"}` )
322- return
371+ default :
372+ rw .WriteHeader (http .StatusCreated )
373+ fmt .Fprint (rw , `{}` )
323374 }
324- // Success on source project
325- rw .WriteHeader (http .StatusCreated )
326- fmt .Fprint (rw , `{}` )
327375 })
328376 }
329377
330378 if tt .args .event .TargetProjectID != 0 {
331379 // Mock target project commit status endpoint
332380 targetStatusPath := fmt .Sprintf ("/projects/%d/statuses/%s" , tt .args .event .TargetProjectID , tt .args .event .SHA )
333381 mux .HandleFunc (targetStatusPath , func (rw http.ResponseWriter , _ * http.Request ) {
334- if tt .args .event .TargetProjectID == 404 {
335- // Simulate failure on target project
382+ switch tt .args .event .TargetProjectID {
383+ case 400 , 405 :
384+ rw .WriteHeader (http .StatusBadRequest )
385+ fmt .Fprint (rw , `{"message": "400 Bad Request"}` )
386+ case 401 :
387+ rw .WriteHeader (http .StatusUnauthorized )
388+ fmt .Fprint (rw , `{"message": "401 Unauthorized"}` )
389+ case 403 :
390+ rw .WriteHeader (http .StatusForbidden )
391+ fmt .Fprint (rw , `{"message": "403 Forbidden"}` )
392+ case 404 :
336393 rw .WriteHeader (http .StatusNotFound )
337394 fmt .Fprint (rw , `{"message": "404 Project Not Found"}` )
338- return
395+ default :
396+ rw .WriteHeader (http .StatusCreated )
397+ fmt .Fprint (rw , `{}` )
339398 }
340- // Success on target project
341- rw .WriteHeader (http .StatusCreated )
342- fmt .Fprint (rw , `{}` )
343399 })
344400 }
345401
0 commit comments