github.com/google/go-github/v69@v69.2.0/github/repos_deployment_protection_rules.go (about) 1 // Copyright 2024 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 // CustomDeploymentProtectionRuleApp represents a single deployment protection rule app for an environment. 14 type CustomDeploymentProtectionRuleApp struct { 15 ID *int64 `json:"id,omitempty"` 16 Slug *string `json:"slug,omitempty"` 17 IntegrationURL *string `json:"integration_url,omitempty"` 18 NodeID *string `json:"node_id,omitempty"` 19 } 20 21 // CustomDeploymentProtectionRule represents a single deployment protection rule for an environment. 22 type CustomDeploymentProtectionRule struct { 23 ID *int64 `json:"id,omitempty"` 24 NodeID *string `json:"node_id,omitempty"` 25 Enabled *bool `json:"enabled,omitempty"` 26 App *CustomDeploymentProtectionRuleApp `json:"app,omitempty"` 27 } 28 29 // ListDeploymentProtectionRuleResponse represents the response that comes back when you list deployment protection rules. 30 type ListDeploymentProtectionRuleResponse struct { 31 TotalCount *int `json:"total_count,omitempty"` 32 ProtectionRules []*CustomDeploymentProtectionRule `json:"custom_deployment_protection_rules,omitempty"` 33 } 34 35 // ListCustomDeploymentRuleIntegrationsResponse represents the slightly different response that comes back when you list custom deployment rule integrations. 36 type ListCustomDeploymentRuleIntegrationsResponse struct { 37 TotalCount *int `json:"total_count,omitempty"` 38 AvailableIntegrations []*CustomDeploymentProtectionRuleApp `json:"available_custom_deployment_protection_rule_integrations,omitempty"` 39 } 40 41 // CustomDeploymentProtectionRuleRequest represents a deployment protection rule request. 42 type CustomDeploymentProtectionRuleRequest struct { 43 IntegrationID *int64 `json:"integration_id,omitempty"` 44 } 45 46 // GetAllDeploymentProtectionRules gets all the deployment protection rules for an environment. 47 // 48 // GitHub API docs: https://docs.github.com/rest/deployments/protection-rules#get-all-deployment-protection-rules-for-an-environment 49 // 50 //meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules 51 func (s *RepositoriesService) GetAllDeploymentProtectionRules(ctx context.Context, owner, repo, environment string) (*ListDeploymentProtectionRuleResponse, *Response, error) { 52 u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment_protection_rules", owner, repo, environment) 53 54 req, err := s.client.NewRequest("GET", u, nil) 55 if err != nil { 56 return nil, nil, err 57 } 58 59 var list *ListDeploymentProtectionRuleResponse 60 resp, err := s.client.Do(ctx, req, &list) 61 if err != nil { 62 return nil, resp, err 63 } 64 65 return list, resp, nil 66 } 67 68 // CreateCustomDeploymentProtectionRule creates a custom deployment protection rule on an environment. 69 // 70 // GitHub API docs: https://docs.github.com/rest/deployments/protection-rules#create-a-custom-deployment-protection-rule-on-an-environment 71 // 72 //meta:operation POST /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules 73 func (s *RepositoriesService) CreateCustomDeploymentProtectionRule(ctx context.Context, owner, repo, environment string, request *CustomDeploymentProtectionRuleRequest) (*CustomDeploymentProtectionRule, *Response, error) { 74 u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment_protection_rules", owner, repo, environment) 75 76 req, err := s.client.NewRequest("POST", u, request) 77 if err != nil { 78 return nil, nil, err 79 } 80 81 protectionRule := new(CustomDeploymentProtectionRule) 82 resp, err := s.client.Do(ctx, req, protectionRule) 83 if err != nil { 84 return nil, resp, err 85 } 86 87 return protectionRule, resp, nil 88 } 89 90 // ListCustomDeploymentRuleIntegrations lists the custom deployment rule integrations for an environment. 91 // 92 // GitHub API docs: https://docs.github.com/rest/deployments/protection-rules#list-custom-deployment-rule-integrations-available-for-an-environment 93 // 94 //meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/apps 95 func (s *RepositoriesService) ListCustomDeploymentRuleIntegrations(ctx context.Context, owner, repo, environment string) (*ListCustomDeploymentRuleIntegrationsResponse, *Response, error) { 96 u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment_protection_rules/apps", owner, repo, environment) 97 98 req, err := s.client.NewRequest("GET", u, nil) 99 if err != nil { 100 return nil, nil, err 101 } 102 103 var list *ListCustomDeploymentRuleIntegrationsResponse 104 resp, err := s.client.Do(ctx, req, &list) 105 if err != nil { 106 return nil, resp, err 107 } 108 109 return list, resp, nil 110 } 111 112 // GetCustomDeploymentProtectionRule gets a custom deployment protection rule for an environment. 113 // 114 // GitHub API docs: https://docs.github.com/rest/deployments/protection-rules#get-a-custom-deployment-protection-rule 115 // 116 //meta:operation GET /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/{protection_rule_id} 117 func (s *RepositoriesService) GetCustomDeploymentProtectionRule(ctx context.Context, owner, repo, environment string, protectionRuleID int64) (*CustomDeploymentProtectionRule, *Response, error) { 118 u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment_protection_rules/%v", owner, repo, environment, protectionRuleID) 119 120 req, err := s.client.NewRequest("GET", u, nil) 121 if err != nil { 122 return nil, nil, err 123 } 124 125 var protectionRule *CustomDeploymentProtectionRule 126 resp, err := s.client.Do(ctx, req, &protectionRule) 127 if err != nil { 128 return nil, resp, err 129 } 130 131 return protectionRule, resp, nil 132 } 133 134 // DisableCustomDeploymentProtectionRule disables a custom deployment protection rule for an environment. 135 // 136 // GitHub API docs: https://docs.github.com/rest/deployments/protection-rules#disable-a-custom-protection-rule-for-an-environment 137 // 138 //meta:operation DELETE /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/{protection_rule_id} 139 func (s *RepositoriesService) DisableCustomDeploymentProtectionRule(ctx context.Context, owner, repo, environment string, protectionRuleID int64) (*Response, error) { 140 u := fmt.Sprintf("repos/%v/%v/environments/%v/deployment_protection_rules/%v", owner, repo, environment, protectionRuleID) 141 142 req, err := s.client.NewRequest("DELETE", u, nil) 143 if err != nil { 144 return nil, err 145 } 146 147 return s.client.Do(ctx, req, nil) 148 }