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

narro pushed a commit to branch fix-8523
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 28a3b41374f09a277f9935e3e7fd78aa501950e9
Author: narro wizard <[email protected]>
AuthorDate: Thu Aug 7 08:01:31 2025 +0000

    feat(gitlab): add toggle for collecting all users
    
    - Add GITLAB_SERVER_COLLECT_ALL_USERS configuration option
    - Implement logic to collect all users when enabled
    - Update task data and configuration reader to support new option
    - Modify account collector to use new option
    
    #8523
---
 backend/plugins/gitlab/impl/impl.go               |  6 +++++-
 backend/plugins/gitlab/tasks/account_collector.go |  8 ++++----
 backend/plugins/gitlab/tasks/task_data.go         | 11 ++++++-----
 env.example                                       |  5 +++++
 4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/backend/plugins/gitlab/impl/impl.go 
b/backend/plugins/gitlab/impl/impl.go
index 1d72bf052..39e245c43 100644
--- a/backend/plugins/gitlab/impl/impl.go
+++ b/backend/plugins/gitlab/impl/impl.go
@@ -207,7 +207,11 @@ func (p Gitlab) PrepareTaskData(taskCtx 
plugin.TaskContext, options map[string]i
        if err := regexEnricher.TryAdd(devops.ENV_NAME_PATTERN, 
op.ScopeConfig.EnvNamePattern); err != nil {
                return nil, errors.BadInput.Wrap(err, "invalid value for 
`envNamePattern`")
        }
-
+       cfg := taskCtx.GetConfigReader()
+       op.CollectAllUsers = true
+       if cfg.IsSet("GITLAB_SERVER_COLLECT_ALL_USERS") {
+               op.CollectAllUsers = 
cfg.GetBool("GITLAB_SERVER_COLLECT_ALL_USERS")
+       }
        taskData := tasks.GitlabTaskData{
                Options:       op,
                ApiClient:     apiClient,
diff --git a/backend/plugins/gitlab/tasks/account_collector.go 
b/backend/plugins/gitlab/tasks/account_collector.go
index e08498589..747c5d6d2 100644
--- a/backend/plugins/gitlab/tasks/account_collector.go
+++ b/backend/plugins/gitlab/tasks/account_collector.go
@@ -50,15 +50,15 @@ func CollectAccounts(taskCtx plugin.SubTaskContext) 
errors.Error {
        rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, 
RAW_USER_TABLE)
        logger := taskCtx.GetLogger()
        logger.Info("collect gitlab users")
-
-       // it means we can not use /members/all to get the data
+       options := taskCtx.GetData().(*GitlabTaskData).Options
        urlTemplate := "/projects/{{ .Params.ProjectId }}/members/all"
        if 
semver.Compare(data.ApiClient.GetData(models.GitlabApiClientData_ApiVersion).(string),
 "v13.11") < 0 {
+               // it means we can not use /members/all to get the data
                urlTemplate = "/projects/{{ .Params.ProjectId }}/members/"
        }
 
-       // Collect all users if endpoint is private gitlab instance
-       if !strings.HasPrefix(data.ApiClient.GetEndpoint(), 
"https://gitlab.com";) && !strings.HasPrefix(data.ApiClient.GetEndpoint(), 
"https://jihulab.com";) {
+       // Collect all users if endpoint is private gitlab instance and 
GITLAB_SERVER_COLLECT_ALL_USERS
+       if !strings.HasPrefix(data.ApiClient.GetEndpoint(), 
"https://gitlab.com";) && !strings.HasPrefix(data.ApiClient.GetEndpoint(), 
"https://jihulab.com";) && options.CollectAllUsers {
                urlTemplate = "/users"
        }
 
diff --git a/backend/plugins/gitlab/tasks/task_data.go 
b/backend/plugins/gitlab/tasks/task_data.go
index 1e9fa6ae1..a4c40f9cb 100644
--- a/backend/plugins/gitlab/tasks/task_data.go
+++ b/backend/plugins/gitlab/tasks/task_data.go
@@ -24,11 +24,12 @@ import (
 )
 
 type GitlabOptions struct {
-       ConnectionId  uint64                    `mapstructure:"connectionId" 
json:"connectionId"`
-       ProjectId     int                       `mapstructure:"projectId" 
json:"projectId"`
-       FullName      string                    `mapstructure:"fullName" 
json:"fullName"`
-       ScopeConfigId uint64                    `mapstructure:"scopeConfigId" 
json:"scopeConfigId"`
-       ScopeConfig   *models.GitlabScopeConfig `mapstructure:"scopeConfig" 
json:"scopeConfig"`
+       ConnectionId    uint64                    `mapstructure:"connectionId" 
json:"connectionId"`
+       ProjectId       int                       `mapstructure:"projectId" 
json:"projectId"`
+       FullName        string                    `mapstructure:"fullName" 
json:"fullName"`
+       ScopeConfigId   uint64                    `mapstructure:"scopeConfigId" 
json:"scopeConfigId"`
+       ScopeConfig     *models.GitlabScopeConfig `mapstructure:"scopeConfig" 
json:"scopeConfig"`
+       CollectAllUsers bool
 }
 
 type GitlabTaskData struct {
diff --git a/env.example b/env.example
index 44604913a..58c89de1a 100755
--- a/env.example
+++ b/env.example
@@ -69,6 +69,11 @@ ENDPOINT_CIDR_BLACKLIST=
 # Do not follow redirection when requesting data source APIs
 FORBID_REDIRECTION=false
 
+##########################
+# Plugin settings
+##########################
+GITLAB_SERVER_COLLECT_ALL_USERS=true
+
 ##########################
 # In plugin gitextractor, use go-git to collector repo's data
 ##########################

Reply via email to