You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/10/25 09:10:16 UTC

[incubator-devlake] branch main updated: fix: gitlab group projects (#6328)

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 9b748913c fix: gitlab group projects (#6328)
9b748913c is described below

commit 9b748913c7f116383fddcd6b7474b6b078033618
Author: abeizn <zi...@merico.dev>
AuthorDate: Wed Oct 25 04:10:12 2023 -0500

    fix: gitlab group projects (#6328)
    
    * fix: gitlab group projects
    
    * fix: remove unuse code
---
 backend/plugins/gitlab/api/remote.go     | 18 +++++++++++-------
 backend/plugins/gitlab/models/project.go |  8 ++++++++
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/backend/plugins/gitlab/api/remote.go b/backend/plugins/gitlab/api/remote.go
index 1f62fe665..d86cd216c 100644
--- a/backend/plugins/gitlab/api/remote.go
+++ b/backend/plugins/gitlab/api/remote.go
@@ -43,6 +43,7 @@ import (
 // @Failure 500  {object} shared.ApiBody "Internal Error"
 // @Router /plugins/gitlab/connections/{connectionId}/remote-scopes [GET]
 func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+	var resGroup []models.GroupResponse
 	return remoteHelper.GetScopesFromRemote(input,
 		func(basicRes context.BasicRes, gid string, queryData *api.RemoteQueryData, connection models.GitlabConnection) ([]models.GroupResponse, errors.Error) {
 			apiClient, err := api.NewApiClientFromConnection(gocontext.TODO(), basicRes, &connection)
@@ -66,13 +67,11 @@ func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, er
 					return nil, err
 				}
 			}
-			var resBody []models.GroupResponse
-			err = api.UnmarshalResponse(res, &resBody)
+			err = api.UnmarshalResponse(res, &resGroup)
 			if err != nil {
 				return nil, err
 			}
-
-			return resBody, err
+			return resGroup, err
 		},
 		func(basicRes context.BasicRes, gid string, queryData *api.RemoteQueryData, connection models.GitlabConnection) ([]models.GitlabApiProject, errors.Error) {
 			apiClient, err := api.NewApiClientFromConnection(gocontext.TODO(), basicRes, &connection)
@@ -94,13 +93,18 @@ func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, er
 				}
 
 				for _, project := range resProjects {
-					if project.Permissions.GroupAccess == nil {
+					skipProject := false
+					for _, group := range resGroup {
+						if project.Namespace.Name == group.Name && project.Namespace.Path == group.Path {
+							skipProject = true
+							break
+						}
+					}
+					if !skipProject {
 						resBody = append(resBody, project)
 					}
 				}
-
 			} else {
-				query.Set("with_shared", "false")
 				if gid[:6] == "group:" {
 					gid = gid[6:]
 				}
diff --git a/backend/plugins/gitlab/models/project.go b/backend/plugins/gitlab/models/project.go
index 0ed8ccad5..73b1a311e 100644
--- a/backend/plugins/gitlab/models/project.go
+++ b/backend/plugins/gitlab/models/project.go
@@ -116,6 +116,14 @@ type GitlabApiProject struct {
 	HttpUrlToRepo     string              `json:"http_url_to_repo"`
 	Archived          bool                `json:"archived"`
 	Permissions       Permissions         `json:"permissions"`
+	Namespace         struct {
+		ID       int    `json:"id"`
+		Name     string `json:"name"`
+		Path     string `json:"path"`
+		Kind     string `json:"kind"`
+		FullPath string `json:"full_path"`
+		ParentID any    `json:"parent_id"`
+	} `json:"namespace"`
 }
 
 type Permissions struct {