Skip to content

Commit 2be4ceb

Browse files
kleshsstojak1Josip Stojak
authored
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 <18380216+sstojak1@users.noreply.github.com> Co-authored-by: Josip Stojak <Josip.Stojak@infobip.com>
1 parent 345c209 commit 2be4ceb

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

backend/plugins/jenkins/api/remote_api.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package api
1919

2020
import (
2121
"fmt"
22+
"golang.org/x/exp/slices"
2223

2324
"github.com/apache/incubator-devlake/core/errors"
2425
"github.com/apache/incubator-devlake/core/plugin"
@@ -32,6 +33,8 @@ type JenkinsRemotePagination struct {
3233
PerPage int `json:"per_page"`
3334
}
3435

36+
var scopesWithJobs = []string{"org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject"}
37+
3538
func listJenkinsRemoteScopes(
3639
connection *models.JenkinsConnection,
3740
apiClient plugin.ApiClient,
@@ -53,13 +56,17 @@ func listJenkinsRemoteScopes(
5356
parentId = &groupId
5457
}
5558
getJobsPageCallBack := func(job *models.Job) errors.Error {
56-
switch job.Class {
57-
case "org.jenkinsci.plugins.workflow.job.WorkflowJob":
58-
fallthrough
59-
case "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject":
60-
fallthrough
61-
case "hudson.model.FreeStyleProject":
62-
// this is a scope
59+
if isGroup(job) {
60+
// This is a group
61+
job.Path = groupId
62+
children = append(children, dsmodels.DsRemoteApiScopeListEntry[models.JenkinsJob]{
63+
Type: api.RAS_ENTRY_TYPE_GROUP,
64+
Id: fmt.Sprintf("%s/job/%s", job.Path, job.Name),
65+
Name: job.Name,
66+
ParentId: parentId,
67+
})
68+
} else {
69+
// This is a scope
6370
jenkinsJob := job.ToJenkinsJob()
6471
children = append(children, dsmodels.DsRemoteApiScopeListEntry[models.JenkinsJob]{
6572
Type: api.RAS_ENTRY_TYPE_SCOPE,
@@ -69,15 +76,6 @@ func listJenkinsRemoteScopes(
6976
Data: jenkinsJob,
7077
ParentId: parentId,
7178
})
72-
default:
73-
// this is a group
74-
job.Path = groupId
75-
children = append(children, dsmodels.DsRemoteApiScopeListEntry[models.JenkinsJob]{
76-
Type: api.RAS_ENTRY_TYPE_GROUP,
77-
Id: fmt.Sprintf("%s/job/%s", job.Path, job.Name),
78-
Name: job.Name,
79-
ParentId: parentId,
80-
})
8179
}
8280

8381
return nil
@@ -95,6 +93,10 @@ func listJenkinsRemoteScopes(
9593
return
9694
}
9795

96+
func isGroup(job *models.Job) bool {
97+
return job.Jobs != nil && !slices.Contains(scopesWithJobs, job.Class)
98+
}
99+
98100
// RemoteScopes list all available scopes on the remote server
99101
// @Summary list all available scopes on the remote server
100102
// @Description list all available scopes on the remote server

0 commit comments

Comments
 (0)