This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch fix-gitlab-group
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/fix-gitlab-group by this push:
new 507a62c7d fix: gitlab group projects
507a62c7d is described below
commit 507a62c7d474ad3374c9ebda5f38190aab76694e
Author: abeizn <[email protected]>
AuthorDate: Wed Oct 25 15:57:03 2023 +0800
fix: gitlab group projects
---
backend/plugins/gitlab/api/remote.go | 19 ++++++++++++-------
backend/plugins/gitlab/models/project.go | 8 ++++++++
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/backend/plugins/gitlab/api/remote.go
b/backend/plugins/gitlab/api/remote.go
index 1f62fe665..69ef0d3da 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,19 @@ 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)
}
}
-
+ return resBody, nil
} 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 {