diff --git a/gitlab/client_repository_teamaccess.go b/gitlab/client_repository_teamaccess.go index a27e234a..ff2e9ccf 100644 --- a/gitlab/client_repository_teamaccess.go +++ b/gitlab/client_repository_teamaccess.go @@ -19,6 +19,7 @@ package gitlab import ( "context" "errors" + "strings" "github.com/dinosk/go-git-providers/gitprovider" ) @@ -80,9 +81,13 @@ func (c *TeamAccessClient) List(ctx context.Context) ([]gitprovider.TeamAccess, if err != nil { return nil, err } - + fullGroupObj, err := c.c.GetGroup(ctx, group.GroupID) + if err != nil { + return nil, err + } + // Append group by its full name with white spaces trimmed, so that it can be found in the reconciliation result = append(result, newTeamAccess(c, gitprovider.TeamAccessInfo{ - Name: group.GroupName, + Name: strings.Replace(fullGroupObj.FullName, " ", "", -1), Permission: gitProviderPermission, })) } diff --git a/gitlab/gitlabclient.go b/gitlab/gitlabclient.go index 566fb458..e6ee254f 100644 --- a/gitlab/gitlabclient.go +++ b/gitlab/gitlabclient.go @@ -37,7 +37,7 @@ type gitlabClient interface { // GetGroup is a wrapper for "GET /groups/{group}". // This function HTTP error wrapping, and validates the server result. - GetGroup(ctx context.Context, groupName string) (*gitlab.Group, error) + GetGroup(ctx context.Context, groupID interface{}) (*gitlab.Group, error) // ListGroups is a wrapper for "GET /groups". // This function handles pagination, HTTP error wrapping, and validates the server result. ListGroups(ctx context.Context) ([]*gitlab.Group, error) @@ -114,8 +114,8 @@ func (c *gitlabClientImpl) Client() *gitlab.Client { return c.c } -func (c *gitlabClientImpl) GetGroup(ctx context.Context, groupName string) (*gitlab.Group, error) { - apiObj, _, err := c.c.Groups.GetGroup(groupName, gitlab.WithContext(ctx)) +func (c *gitlabClientImpl) GetGroup(ctx context.Context, groupID interface{}) (*gitlab.Group, error) { + apiObj, _, err := c.c.Groups.GetGroup(groupID, gitlab.WithContext(ctx)) if err != nil { return nil, err } diff --git a/gitlab/integration_test.go b/gitlab/integration_test.go index e7fdcf1d..2b0fa30d 100644 --- a/gitlab/integration_test.go +++ b/gitlab/integration_test.go @@ -139,7 +139,8 @@ var _ = Describe("GitLab Provider", func() { ) BeforeSuite(func() { - gitlabToken := os.Getenv("GITLAB_TOKEN") + // gitlabToken := os.Getenv("GITLAB_TOKEN") + gitlabToken := "9ifPpQVzp7BNkGXAVzK7" if len(gitlabToken) == 0 { b, err := ioutil.ReadFile(ghTokenFile) if token := string(b); err == nil && len(token) != 0 { @@ -400,6 +401,14 @@ var _ = Describe("GitLab Provider", func() { projectTeams, err = repo.TeamAccess().List(ctx) Expect(err).ToNot(HaveOccurred()) Expect(len(projectTeams)).To(Equal(2)) + subgroupAdded := false + for _, projectTeam := range projectTeams { + if projectTeam.Get().Name == fmt.Sprintf("%s/%s", testOrgName, testSubgroupName) { + subgroupAdded = true + break + } + } + Expect(subgroupAdded).To(Equal(true)) }) It("should create, delete and reconcile deploy keys", func() {