Skip to content

Commit 86e5b93

Browse files
committed
add groupprivileges
1 parent a6205c6 commit 86e5b93

File tree

4 files changed

+126
-15
lines changed

4 files changed

+126
-15
lines changed

client.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ func apiBaseUrl() (*url.URL, error) {
3535
}
3636

3737
type Client struct {
38-
Auth *auth
39-
Users users
40-
User user
41-
Teams teams
42-
Repositories *Repositories
43-
Workspaces *Workspace
44-
Pagelen uint64
45-
MaxDepth uint64
46-
apiBaseURL *url.URL
38+
Auth *auth
39+
Users users
40+
User user
41+
Teams teams
42+
Repositories *Repositories
43+
Workspaces *Workspace
44+
GroupPrivileges *GroupPrivileges
45+
Pagelen uint64
46+
MaxDepth uint64
47+
apiBaseURL *url.URL
4748

4849
HttpClient *http.Client
4950
}
@@ -156,6 +157,7 @@ func injectClient(a *auth) *Client {
156157
c.User = &User{c: c}
157158
c.Teams = &Teams{c: c}
158159
c.Workspaces = &Workspace{c: c, Repositories: c.Repositories, Permissions: &Permission{c: c}}
160+
c.GroupPrivileges = &GroupPrivileges{c: c}
159161
c.HttpClient = new(http.Client)
160162
return c
161163
}

commits.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package bitbucket
22

33
import (
4-
"net/url"
54
"encoding/json"
5+
"net/url"
66
)
77

