Skip to content

Commit

Permalink
fix: added fake support for listing teams and team members
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrachan committed Jul 9, 2019
1 parent 8adb44c commit 3a9c8fd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scm/driver/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func NewDefault() (*scm.Client, *Data) {

client.Git = &gitService{client: client, data: data}
client.Issues = &issueService{client: client, data: data}
client.Organizations = &organizationService{client: client, data: data}
client.PullRequests = &pullService{client: client, data: data}
client.Repositories = &repositoryService{client: client, data: data}
client.Reviews = &reviewService{client: client, data: data}

// TODO
/*
client.Contents = &contentService{client}
client.Organizations = &organizationService{client}
client.Users = &userService{client}
client.Webhooks = &webhookService{client}
*/
Expand Down
64 changes: 64 additions & 0 deletions scm/driver/fake/org.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package fake

import (
"context"
"fmt"

"github.com/jenkins-x/go-scm/scm"
)

const (
// RoleAll lists both members and admins
RoleAll = "all"
// RoleAdmin specifies the user is an org admin, or lists only admins
RoleAdmin = "admin"
// RoleMaintainer specifies the user is a team maintainer, or lists only maintainers
RoleMaintainer = "maintainer"
// RoleMember specifies the user is a regular user, or only lists regular users
RoleMember = "member"
// StatePending specifies the user has an invitation to the org/team.
StatePending = "pending"
// StateActive specifies the user's membership is active.
StateActive = "active"
)

type organizationService struct {
client *wrapper
data *Data
}

func (s *organizationService) Find(context.Context, string) (*scm.Organization, *scm.Response, error) {
panic("implement me")
}

func (s *organizationService) List(context.Context, scm.ListOptions) ([]*scm.Organization, *scm.Response, error) {
panic("implement me")
}

func (s *organizationService) ListTeams(ctx context.Context, org string, ops scm.ListOptions) ([]*scm.Team, *scm.Response, error) {
return []*scm.Team{
{
ID: 0,
Name: "Admins",
},
{
ID: 42,
Name: "Leads",
},
}, nil, nil
}

func (s *organizationService) ListTeamMembers(ctx context.Context, teamID int, role string, ops scm.ListOptions) ([]*scm.TeamMember, *scm.Response, error) {
if role != RoleAll {
return nil, nil, fmt.Errorf("unsupported role %v (only all supported)", role)
}
teams := map[int][]*scm.TeamMember{
0: {{Login: "default-sig-lead"}},
42: {{Login: "sig-lead"}},
}
members, ok := teams[teamID]
if !ok {
return []*scm.TeamMember{}, nil, nil
}
return members, nil, nil
}

0 comments on commit 3a9c8fd

Please sign in to comment.