Skip to content

Commit

Permalink
Add and update organisation dependabot secrets (#2316)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohy01 committed Jan 1, 2024
1 parent 2f44b2e commit 603896f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
13 changes: 8 additions & 5 deletions github/Organization.py
Expand Up @@ -604,30 +604,33 @@ def create_secret(
completed=False,
)

def get_secrets(self) -> PaginatedList[OrganizationSecret]:
def get_secrets(self, secret_type: str = "actions") -> PaginatedList[OrganizationSecret]:
"""
Gets all organization secrets
:param secret_type: string options actions or dependabot
:rtype: :class:`PaginatedList` of :class:`github.OrganizationSecret.OrganizationSecret`
"""
assert secret_type in ["actions", "dependabot"], "secret_type should be actions or dependabot"
return PaginatedList(
github.OrganizationSecret.OrganizationSecret,
self._requester,
f"{self.url}/actions/secrets",
f"{self.url}/{secret_type}/secrets",
None,
list_item="secrets",
)

def get_secret(self, secret_name: str) -> OrganizationSecret:
def get_secret(self, secret_name: str, secret_type: str = "actions") -> OrganizationSecret:
"""
:calls: 'GET /orgs/{org}/actions/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#get-an-organization-secret>`_
:calls: 'GET /orgs/{org}/{secret_type}/secrets/{secret_name} <https://docs.github.com/en/rest/actions/secrets#get-an-organization-secret>`_
:param secret_name: string
:param secret_type: string options actions or dependabot
:rtype: github.OrganizationSecret.OrganizationSecret
"""
assert isinstance(secret_name, str), secret_name
return github.OrganizationSecret.OrganizationSecret(
requester=self._requester,
headers={},
attributes={"url": f"{self.url}/actions/secrets/{urllib.parse.quote(secret_name)}"},
attributes={"url": f"{self.url}/{secret_type}/secrets/{urllib.parse.quote(secret_name)}"},
completed=False,
)

Expand Down
9 changes: 9 additions & 0 deletions tests/Organization.py
Expand Up @@ -448,6 +448,15 @@ def testGetSecrets(self):
secrets = self.org.get_secrets()
self.assertEqual(len(list(secrets)), 1)

def testGetDependabotSecrets(self):
secrets = self.org.get_secrets(secret_type="dependabot")
self.assertEqual(len(list(secrets)), 1)

def testGetSecretsFail(self):
with self.assertRaises(AssertionError) as raisedexp:
self.org.get_secrets(secret_type="secret")
self.assertEqual("secret_type should be actions or dependabot", str(raisedexp.exception))

def testInviteUserWithNeither(self):
with self.assertRaises(AssertionError) as raisedexp:
self.org.invite_user()
Expand Down
10 changes: 10 additions & 0 deletions tests/ReplayData/Organization.testGetDependabotSecrets.txt
@@ -0,0 +1,10 @@
https
GET
api.github.com
None
/orgs/BeaverSoftware/dependabot/secrets
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4978'), ('content-length', '487'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1dd282b50e691f8f162ef9355dad8771"'), ('date', 'Thu, 10 May 2012 19:03:19 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"total_count": 1, "secrets": [{"name": "secret-name","created_at": "2019-08-10T14:59:22Z","updated_at": "2020-01-10T14:59:22Z","visibility": "selected","selected_repositories_url": "https://api.github.com/orgs/BeaverSoftware/dependabot/secrets/secret-name/repositories"}]}

0 comments on commit 603896f

Please sign in to comment.