| 1 |
// Copyright 2022 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
) |
| 12 |
|
| 13 |
// ActionsPermissionsRepository represents a policy for repositories and allowed actions in a repository. |
| 14 |
// |
| 15 |
// GitHub API docs: https://docs.github.com/rest/actions/permissions |
| 16 |
type ActionsPermissionsRepository struct { |
| 17 |
Enabled *bool `json:"enabled,omitempty"` |
| 18 |
AllowedActions *string `json:"allowed_actions,omitempty"` |
| 19 |
SelectedActionsURL *string `json:"selected_actions_url,omitempty"` |
| 20 |
} |
| 21 |
|
| 22 |
func (a ActionsPermissionsRepository) String() string { |
| 23 |
return Stringify(a) |
| 24 |
} |
| 25 |
|
| 26 |
// DefaultWorkflowPermissionRepository represents the default permissions for GitHub Actions workflows for a repository. |
| 27 |
// |
| 28 |
// GitHub API docs: https://docs.github.com/rest/actions/permissions |
| 29 |
type DefaultWorkflowPermissionRepository struct { |
| 30 |
DefaultWorkflowPermissions *string `json:"default_workflow_permissions,omitempty"` |
| 31 |
CanApprovePullRequestReviews *bool `json:"can_approve_pull_request_reviews,omitempty"` |
| 32 |
} |
| 33 |
|
| 34 |
// GetActionsPermissions gets the GitHub Actions permissions policy for repositories and allowed actions in a repository. |
| 35 |
// |
| 36 |
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-github-actions-permissions-for-a-repository |
| 37 |
// |
| 38 |
//meta:operation GET /repos/{owner}/{repo}/actions/permissions |
| 39 |
func (s *RepositoriesService) GetActionsPermissions(ctx context.Context, owner, repo string) (*ActionsPermissionsRepository, *Response, error) { |
| 40 |
u := fmt.Sprintf("repos/%v/%v/actions/permissions", owner, repo) |
| 41 |
|
| 42 |
req, err := s.client.NewRequest("GET", u, nil) |
| 43 |
if err != nil { |
| 44 |
return nil, nil, err |
| 45 |
} |
| 46 |
|
| 47 |
permissions := new(ActionsPermissionsRepository) |
| 48 |
resp, err := s.client.Do(ctx, req, permissions) |
| 49 |
if err != nil { |
| 50 |
return nil, resp, err |
| 51 |
} |
| 52 |
|
| 53 |
return permissions, resp, nil |
| 54 |
} |
| 55 |
|
| 56 |
// EditActionsPermissions sets the permissions policy for repositories and allowed actions in a repository. |
| 57 |
// |
| 58 |
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-github-actions-permissions-for-a-repository |
| 59 |
// |
| 60 |
//meta:operation PUT /repos/{owner}/{repo}/actions/permissions |
| 61 |
func (s *RepositoriesService) EditActionsPermissions(ctx context.Context, owner, repo string, actionsPermissionsRepository ActionsPermissionsRepository) (*ActionsPermissionsRepository, *Response, error) { |
| 62 |
u := fmt.Sprintf("repos/%v/%v/actions/permissions", owner, repo) |
| 63 |
req, err := s.client.NewRequest("PUT", u, actionsPermissionsRepository) |
| 64 |
if err != nil { |
| 65 |
return nil, nil, err |
| 66 |
} |
| 67 |
|
| 68 |
permissions := new(ActionsPermissionsRepository) |
| 69 |
resp, err := s.client.Do(ctx, req, permissions) |
| 70 |
if err != nil { |
| 71 |
return nil, resp, err |
| 72 |
} |
| 73 |
|
| 74 |
return permissions, resp, nil |
| 75 |
} |
| 76 |
|
| 77 |
// GetDefaultWorkflowPermissions gets the GitHub Actions default workflow permissions in a repository. |
| 78 |
// |
| 79 |
// GitHub API docs: https://docs.github.com/rest/actions/permissions#get-default-workflow-permissions-for-a-repository |
| 80 |
// |
| 81 |
//meta:operation GET /repos/{owner}/{repo}/actions/permissions/workflow |
| 82 |
func (s *RepositoriesService) GetDefaultWorkflowPermissions(ctx context.Context, owner, repo string) (*DefaultWorkflowPermissionRepository, *Response, error) { |
| 83 |
u := fmt.Sprintf("repos/%v/%v/actions/permissions/workflow", owner, repo) |
| 84 |
|
| 85 |
req, err := s.client.NewRequest("GET", u, nil) |
| 86 |
if err != nil { |
| 87 |
return nil, nil, err |
| 88 |
} |
| 89 |
|
| 90 |
permissions := new(DefaultWorkflowPermissionRepository) |
| 91 |
resp, err := s.client.Do(ctx, req, permissions) |
| 92 |
if err != nil { |
| 93 |
return nil, resp, err |
| 94 |
} |
| 95 |
|
| 96 |
return permissions, resp, nil |
| 97 |
} |
| 98 |
|
| 99 |
// EditDefaultWorkflowPermissions sets the GitHub Actions default workflow permissions in a repository. |
| 100 |
// |
| 101 |
// GitHub API docs: https://docs.github.com/rest/actions/permissions#set-default-workflow-permissions-for-a-repository |
| 102 |
// |
| 103 |
//meta:operation PUT /repos/{owner}/{repo}/actions/permissions/workflow |
| 104 |
func (s *RepositoriesService) EditDefaultWorkflowPermissions(ctx context.Context, owner, repo string, permissions DefaultWorkflowPermissionRepository) (*DefaultWorkflowPermissionRepository, *Response, error) { |
| 105 |
u := fmt.Sprintf("repos/%v/%v/actions/permissions/workflow", owner, repo) |
| 106 |
req, err := s.client.NewRequest("PUT", u, permissions) |
| 107 |
if err != nil { |
| 108 |
return nil, nil, err |
| 109 |
} |
| 110 |
|
| 111 |
p := new(DefaultWorkflowPermissionRepository) |
| 112 |
resp, err := s.client.Do(ctx, req, p) |
| 113 |
if err != nil { |
| 114 |
return nil, resp, err |
| 115 |
} |
| 116 |
|
| 117 |
return p, resp, nil |
| 118 |
} |