This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit e77a31440761d6ac99154eb050c0c46dedfde208
Author: Luis Sergio Carneiro <luis.carne...@sensedia.com>
AuthorDate: Tue Aug 13 17:30:20 2024 -0300

    lint: reducing code complexity
---
 pkg/apis/camel/v1/build_types_support.go | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/pkg/apis/camel/v1/build_types_support.go 
b/pkg/apis/camel/v1/build_types_support.go
index da0802207..c66930f72 100644
--- a/pkg/apis/camel/v1/build_types_support.go
+++ b/pkg/apis/camel/v1/build_types_support.go
@@ -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
@@ -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
                        }
@@ -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)
 }

Reply via email to