1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14 type OrganizationCustomRepoRoles struct {
15 TotalCount *int `json:"total_count,omitempty"`
16 CustomRepoRoles []*CustomRepoRoles `json:"custom_roles,omitempty"`
17 }
18
19
20
21
22 type CustomRepoRoles struct {
23 ID *int64 `json:"id,omitempty"`
24 Name *string `json:"name,omitempty"`
25 Description *string `json:"description,omitempty"`
26 BaseRole *string `json:"base_role,omitempty"`
27 Permissions []string `json:"permissions,omitempty"`
28 }
29
30
31
32
33
34 func (s *OrganizationsService) ListCustomRepoRoles(ctx context.Context, org string) (*OrganizationCustomRepoRoles, *Response, error) {
35 u := fmt.Sprintf("orgs/%v/custom-repository-roles", org)
36
37 req, err := s.client.NewRequest("GET", u, nil)
38 if err != nil {
39 return nil, nil, err
40 }
41
42 customRepoRoles := new(OrganizationCustomRepoRoles)
43 resp, err := s.client.Do(ctx, req, customRepoRoles)
44 if err != nil {
45 return nil, resp, err
46 }
47
48 return customRepoRoles, resp, nil
49 }
50
51
52 type CreateOrUpdateCustomRoleOptions struct {
53 Name *string `json:"name,omitempty"`
54 Description *string `json:"description,omitempty"`
55 BaseRole *string `json:"base_role,omitempty"`
56 Permissions []string `json:"permissions,omitempty"`
57 }
58
59
60
61
62
63 func (s *OrganizationsService) CreateCustomRepoRole(ctx context.Context, org string, opts *CreateOrUpdateCustomRoleOptions) (*CustomRepoRoles, *Response, error) {
64 u := fmt.Sprintf("orgs/%v/custom-repository-roles", org)
65
66 req, err := s.client.NewRequest("POST", u, opts)
67 if err != nil {
68 return nil, nil, err
69 }
70
71 resultingRole := new(CustomRepoRoles)
72 resp, err := s.client.Do(ctx, req, resultingRole)
73 if err != nil {
74 return nil, resp, err
75 }
76
77 return resultingRole, resp, err
78 }
79
80
81
82
83
84 func (s *OrganizationsService) UpdateCustomRepoRole(ctx context.Context, org, roleID string, opts *CreateOrUpdateCustomRoleOptions) (*CustomRepoRoles, *Response, error) {
85 u := fmt.Sprintf("orgs/%v/custom-repository-roles/%v", org, roleID)
86
87 req, err := s.client.NewRequest("PATCH", u, opts)
88 if err != nil {
89 return nil, nil, err
90 }
91
92 resultingRole := new(CustomRepoRoles)
93 resp, err := s.client.Do(ctx, req, resultingRole)
94 if err != nil {
95 return nil, resp, err
96 }
97
98 return resultingRole, resp, err
99 }
100
101
102
103
104
105 func (s *OrganizationsService) DeleteCustomRepoRole(ctx context.Context, org, roleID string) (*Response, error) {
106 u := fmt.Sprintf("orgs/%v/custom-repository-roles/%v", org, roleID)
107
108 req, err := s.client.NewRequest("DELETE", u, nil)
109 if err != nil {
110 return nil, err
111 }
112
113 resultingRole := new(CustomRepoRoles)
114 resp, err := s.client.Do(ctx, req, resultingRole)
115 if err != nil {
116 return resp, err
117 }
118
119 return resp, nil
120 }
121
View as plain text