code.gitea.io/gitea@v1.22.3/services/actions/rerun.go (about)

     1  // Copyright 2024 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package actions
     5  
     6  import (
     7  	actions_model "code.gitea.io/gitea/models/actions"
     8  	"code.gitea.io/gitea/modules/container"
     9  )
    10  
    11  // GetAllRerunJobs get all jobs that need to be rerun when job should be rerun
    12  func GetAllRerunJobs(job *actions_model.ActionRunJob, allJobs []*actions_model.ActionRunJob) []*actions_model.ActionRunJob {
    13  	rerunJobs := []*actions_model.ActionRunJob{job}
    14  	rerunJobsIDSet := make(container.Set[string])
    15  	rerunJobsIDSet.Add(job.JobID)
    16  
    17  	for {
    18  		found := false
    19  		for _, j := range allJobs {
    20  			if rerunJobsIDSet.Contains(j.JobID) {
    21  				continue
    22  			}
    23  			for _, need := range j.Needs {
    24  				if rerunJobsIDSet.Contains(need) {
    25  					found = true
    26  					rerunJobs = append(rerunJobs, j)
    27  					rerunJobsIDSet.Add(j.JobID)
    28  					break
    29  				}
    30  			}
    31  		}
    32  		if !found {
    33  			break
    34  		}
    35  	}
    36  
    37  	return rerunJobs
    38  }