@@ -606,33 +606,53 @@ func Cancel(ctx *context_module.Context) {
606606func Approve (ctx * context_module.Context ) {
607607 runIndex := getRunIndex (ctx )
608608
609- current , jobs := getRunJobs (ctx , runIndex , - 1 )
609+ approveRuns (ctx , [] int64 { runIndex } )
610610 if ctx .Written () {
611611 return
612612 }
613- run := current .Run
613+
614+ ctx .JSONOK ()
615+ }
616+
617+ func approveRuns (ctx * context_module.Context , runIndexes []int64 ) {
614618 doer := ctx .Doer
619+ repo := ctx .Repo .Repository
615620
616- var updatedJobs []* actions_model.ActionRunJob
621+ updatedJobs := make ([]* actions_model.ActionRunJob , 0 )
622+ runMap := make (map [int64 ]* actions_model.ActionRun , len (runIndexes ))
623+ runJobs := make (map [int64 ][]* actions_model.ActionRunJob , len (runIndexes ))
617624
618625 err := db .WithTx (ctx , func (ctx context.Context ) (err error ) {
619- run .NeedApproval = false
620- run .ApprovedBy = doer .ID
621- if err := actions_model .UpdateRun (ctx , run , "need_approval" , "approved_by" ); err != nil {
622- return err
623- }
624- for _ , job := range jobs {
625- job .Status , err = actions_service .PrepareToStartJobWithConcurrency (ctx , job )
626+ for _ , runIndex := range runIndexes {
627+ run , err := actions_model .GetRunByIndex (ctx , repo .ID , runIndex )
626628 if err != nil {
627629 return err
628630 }
629- if job .Status == actions_model .StatusWaiting {
630- n , err := actions_model .UpdateRunJob (ctx , job , nil , "status" )
631+ runMap [run .ID ] = run
632+ run .Repo = repo
633+ run .NeedApproval = false
634+ run .ApprovedBy = doer .ID
635+ if err := actions_model .UpdateRun (ctx , run , "need_approval" , "approved_by" ); err != nil {
636+ return err
637+ }
638+ jobs , err := actions_model .GetRunJobsByRunID (ctx , run .ID )
639+ if err != nil {
640+ return err
641+ }
642+ runJobs [run .ID ] = jobs
643+ for _ , job := range jobs {
644+ job .Status , err = actions_service .PrepareToStartJobWithConcurrency (ctx , job )
631645 if err != nil {
632646 return err
633647 }
634- if n > 0 {
635- updatedJobs = append (updatedJobs , job )
648+ if job .Status == actions_model .StatusWaiting {
649+ n , err := actions_model .UpdateRunJob (ctx , job , nil , "status" )
650+ if err != nil {
651+ return err
652+ }
653+ if n > 0 {
654+ updatedJobs = append (updatedJobs , job )
655+ }
636656 }
637657 }
638658 }
@@ -643,7 +663,9 @@ func Approve(ctx *context_module.Context) {
643663 return
644664 }
645665
646- actions_service .CreateCommitStatusForRunJobs (ctx , current .Run , jobs ... )
666+ for runID , run := range runMap {
667+ actions_service .CreateCommitStatusForRunJobs (ctx , run , runJobs [runID ]... )
668+ }
647669
648670 if len (updatedJobs ) > 0 {
649671 job := updatedJobs [0 ]
@@ -654,8 +676,6 @@ func Approve(ctx *context_module.Context) {
654676 _ = job .LoadAttributes (ctx )
655677 notify_service .WorkflowJobStatusUpdate (ctx , job .Run .Repo , job .Run .TriggerUser , job , nil )
656678 }
657-
658- ctx .JSONOK ()
659679}
660680
661681func Delete (ctx * context_module.Context ) {
@@ -818,6 +838,42 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
818838 }
819839}
820840
841+ func ApproveAllChecks (ctx * context_module.Context ) {
842+ repo := ctx .Repo .Repository
843+ commitID := ctx .FormString ("commit_id" )
844+
845+ commitStatuses , err := git_model .GetLatestCommitStatus (ctx , repo .ID , commitID , db .ListOptionsAll )
846+ if err != nil {
847+ ctx .ServerError ("GetLatestCommitStatus" , err )
848+ return
849+ }
850+ runs , err := actions_service .GetRunsFromCommitStatuses (ctx , commitStatuses )
851+ if err != nil {
852+ ctx .ServerError ("GetRunsFromCommitStatuses" , 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 .JSONOK ()
865+ return
866+ }
867+
868+ approveRuns (ctx , runIndexes )
869+ if ctx .Written () {
870+ return
871+ }
872+
873+ ctx .Flash .Success (ctx .Tr ("actions.approve_all_success" ))
874+ ctx .JSONOK ()
875+ }
876+
821877func DisableWorkflowFile (ctx * context_module.Context ) {
822878 disableOrEnableWorkflowFile (ctx , false )
823879}
0 commit comments