@@ -605,33 +605,53 @@ func Cancel(ctx *context_module.Context) {
605605func  Approve (ctx  * context_module.Context ) {
606606	runIndex  :=  getRunIndex (ctx )
607607
608- 	current ,  jobs   :=   getRunJobs (ctx , runIndex ,  - 1 )
608+ 	approveRuns (ctx , [] int64 { runIndex } )
609609	if  ctx .Written () {
610610		return 
611611	}
612- 	run  :=  current .Run 
612+ 
613+ 	ctx .JSONOK ()
614+ }
615+ 
616+ func  approveRuns (ctx  * context_module.Context , runIndexes  []int64 ) {
613617	doer  :=  ctx .Doer 
618+ 	repo  :=  ctx .Repo .Repository 
614619
615- 	var  updatedJobs  []* actions_model.ActionRunJob 
620+ 	updatedJobs  :=  make ([]* actions_model.ActionRunJob , 0 )
621+ 	runMap  :=  make (map [int64 ]* actions_model.ActionRun , len (runIndexes ))
622+ 	runJobs  :=  make (map [int64 ][]* actions_model.ActionRunJob , len (runIndexes ))
616623
617624	err  :=  db .WithTx (ctx , func (ctx  context.Context ) (err  error ) {
618- 		run .NeedApproval  =  false 
619- 		run .ApprovedBy  =  doer .ID 
620- 		if  err  :=  actions_model .UpdateRun (ctx , run , "need_approval" , "approved_by" ); err  !=  nil  {
621- 			return  err 
622- 		}
623- 		for  _ , job  :=  range  jobs  {
624- 			job .Status , err  =  actions_service .PrepareToStartJobWithConcurrency (ctx , job )
625+ 		for  _ , runIndex  :=  range  runIndexes  {
626+ 			run , err  :=  actions_model .GetRunByIndex (ctx , repo .ID , runIndex )
627+ 			if  err  !=  nil  {
628+ 				return  err 
629+ 			}
630+ 			runMap [run .ID ] =  run 
631+ 			run .Repo  =  repo 
632+ 			run .NeedApproval  =  false 
633+ 			run .ApprovedBy  =  doer .ID 
634+ 			if  err  :=  actions_model .UpdateRun (ctx , run , "need_approval" , "approved_by" ); err  !=  nil  {
635+ 				return  err 
636+ 			}
637+ 			jobs , err  :=  actions_model .GetRunJobsByRunID (ctx , run .ID )
625638			if  err  !=  nil  {
626639				return  err 
627640			}
628- 			if  job .Status  ==  actions_model .StatusWaiting  {
629- 				n , err  :=  actions_model .UpdateRunJob (ctx , job , nil , "status" )
641+ 			runJobs [run .ID ] =  jobs 
642+ 			for  _ , job  :=  range  jobs  {
643+ 				job .Status , err  =  actions_service .PrepareToStartJobWithConcurrency (ctx , job )
630644				if  err  !=  nil  {
631645					return  err 
632646				}
633- 				if  n  >  0  {
634- 					updatedJobs  =  append (updatedJobs , job )
647+ 				if  job .Status  ==  actions_model .StatusWaiting  {
648+ 					n , err  :=  actions_model .UpdateRunJob (ctx , job , nil , "status" )
649+ 					if  err  !=  nil  {
650+ 						return  err 
651+ 					}
652+ 					if  n  >  0  {
653+ 						updatedJobs  =  append (updatedJobs , job )
654+ 					}
635655				}
636656			}
637657		}
@@ -642,7 +662,9 @@ func Approve(ctx *context_module.Context) {
642662		return 
643663	}
644664
645- 	actions_service .CreateCommitStatusForRunJobs (ctx , current .Run , jobs ... )
665+ 	for  runID , run  :=  range  runMap  {
666+ 		actions_service .CreateCommitStatusForRunJobs (ctx , run , runJobs [runID ]... )
667+ 	}
646668
647669	if  len (updatedJobs ) >  0  {
648670		job  :=  updatedJobs [0 ]
@@ -653,8 +675,6 @@ func Approve(ctx *context_module.Context) {
653675		_  =  job .LoadAttributes (ctx )
654676		notify_service .WorkflowJobStatusUpdate (ctx , job .Run .Repo , job .Run .TriggerUser , job , nil )
655677	}
656- 
657- 	ctx .JSONOK ()
658678}
659679
660680func  Delete (ctx  * context_module.Context ) {
@@ -817,6 +837,43 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
817837	}
818838}
819839
840+ func  ApproveAllChecks (ctx  * context_module.Context ) {
841+ 	repo  :=  ctx .Repo .Repository 
842+ 	sha  :=  ctx .FormString ("sha" )
843+ 	redirect  :=  ctx .FormString ("redirect" )
844+ 
845+ 	commitStatuses , err  :=  git_model .GetLatestCommitStatus (ctx , repo .ID , sha , db .ListOptionsAll )
846+ 	if  err  !=  nil  {
847+ 		ctx .ServerError ("GetLatestCommitStatus" , err )
848+ 		return 
849+ 	}
850+ 	runs , _ , err  :=  actions_service .GetRunsAndJobsFromCommitStatuses (ctx , commitStatuses )
851+ 	if  err  !=  nil  {
852+ 		ctx .ServerError ("GetRunsAndJobsFromCommitStatuses" , err )
853+ 		return 
854+ 	}
855+ 
856+ 	runIndexes  :=  make ([]int64 , 0 , len (runs ))
857+ 	for  _ , run  :=  range  runs  {
858+ 		if  run .NeedApproval  {
859+ 			runIndexes  =  append (runIndexes , run .Index )
860+ 		}
861+ 	}
862+ 
863+ 	if  len (runIndexes ) ==  0  {
864+ 		ctx .Redirect (redirect )
865+ 		return 
866+ 	}
867+ 
868+ 	approveRuns (ctx , runIndexes )
869+ 	if  ctx .Written () {
870+ 		return 
871+ 	}
872+ 
873+ 	ctx .Flash .Success ("Successfully approved all pending checks" )
874+ 	ctx .Redirect (redirect )
875+ }
876+ 
820877func  DisableWorkflowFile (ctx  * context_module.Context ) {
821878	disableOrEnableWorkflowFile (ctx , false )
822879}
0 commit comments