code complexity of NewPlanExecutor

Signed-off-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
Casey Lee 2020-02-17 10:30:52 -08:00
parent 60be2d67c1
commit 9651992584
No known key found for this signature in database
GPG key ID: 1899120ECD0A1784
2 changed files with 15 additions and 9 deletions

View file

@ -137,6 +137,20 @@ func (wp *workflowPlanner) GetEvents() []string {
return events
}
// MaxRunNameLen determines the max name length of all jobs
func (p *Plan) MaxRunNameLen() int {
maxRunNameLen := 0
for _, stage := range p.Stages {
for _, run := range stage.Runs {
runNameLen := len(run.String())
if runNameLen > maxRunNameLen {
maxRunNameLen = runNameLen
}
}
}
return maxRunNameLen
}
// GetJobIDs will get all the job names in the stage
func (s *Stage) GetJobIDs() []string {
names := make([]string, 0)

View file

@ -50,15 +50,7 @@ func New(runnerConfig *Config) (Runner, error) {
}
func (runner *runnerImpl) NewPlanExecutor(plan *model.Plan) common.Executor {
maxJobNameLen := 0
for _, stage := range plan.Stages {
for _, run := range stage.Runs {
jobNameLen := len(run.String())
if jobNameLen > maxJobNameLen {
maxJobNameLen = jobNameLen
}
}
}
maxJobNameLen := plan.MaxRunNameLen()
pipeline := make([]common.Executor, 0)
for _, stage := range plan.Stages {