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

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


The following commit(s) were added to refs/heads/main by this push:
     new 0d639e4ad fix: nil pointer when gitlab scope config==nil (#6389)
0d639e4ad is described below

commit 0d639e4ad94358fea2ec95ebb42e8e21e17a7c13
Author: abeizn <[email protected]>
AuthorDate: Thu Nov 2 02:09:16 2023 -0500

    fix: nil pointer when gitlab scope config==nil (#6389)
---
 backend/plugins/gitlab/impl/impl.go | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/backend/plugins/gitlab/impl/impl.go 
b/backend/plugins/gitlab/impl/impl.go
index bf25186f9..2de57fa02 100644
--- a/backend/plugins/gitlab/impl/impl.go
+++ b/backend/plugins/gitlab/impl/impl.go
@@ -149,7 +149,6 @@ func (p Gitlab) PrepareTaskData(taskCtx plugin.TaskContext, 
options map[string]i
        if err != nil {
                return nil, err
        }
-
        if op.ProjectId != 0 {
                var scope *models.GitlabProject
                // support v100 & advance mode
@@ -181,17 +180,21 @@ func (p Gitlab) PrepareTaskData(taskCtx 
plugin.TaskContext, options map[string]i
                }
        }
 
-       if op.ScopeConfig == nil && op.ScopeConfigId != 0 {
-               var scopeConfig models.GitlabScopeConfig
-               db := taskCtx.GetDal()
-               err = db.First(&scopeConfig, dal.Where("id = ?", 
op.ScopeConfigId))
-               if err != nil {
-                       if db.IsErrorNotFound(err) {
-                               return nil, errors.Default.Wrap(err, 
fmt.Sprintf("can not find scopeConfigs by scopeConfigId [%d]", 
op.ScopeConfigId))
+       if op.ScopeConfig == nil {
+               if op.ScopeConfigId != 0 {
+                       var scopeConfig models.GitlabScopeConfig
+                       db := taskCtx.GetDal()
+                       err = db.First(&scopeConfig, dal.Where("id = ?", 
op.ScopeConfigId))
+                       if err != nil {
+                               if db.IsErrorNotFound(err) {
+                                       return nil, errors.Default.Wrap(err, 
fmt.Sprintf("can not find scopeConfigs by scopeConfigId [%d]", 
op.ScopeConfigId))
+                               }
+                               return nil, errors.Default.Wrap(err, 
fmt.Sprintf("fail to find scopeConfigs by scopeConfigId [%d]", 
op.ScopeConfigId))
                        }
-                       return nil, errors.Default.Wrap(err, fmt.Sprintf("fail 
to find scopeConfigs by scopeConfigId [%d]", op.ScopeConfigId))
+                       op.ScopeConfig = &scopeConfig
+               } else {
+                       op.ScopeConfig = &models.GitlabScopeConfig{}
                }
-               op.ScopeConfig = &scopeConfig
        }
 
        regexEnricher := helper.NewRegexEnricher()

Reply via email to