From 603896f44541740d72aa441ed60c698760a1393e Mon Sep 17 00:00:00 2001 From: Mohamed Mostafa <112487260+mohy01@users.noreply.github.com> Date: Tue, 2 Jan 2024 00:32:15 +0200 Subject: [PATCH] Add and update organisation dependabot secrets (#2316) --- github/Organization.py | 13 ++++++++----- tests/Organization.py | 9 +++++++++ .../Organization.testGetDependabotSecrets.txt | 10 ++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 tests/ReplayData/Organization.testGetDependabotSecrets.txt diff --git a/github/Organization.py b/github/Organization.py index 6c92e1bd7b..5f04613e70 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -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} `_ + :calls: 'GET /orgs/{org}/{secret_type}/secrets/{secret_name} `_ :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, ) diff --git a/tests/Organization.py b/tests/Organization.py index 932a44ebc0..c96ff3ad05 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -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() diff --git a/tests/ReplayData/Organization.testGetDependabotSecrets.txt b/tests/ReplayData/Organization.testGetDependabotSecrets.txt new file mode 100644 index 0000000000..84cf5c4598 --- /dev/null +++ b/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"}]}