Skip to content

Commit

Permalink
List project teams by full name
Browse files Browse the repository at this point in the history
  • Loading branch information
dinosk committed Sep 22, 2020
1 parent 2159d57 commit 1ea6993
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
9 changes: 7 additions & 2 deletions gitlab/client_repository_teamaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package gitlab
import (
"context"
"errors"
"strings"

"github.com/dinosk/go-git-providers/gitprovider"
)
Expand Down Expand Up @@ -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,
}))
}
Expand Down
6 changes: 3 additions & 3 deletions gitlab/gitlabclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 10 additions & 1 deletion gitlab/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 1ea6993

Please sign in to comment.