Skip to content

Commit

Permalink
refactor: hudson.maven.MavenModuleSet is now treated as a scope (#7599)
Browse files Browse the repository at this point in the history
* hudson.maven.MavenModuleSet is now treated as a scope

* refactor: scope is now the default

---------

Co-authored-by: Josip Stojak <[email protected]>
  • Loading branch information
2 people authored and klesh committed Jul 16, 2024
1 parent e488b37 commit 2655e8b
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions backend/plugins/jenkins/api/remote_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2655e8b

Please sign in to comment.