-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathrepos_actions_permissions.go
More file actions
230 lines (193 loc) · 9 KB
/
repos_actions_permissions.go
File metadata and controls
230 lines (193 loc) · 9 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Copyright 2022 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"fmt"
)
// ActionsPermissionsRepository represents a policy for repositories and allowed actions in a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions
type ActionsPermissionsRepository struct {
Enabled *bool `json:"enabled,omitempty"`
AllowedActions *string `json:"allowed_actions,omitempty"`
SelectedActionsURL *string `json:"selected_actions_url,omitempty"`
SHAPinningRequired *bool `json:"sha_pinning_required,omitempty"`
}
func (a ActionsPermissionsRepository) String() string {
return Stringify(a)
}
// DefaultWorkflowPermissionRepository represents the default permissions for GitHub Actions workflows for a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions
type DefaultWorkflowPermissionRepository struct {
DefaultWorkflowPermissions *string `json:"default_workflow_permissions,omitempty"`
CanApprovePullRequestReviews *bool `json:"can_approve_pull_request_reviews,omitempty"`
}
// GetActionsPermissions gets the GitHub Actions permissions policy for repositories and allowed actions in a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-github-actions-permissions-for-a-repository
//
//meta:operation GET /repos/{owner}/{repo}/actions/permissions
func (s *RepositoriesService) GetActionsPermissions(ctx context.Context, owner, repo string) (*ActionsPermissionsRepository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
permissions := new(ActionsPermissionsRepository)
resp, err := s.client.Do(ctx, req, permissions)
if err != nil {
return nil, resp, err
}
return permissions, resp, nil
}
// UpdateActionsPermissions sets the permissions policy for repositories and allowed actions in a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-github-actions-permissions-for-a-repository
//
//meta:operation PUT /repos/{owner}/{repo}/actions/permissions
func (s *RepositoriesService) UpdateActionsPermissions(ctx context.Context, owner, repo string, actionsPermissionsRepository ActionsPermissionsRepository) (*ActionsPermissionsRepository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions", owner, repo)
req, err := s.client.NewRequest("PUT", u, actionsPermissionsRepository)
if err != nil {
return nil, nil, err
}
permissions := new(ActionsPermissionsRepository)
resp, err := s.client.Do(ctx, req, permissions)
if err != nil {
return nil, resp, err
}
return permissions, resp, nil
}
// GetDefaultWorkflowPermissions gets the GitHub Actions default workflow permissions in a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-default-workflow-permissions-for-a-repository
//
//meta:operation GET /repos/{owner}/{repo}/actions/permissions/workflow
func (s *RepositoriesService) GetDefaultWorkflowPermissions(ctx context.Context, owner, repo string) (*DefaultWorkflowPermissionRepository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions/workflow", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
permissions := new(DefaultWorkflowPermissionRepository)
resp, err := s.client.Do(ctx, req, permissions)
if err != nil {
return nil, resp, err
}
return permissions, resp, nil
}
// UpdateDefaultWorkflowPermissions sets the GitHub Actions default workflow permissions in a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-default-workflow-permissions-for-a-repository
//
//meta:operation PUT /repos/{owner}/{repo}/actions/permissions/workflow
func (s *RepositoriesService) UpdateDefaultWorkflowPermissions(ctx context.Context, owner, repo string, permissions DefaultWorkflowPermissionRepository) (*DefaultWorkflowPermissionRepository, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions/workflow", owner, repo)
req, err := s.client.NewRequest("PUT", u, permissions)
if err != nil {
return nil, nil, err
}
p := new(DefaultWorkflowPermissionRepository)
resp, err := s.client.Do(ctx, req, p)
if err != nil {
return nil, resp, err
}
return p, resp, nil
}
// GetArtifactAndLogRetentionPeriod gets the artifact and log retention period for a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-artifact-and-log-retention-settings-for-a-repository
//
//meta:operation GET /repos/{owner}/{repo}/actions/permissions/artifact-and-log-retention
func (s *RepositoriesService) GetArtifactAndLogRetentionPeriod(ctx context.Context, owner, repo string) (*ArtifactPeriod, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions/artifact-and-log-retention", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
arp := new(ArtifactPeriod)
resp, err := s.client.Do(ctx, req, arp)
if err != nil {
return nil, resp, err
}
return arp, resp, nil
}
// UpdateArtifactAndLogRetentionPeriod sets the artifact and log retention period for a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-artifact-and-log-retention-settings-for-a-repository
//
//meta:operation PUT /repos/{owner}/{repo}/actions/permissions/artifact-and-log-retention
func (s *RepositoriesService) UpdateArtifactAndLogRetentionPeriod(ctx context.Context, owner, repo string, period ArtifactPeriodOpt) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions/artifact-and-log-retention", owner, repo)
req, err := s.client.NewRequest("PUT", u, period)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// GetPrivateRepoForkPRWorkflowSettings gets the settings for whether workflows from fork pull requests can run on a private repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-private-repo-fork-pr-workflow-settings-for-a-repository
//
//meta:operation GET /repos/{owner}/{repo}/actions/permissions/fork-pr-workflows-private-repos
func (s *RepositoriesService) GetPrivateRepoForkPRWorkflowSettings(ctx context.Context, owner, repo string) (*WorkflowsPermissions, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions/fork-pr-workflows-private-repos", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
permissions := new(WorkflowsPermissions)
resp, err := s.client.Do(ctx, req, permissions)
if err != nil {
return nil, resp, err
}
return permissions, resp, nil
}
// UpdatePrivateRepoForkPRWorkflowSettings sets the settings for whether workflows from fork pull requests can run on a private repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-private-repo-fork-pr-workflow-settings-for-a-repository
//
//meta:operation PUT /repos/{owner}/{repo}/actions/permissions/fork-pr-workflows-private-repos
func (s *RepositoriesService) UpdatePrivateRepoForkPRWorkflowSettings(ctx context.Context, owner, repo string, permissions *WorkflowsPermissionsOpt) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions/fork-pr-workflows-private-repos", owner, repo)
req, err := s.client.NewRequest("PUT", u, permissions)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// GetForkPRContributorApprovalPermissions gets the fork PR contributor approval policy for a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-fork-pr-contributor-approval-permissions-for-a-repository
//
//meta:operation GET /repos/{owner}/{repo}/actions/permissions/fork-pr-contributor-approval
func (s *ActionsService) GetForkPRContributorApprovalPermissions(ctx context.Context, owner, repo string) (*ContributorApprovalPermissions, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions/fork-pr-contributor-approval", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
policy := new(ContributorApprovalPermissions)
resp, err := s.client.Do(ctx, req, policy)
if err != nil {
return nil, resp, err
}
return policy, resp, nil
}
// UpdateForkPRContributorApprovalPermissions sets the fork PR contributor approval policy for a repository.
//
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-fork-pr-contributor-approval-permissions-for-a-repository
//
//meta:operation PUT /repos/{owner}/{repo}/actions/permissions/fork-pr-contributor-approval
func (s *ActionsService) UpdateForkPRContributorApprovalPermissions(ctx context.Context, owner, repo string, policy ContributorApprovalPermissions) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/actions/permissions/fork-pr-contributor-approval", owner, repo)
req, err := s.client.NewRequest("PUT", u, policy)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}