forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 86
/
org.go
144 lines (127 loc) · 4.02 KB
/
org.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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) Create(context.Context, *scm.OrganizationInput) (*scm.Organization, *scm.Response, error) {
panic("implement me")
}
func (s *organizationService) Delete(context.Context, string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}
func (s *organizationService) IsMember(ctx context.Context, org string, user string) (bool, *scm.Response, error) {
panic("implement me")
}
func (s *organizationService) IsAdmin(ctx context.Context, org string, user string) (bool, *scm.Response, error) {
return user == "adminUser", &scm.Response{}, nil
}
func (s *organizationService) Find(ctx context.Context, name string) (*scm.Organization, *scm.Response, error) {
for _, org := range s.data.Organizations {
if org.Name == name {
return org, nil, nil
}
}
return nil, nil, scm.ErrNotFound
}
func (s *organizationService) List(context.Context, scm.ListOptions) ([]*scm.Organization, *scm.Response, error) {
orgs := s.data.Organizations
if orgs == nil {
// Return hardcoded organizations if none specified explicitly
for i := 0; i < 5; i++ {
org := scm.Organization{
ID: i,
Name: fmt.Sprintf("organisation%d", i),
Avatar: fmt.Sprintf("https://github.com/organisation%d.png", i),
Permissions: scm.Permissions{
MembersCreatePrivate: true,
MembersCreatePublic: true,
MembersCreateInternal: true,
},
}
orgs = append(orgs, &org)
}
}
return orgs, &scm.Response{}, nil
}
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
}
func (s *organizationService) ListOrgMembers(ctx context.Context, org string, ops scm.ListOptions) ([]*scm.TeamMember, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}
func (s *organizationService) ListPendingInvitations(_ context.Context, org string, opts scm.ListOptions) ([]*scm.OrganizationPendingInvite, *scm.Response, error) {
for _, o := range s.data.Organizations {
if o.Name == org {
return []*scm.OrganizationPendingInvite{{
ID: 123,
Login: "fred",
InviterLogin: "charles",
}}, nil, nil
}
}
return nil, nil, scm.ErrNotFound
}
func (s *organizationService) ListMemberships(ctx context.Context, opts scm.ListOptions) ([]*scm.Membership, *scm.Response, error) {
return []*scm.Membership{
{
OrganizationName: "test-org1",
State: "active",
Role: "admin",
},
{
OrganizationName: "test-org2",
State: "pending",
Role: "member",
},
}, nil, nil
}
func (s *organizationService) AcceptOrganizationInvitation(_ context.Context, org string) (*scm.Response, error) {
for _, o := range s.data.Organizations {
if o.Name == org {
return nil, nil
}
}
return nil, scm.ErrNotFound
}