-
Notifications
You must be signed in to change notification settings - Fork 9
/
project_repository_group_permissions.go
81 lines (61 loc) · 2.14 KB
/
project_repository_group_permissions.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
package bitclient
import (
"fmt"
)
type SetRepositoryGroupPermissionRequest struct {
Name string `url:"name"`
Permission string `url:"permission"`
}
func (bc *BitClient) SetRepositoryGroupPermission(projectKey string, repositorySlug string, params SetRepositoryGroupPermissionRequest) error {
_, err := bc.DoPutUrl(
fmt.Sprintf("/projects/%s/repos/%s/permissions/groups", projectKey, repositorySlug),
params,
nil,
)
return err
}
type UnsetRepositoryGroupPermissionRequest struct {
Name string `url:"name"`
}
func (bc *BitClient) UnsetRepositoryGroupPermission(projectKey string, repositorySlug string, params UnsetRepositoryGroupPermissionRequest) error {
_, err := bc.DoDeleteUrl(
fmt.Sprintf("/projects/%s/repos/%s/permissions/groups", projectKey, repositorySlug),
params,
nil,
)
return err
}
type GetRepositoryGroupPermissionRequest struct {
PagedRequest
Filter string
}
type GetRepositoryGroupPermissionResponse struct {
PagedResponse
Values []GroupPermission
}
func (bc *BitClient) GetRepositoryGroupPermission(projectKey string, repositorySlug string, params GetRepositoryGroupPermissionRequest) (GetRepositoryGroupPermissionResponse, error) {
response := GetRepositoryGroupPermissionResponse{}
_, err := bc.DoGet(
fmt.Sprintf("/projects/%s/repos/%s/permissions/groups", projectKey, repositorySlug),
params,
&response,
)
return response, err
}
func (bc *BitClient) CloneRepositoryGroupPermissions(sourceProjectKey, sourceRepositorySlug, targetProjectKey, targetRepositorySlug string) error {
response, err := bc.GetRepositoryGroupPermission(sourceProjectKey, sourceRepositorySlug, GetRepositoryGroupPermissionRequest{})
if err != nil {
return err
}
for _, permission := range response.Values {
params := SetRepositoryGroupPermissionRequest{
Name: permission.Group.Name,
Permission: permission.Permission,
}
err := bc.SetRepositoryGroupPermission(targetProjectKey, targetRepositorySlug, params)
if err != nil {
return fmt.Errorf("error adding %s permission to group %s on %s/%s: %s", permission.Permission, permission.Group.Name, targetProjectKey, targetRepositorySlug, err)
}
}
return nil
}