88
type Commits struct {
@@ -50,7 +50,6 @@ func (cm *Commits) RemoveApprove(cmo *CommitsOptions) (interface{}, error) {
5050
return cm.c.execute("DELETE", urlStr, "")
5151
}
5252

53-
5453
func (cm *Commits) CreateCommitStatus(cmo *CommitsOptions, cso *CommitStatusOptions) (interface{}, error) {
5554
urlStr := cm.c.requestUrl("/repositories/%s/%s/commit/%s/statuses/build", cmo.Owner, cmo.RepoSlug, cmo.Revision)
5655
data, err := json.Marshal(cso)
@@ -60,7 +59,6 @@ func (cm *Commits) CreateCommitStatus(cmo *CommitsOptions, cso *CommitStatusOpti
6059
return cm.c.execute("POST", urlStr, string(data))
6160
}
6261

63-
6462
func (cm *Commits) buildCommitsQuery(include, exclude string) string {
6563

6664
p := url.Values{}

groupprivileges.go

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package bitbucket
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/mitchellh/mapstructure"
7+
)
8+
9+
type GroupPrivileges struct {
10+
c *Client
11+
}
12+
13+
type GroupPrivilegesOptions struct {
14+
Owner string
15+
RepoSlug string
16+
Group string
17+
GroupOwner string
18+
Permission string
19+
}
20+
21+
type GroupPrivilege struct {
22+
Repo string `mapstructure:"repo"`
23+
Privilege string `mapstructure:"privilege"`
24+
Group struct {
25+
Owner struct {
26+
DisplayName string `mapstructure:"display_name"`
27+
UUID string `mapstructure:"uuid"`
28+
IsActive bool `mapstructure:"is_active"`
29+
IsTeam bool `mapstructure:"is_team"`
30+
MentionID string `mapstructure:"mention_id"`
31+
Avatar string `mapstructure:"avatar"`
32+
Nickname string `mapstructure:"nickname"`
33+
AccountID string `mapstructure:"account_id"`
34+
} `mapstructure:"owner"`
35+
Name string `mapstructure:"name"`
36+
Members []interface{} `mapstructure:"members"`
37+
Slug string `mapstructure:"slug"`
38+
} `mapstructure:"group"`
39+
Repository struct {
40+
Owner struct {
41+
DisplayName string `mapstructure:"display_name"`
42+
UUID string `mapstructure:"uuid"`
43+
IsActive bool `mapstructure:"is_active"`
44+
IsTeam bool `mapstructure:"is_team"`
45+
MentionID string `mapstructure:"mention_id"`
46+
Avatar string `mapstructure:"avatar"`
47+
Nickname string `mapstructure:"nickname"`
48+
AccountID string `mapstructure:"account_id"`
49+
} `mapstructure:"owner"`
50+
Name string `mapstructure:"name"`
51+
Slug string `mapstructure:"slug"`
52+
} `mapstructure:"repository"`
53+
}
54+
55+
func (g *GroupPrivileges) List(workspace, repoSlug string) ([]GroupPrivilege, error) {
56+
urlStr := fmt.Sprintf("%s/1.0/group-privileges/%s/%s", g.c.GetApiHostnameURL(), workspace, repoSlug)
57+
data, err := g.c.execute("GET", urlStr, "")
58+
if err != nil {
59+
return nil, err
60+
}
61+
62+
return g.decodeGroupPrivileges(data)
63+
}
64+
65+
func (g *GroupPrivileges) Add(gpo GroupPrivilegesOptions) ([]GroupPrivilege, error) {
66+
groupOwner := gpo.GroupOwner
67+
if gpo.GroupOwner == "" {
68+
groupOwner = gpo.Owner
69+
70+
}
71+
urlStr := fmt.Sprintf("%s/1.0/group-privileges/%s/%s/%s/%s/", g.c.GetApiHostnameURL(), gpo.Owner, gpo.RepoSlug, groupOwner, gpo.Group)
72+
data, err := g.c.executeContentType("PUT", urlStr, gpo.Permission, "application/x-www-form-urlencoded")
73+
if err != nil {
74+
return nil, err
75+
}
76+
77+
return g.decodeGroupPrivileges(data)
78+
}
79+
80+
func (g *GroupPrivileges) Get(gpo GroupPrivilegesOptions) ([]GroupPrivilege, error) {
81+
groupOwner := gpo.GroupOwner
82+
if gpo.GroupOwner == "" {
83+
groupOwner = gpo.Owner
84+
85+
}
86+
urlStr := fmt.Sprintf("%s/1.0/group-privileges/%s/%s/%s/%s/", g.c.GetApiHostnameURL(), gpo.Owner, gpo.RepoSlug, groupOwner, gpo.Group)
87+
data, err := g.c.execute("GET", urlStr, "")
88+
if err != nil {
89+
return nil, err
90+
}
91+
92+
return g.decodeGroupPrivileges(data)
93+
}
94+
95+
func (g *GroupPrivileges) Delete(gpo GroupPrivilegesOptions) (interface{}, error) {
96+
groupOwner := gpo.GroupOwner
97+
if gpo.GroupOwner == "" {
98+
groupOwner = gpo.Owner
99+
100+
}
101+
urlStr := fmt.Sprintf("%s/1.0/group-privileges/%s/%s/%s/%s/", g.c.GetApiHostnameURL(), gpo.Owner, gpo.RepoSlug, groupOwner, gpo.Group)
102+
return g.c.execute("DELETE", urlStr, "")
103+
}
104+
105+
func (g *GroupPrivileges) decodeGroupPrivileges(response interface{}) ([]GroupPrivilege, error) {
106+
var gp []GroupPrivilege
107+
err := mapstructure.Decode(response, &gp)
108+
if err != nil {
109+
return nil, err
110+
}
111+
return gp, nil
112+
}

teams.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ func (t *Teams) Repositories(teamname string) (interface{}, error) {
3535
}
3636

3737
func (t *Teams) Projects(teamname string) (interface{}, error) {
38-
urlStr := t.c.requestUrl("/teams/%s/projects/", teamname)
39-
return t.c.execute("GET", urlStr, "")
38+
urlStr := t.c.requestUrl("/teams/%s/projects/", teamname)
39+
return t.c.execute("GET", urlStr, "")
4040
}
41-

0 commit comments

Comments
 (0)