// Copyright 2019 Drone.IO Inc. All rights reserved. // Use of this source code is governed by the Drone Non-Commercial License // that can be found in the LICENSE file. package manager import ( "github.com/drone/drone/core" ) func isBuildComplete(stages []*core.Stage) bool { for _, stage := range stages { switch stage.Status { case core.StatusPending, core.StatusRunning, core.StatusWaiting, core.StatusDeclined, core.StatusBlocked: return false } } return true } func isLastStage(stage *core.Stage, stages []*core.Stage) bool { for _, sibling := range stages { if stage.Number == sibling.Number { continue } if sibling.Updated > stage.Updated { return false } else if sibling.Updated == stage.Updated && sibling.Number > stage.Number { return false } } return true } func isDep(a *core.Stage, b *core.Stage) bool { for _, name := range b.DependsOn { if name == a.Name { return true } } return false } func areDepsComplete(stage *core.Stage, stages []*core.Stage) bool { deps := map[string]struct{}{} for _, dep := range stage.DependsOn { deps[dep] = struct{}{} } for _, sibling := range stages { if _, ok := deps[sibling.Name]; !ok { continue } if !sibling.IsDone() { return false } } return true } // helper function returns true if the current stage is the last // dependency in the tree. func isLastDep(curr, next *core.Stage, stages []*core.Stage) bool { deps := map[string]struct{}{} for _, dep := range next.DependsOn { deps[dep] = struct{}{} } for _, sibling := range stages { if _, ok := deps[sibling.Name]; !ok { continue } if sibling.Updated > curr.Updated { return false } else if sibling.Updated == curr.Updated && sibling.Number > curr.Number { return false } } return true } // helper function returns true if all dependencies are complete. func depsComplete(stage *core.Stage, siblings []*core.Stage) bool { for _, dep := range stage.DependsOn { found := false inner: for _, sibling := range siblings { if sibling.Name == dep { found = true break inner } } if !found { return false } } return true }