|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Github\Api\Organization\Actions; |
| 4 | + |
| 5 | +use Github\Api\AbstractApi; |
| 6 | + |
| 7 | +/** |
| 8 | + * @link https://developer.github.com/v3/actions/secrets/ |
| 9 | + */ |
| 10 | +class Secrets extends AbstractApi |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @link https://developer.github.com/v3/actions/secrets/#list-organization-secrets |
| 14 | + * |
| 15 | + * @param string $organization |
| 16 | + * |
| 17 | + * @return array|string |
| 18 | + */ |
| 19 | + public function all(string $organization) |
| 20 | + { |
| 21 | + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets'); |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * @link https://developer.github.com/v3/actions/secrets/#get-an-organization-secret |
| 26 | + * |
| 27 | + * @param string $organization |
| 28 | + * @param string $secretName |
| 29 | + * |
| 30 | + * @return array|string |
| 31 | + */ |
| 32 | + public function show(string $organization, string $secretName) |
| 33 | + { |
| 34 | + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName)); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @link https://developer.github.com/v3/actions/secrets/#create-or-update-an-organization-secret |
| 39 | + * |
| 40 | + * @param string $organization |
| 41 | + * @param string $secretName |
| 42 | + * @param string $encryptedValue |
| 43 | + * @param string $visibility |
| 44 | + * @param array $selectedRepositoryIds |
| 45 | + * |
| 46 | + * @return array|string |
| 47 | + */ |
| 48 | + public function create(string $organization, string $secretName, string $encryptedValue, string $visibility = 'all', array $selectedRepositoryIds = []) |
| 49 | + { |
| 50 | + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName), [ |
| 51 | + 'encrypted_value' => $encryptedValue, |
| 52 | + 'visibility' => $visibility, |
| 53 | + 'selected_repository_ids' => $selectedRepositoryIds, |
| 54 | + ]); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @link https://developer.github.com/v3/actions/secrets/#create-or-update-an-organization-secret |
| 59 | + * |
| 60 | + * @param string $organization |
| 61 | + * @param string $secretName |
| 62 | + * @param string $keyId |
| 63 | + * @param string $encryptedValue |
| 64 | + * @param string $visibility |
| 65 | + * @param array $selectedRepositoryIds |
| 66 | + * |
| 67 | + * @return array|string |
| 68 | + */ |
| 69 | + public function update(string $organization, string $secretName, string $keyId, string $encryptedValue, string $visibility = 'all', array $selectedRepositoryIds = []) |
| 70 | + { |
| 71 | + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName), [ |
| 72 | + 'key_id' => $keyId, |
| 73 | + 'encrypted_value' => $encryptedValue, |
| 74 | + 'visibility' => $visibility, |
| 75 | + 'selected_repository_ids' => $selectedRepositoryIds, |
| 76 | + ]); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @link https://developer.github.com/v3/actions/secrets/#delete-an-organization-secret |
| 81 | + * |
| 82 | + * @param string $organization |
| 83 | + * @param string $secretName |
| 84 | + * |
| 85 | + * @return array|string |
| 86 | + */ |
| 87 | + public function remove(string $organization, string $secretName) |
| 88 | + { |
| 89 | + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName)); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * @link https://developer.github.com/v3/actions/secrets/#list-selected-repositories-for-an-organization-secret |
| 94 | + * |
| 95 | + * @param string $organization |
| 96 | + * @param string $secretName |
| 97 | + * |
| 98 | + * @return array|string |
| 99 | + */ |
| 100 | + public function selectedRepositories(string $organization, string $secretName) |
| 101 | + { |
| 102 | + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories'); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * @link https://developer.github.com/v3/actions/secrets/#set-selected-repositories-for-an-organization-secret |
| 107 | + * |
| 108 | + * @param string $organization |
| 109 | + * @param string $secretName |
| 110 | + * @param array $selectedRepositoryIds |
| 111 | + * |
| 112 | + * @return array|string |
| 113 | + */ |
| 114 | + public function setSelectedRepositories(string $organization, string $secretName, array $selectedRepositoryIds = []) |
| 115 | + { |
| 116 | + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories', [ |
| 117 | + 'selected_repository_ids' => $selectedRepositoryIds, |
| 118 | + ]); |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * @link https://developer.github.com/v3/actions/secrets/#add-selected-repository-to-an-organization-secret |
| 123 | + * |
| 124 | + * @param string $organization |
| 125 | + * @param string $repositoryId |
| 126 | + * @param string $secretName |
| 127 | + * |
| 128 | + * @return array|string |
| 129 | + */ |
| 130 | + public function addSecret(string $organization, string $repositoryId, string $secretName) |
| 131 | + { |
| 132 | + return $this->put('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories/'.$repositoryId); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * @link https://developer.github.com/v3/actions/secrets/#remove-selected-repository-from-an-organization-secret |
| 137 | + * |
| 138 | + * @param string $organization |
| 139 | + * @param string $repositoryId |
| 140 | + * @param string $secretName |
| 141 | + * |
| 142 | + * @return array|string |
| 143 | + */ |
| 144 | + public function removeSecret(string $organization, string $repositoryId, string $secretName) |
| 145 | + { |
| 146 | + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/secrets/'.rawurlencode($secretName).'/repositories/'.$repositoryId); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * @link https://developer.github.com/v3/actions/secrets/#get-an-organization-public-key |
| 151 | + * |
| 152 | + * @param string $organization |
| 153 | + * |
| 154 | + * @return array|string |
| 155 | + */ |
| 156 | + public function publicKey(string $organization) |
| 157 | + { |
| 158 | + return $this->get('/orgs/'.rawurlencode($organization).'/actions/secrets/secret-key'); |
| 159 | + } |
| 160 | +} |
0 commit comments