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

abeizn pushed a commit to branch release-v1.0
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v1.0 by this push:
     new 2be4ceba2 refactor: hudson.maven.MavenModuleSet is now treated as a 
scope (#7599) (#7745)
2be4ceba2 is described below

commit 2be4ceba21faa75acb8452c6b3d2538d92ffb2f0
Author: Klesh Wong <[email protected]>
AuthorDate: Tue Jul 16 16:45:55 2024 +0800

    refactor: hudson.maven.MavenModuleSet is now treated as a scope (#7599) 
(#7745)
    
    * hudson.maven.MavenModuleSet is now treated as a scope
    
    * refactor: scope is now the default
    
    ---------
    
    Co-authored-by: sstojak1 <[email protected]>
    Co-authored-by: Josip Stojak <[email protected]>
---
 backend/plugins/jenkins/api/remote_api.go | 34 ++++++++++++++++---------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/backend/plugins/jenkins/api/remote_api.go 
b/backend/plugins/jenkins/api/remote_api.go
index fad6e3d61..e825fecba 100644
--- a/backend/plugins/jenkins/api/remote_api.go
+++ b/backend/plugins/jenkins/api/remote_api.go
@@ -19,6 +19,7 @@ package api
 
 import (
        "fmt"
+       "golang.org/x/exp/slices"
 
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/plugin"
@@ -32,6 +33,8 @@ type JenkinsRemotePagination struct {
        PerPage int `json:"per_page"`
 }
 
+var scopesWithJobs = 
[]string{"org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject"}
+
 func listJenkinsRemoteScopes(
        connection *models.JenkinsConnection,
        apiClient plugin.ApiClient,
@@ -53,13 +56,17 @@ func listJenkinsRemoteScopes(
                parentId = &groupId
        }
        getJobsPageCallBack := func(job *models.Job) errors.Error {
-               switch job.Class {
-               case "org.jenkinsci.plugins.workflow.job.WorkflowJob":
-                       fallthrough
-               case 
"org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject":
-                       fallthrough
-               case "hudson.model.FreeStyleProject":
-                       // this is a scope
+               if isGroup(job) {
+                       // This is a group
+                       job.Path = groupId
+                       children = append(children, 
dsmodels.DsRemoteApiScopeListEntry[models.JenkinsJob]{
+                               Type:     api.RAS_ENTRY_TYPE_GROUP,
+                               Id:       fmt.Sprintf("%s/job/%s", job.Path, 
job.Name),
+                               Name:     job.Name,
+                               ParentId: parentId,
+                       })
+               } else {
+                       // This is a scope
                        jenkinsJob := job.ToJenkinsJob()
                        children = append(children, 
dsmodels.DsRemoteApiScopeListEntry[models.JenkinsJob]{
                                Type:     api.RAS_ENTRY_TYPE_SCOPE,
@@ -69,15 +76,6 @@ func listJenkinsRemoteScopes(
                                Data:     jenkinsJob,
                                ParentId: parentId,
                        })
-               default:
-                       // this is a group
-                       job.Path = groupId
-                       children = append(children, 
dsmodels.DsRemoteApiScopeListEntry[models.JenkinsJob]{
-                               Type:     api.RAS_ENTRY_TYPE_GROUP,
-                               Id:       fmt.Sprintf("%s/job/%s", job.Path, 
job.Name),
-                               Name:     job.Name,
-                               ParentId: parentId,
-                       })
                }
 
                return nil
@@ -95,6 +93,10 @@ func listJenkinsRemoteScopes(
        return
 }
 
+func isGroup(job *models.Job) bool {
+       return job.Jobs != nil && !slices.Contains(scopesWithJobs, job.Class)
+}
+
 // RemoteScopes list all available scopes on the remote server
 // @Summary list all available scopes on the remote server
 // @Description list all available scopes on the remote server

Reply via email to