Skip to content

Commit

Permalink
lint: reducing code complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
lsergio authored and squakez committed Aug 14, 2024
1 parent a886019 commit e77a314
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions pkg/apis/camel/v1/build_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,12 @@ func (bl BuildList) HasMatchingBuild(build *Build) (bool, *Build) {
continue
}

// handle suitable build that has started already
if b.Status.Phase == BuildPhasePending || b.Status.Phase == BuildPhaseRunning {
switch b.Status.Phase {
case BuildPhasePending, BuildPhaseRunning:
// handle suitable build that has started already
return true, &b
}

// handle suitable scheduled build
if b.Status.Phase == BuildPhaseInitialization || b.Status.Phase == BuildPhaseScheduling {
case BuildPhaseInitialization, BuildPhaseScheduling:
// handle suitable scheduled build
if allMatching && len(required) == len(dependencies) {
// seems like both builds require exactly the same list of dependencies
// additionally check for the creation timestamp
Expand All @@ -332,13 +331,9 @@ func (bl BuildList) HasMatchingBuild(build *Build) (bool, *Build) {
} else if !allMatching && commonDependencies > 0 {
// there are common dependencies. let's compare the total number of dependencies
// in each build. whichever build has less dependencies should run first
if len(dependencies) < len(required) {
if len(dependencies) < len(required) ||
len(dependencies) == len(required) && compareBuilds(&b, build) < 0 {
return true, &b
} else if len(dependencies) == len(required) {
// same number of total dependencies.
if compareBuilds(&b, build) < 0 {
return true, &b
}
}
continue
}
Expand All @@ -351,9 +346,9 @@ func (bl BuildList) HasMatchingBuild(build *Build) (bool, *Build) {
func compareBuilds(b1 *Build, b2 *Build) int {
if b1.CreationTimestamp.Before(&b2.CreationTimestamp) {
return -1
} else if b2.CreationTimestamp.Before(&b1.CreationTimestamp) {
}
if b2.CreationTimestamp.Before(&b1.CreationTimestamp) {
return 1
} else {
return strings.Compare(b1.Name, b2.Name)
}
return strings.Compare(b1.Name, b2.Name)
}

0 comments on commit e77a314

Please sign in to comment.