Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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