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
|
// Copyright 2023 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"
)
// DeploymentBranchPolicy represents a single deployment branch policy for an environment.
type DeploymentBranchPolicy struct {
Name *string `json:"name,omitempty"`
ID *int64 `json:"id,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Type *string `json:"type,omitempty"`
}
// DeploymentBranchPolicyResponse represents the slightly different format of response that comes back when you list deployment branch policies.
type DeploymentBranchPolicyResponse struct {
TotalCount *int `json:"total_count,omitempty"`
BranchPolicies []*DeploymentBranchPolicy `json:"branch_policies,omitempty"`
}
// DeploymentBranchPolicyRequest represents a deployment branch policy request.
type DeploymentBranchPolicyRequest struct {
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
}
// ListDeploymentBranchPolicies lists the deployment branch policies for an environment.
//
// GitHub API docs: https://docs.github.com/rest/deployments/branch-policies#list-deployment-branch-policies
//
//meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies
func (s *RepositoriesService) ListDeploymentBranchPolicies(ctx context.Context, owner, repo, environment string) (*DeploymentBranchPolicyResponse, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment-branch-policies", owner, repo, environment)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var list *DeploymentBranchPolicyResponse
resp, err := s.client.Do(ctx, req, &list)
if err != nil {
return nil, resp, err
}
return list, resp, nil
}
// GetDeploymentBranchPolicy gets a deployment branch policy for an environment.
//
// GitHub API docs: https://docs.github.com/rest/deployments/branch-policies#get-a-deployment-branch-policy
//
//meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}
func (s *RepositoriesService) GetDeploymentBranchPolicy(ctx context.Context, owner, repo, environment string, branchPolicyID int64) (*DeploymentBranchPolicy, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment-branch-policies/%v", owner, repo, environment, branchPolicyID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var policy *DeploymentBranchPolicy
resp, err := s.client.Do(ctx, req, &policy)
if err != nil {
return nil, resp, err
}
return policy, resp, nil
}
// CreateDeploymentBranchPolicy creates a deployment branch policy for an environment.
//
// GitHub API docs: https://docs.github.com/rest/deployments/branch-policies#create-a-deployment-branch-policy
//
//meta:operation POST /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies
func (s *RepositoriesService) CreateDeploymentBranchPolicy(ctx context.Context, owner, repo, environment string, request *DeploymentBranchPolicyRequest) (*DeploymentBranchPolicy, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment-branch-policies", owner, repo, environment)
req, err := s.client.NewRequest("POST", u, request)
if err != nil {
return nil, nil, err
}
var policy *DeploymentBranchPolicy
resp, err := s.client.Do(ctx, req, &policy)
if err != nil {
return nil, resp, err
}
return policy, resp, nil
}
// UpdateDeploymentBranchPolicy updates a deployment branch policy for an environment.
//
// GitHub API docs: https://docs.github.com/rest/deployments/branch-policies#update-a-deployment-branch-policy
//
//meta:operation PUT /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}
func (s *RepositoriesService) UpdateDeploymentBranchPolicy(ctx context.Context, owner, repo, environment string, branchPolicyID int64, request *DeploymentBranchPolicyRequest) (*DeploymentBranchPolicy, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment-branch-policies/%v", owner, repo, environment, branchPolicyID)
req, err := s.client.NewRequest("PUT", u, request)
if err != nil {
return nil, nil, err
}
var policy *DeploymentBranchPolicy
resp, err := s.client.Do(ctx, req, &policy)
if err != nil {
return nil, resp, err
}
return policy, resp, nil
}
// DeleteDeploymentBranchPolicy deletes a deployment branch policy for an environment.
//
// GitHub API docs: https://docs.github.com/rest/deployments/branch-policies#delete-a-deployment-branch-policy
//
//meta:operation DELETE /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies/{branch_policy_id}
func (s *RepositoriesService) DeleteDeploymentBranchPolicy(ctx context.Context, owner, repo, environment string, branchPolicyID int64) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment-branch-policies/%v", owner, repo, environment, branchPolicyID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
|