Skip to content

Commit

Permalink
Add selected repository to an organization secret
Browse files Browse the repository at this point in the history
Signed-off-by: mohy <mohamed.mohyeldeanmostafa@pfizer.com>
  • Loading branch information
mohy01 committed Feb 9, 2023
1 parent 5e27c10 commit ccdcd82
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
24 changes: 24 additions & 0 deletions github/Organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,30 @@ def create_secret(
)
return status == 201

def add_repository_to_secret(
self,
secret_name,
repository_id,
secret_type,
):
"""
:calls: `PUT /orgs/{org}/{secret_type}/secrets/{secret_name}/repositories/{repository_id} <https://docs.github.com/en/rest/actions/secrets#add-selected-repository-to-an-organization-secret>`_
:param secret_name: string
:param repository_id: int
:param secret_type: string ('actions', 'dependabot')
:rtype: bool
"""
assert isinstance(secret_name, str), secret_name
assert isinstance(repository_id, int)
assert isinstance(secret_type, str)
assert secret_type in ["actions", "dependabot"]

status, headers, data = self._requester.requestJson(
"PUT",
f"{self.url}/{secret_type}/secrets/{secret_name}/repositories/{repository_id}",
)
return status == 204

def create_team(
self,
name,
Expand Down
6 changes: 6 additions & 0 deletions github/Organization.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class Organization(CompletableGithubObject):
visibility: str = ...,
selected_repositories: Union[List[Repository], _NotSetType] = ...,
) -> bool: ...
def add_repository_to_secret(
self,
secret_name: str,
repository_id: int,
secret_type: str,
) -> bool: ...
def create_team(
self,
name: str,
Expand Down
12 changes: 12 additions & 0 deletions tests/Organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,18 @@ def testCreateSecretSelected(self, encrypt):
def testDeleteSecret(self):
self.assertTrue(self.org.delete_secret("secret-name"))

def testAddOrganizationSecretToRepo(self):
repo = self.org.get_repo("TestPyGithub")
self.assertTrue(
self.org.add_repository_to_secret("secret-name", repo.id, "actions")
)

def testAddOrganizationDependabotSecretToRepo(self):
repo = self.org.get_repo("TestPyGithub")
self.assertTrue(
self.org.add_repository_to_secret("secret-name", repo.id, "dependabot")
)

def testInviteUserWithNeither(self):
with self.assertRaises(AssertionError) as raisedexp:
self.org.invite_user()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
https
GET
api.github.com
None
/repos/BeaverSoftware/TestPyGithub
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.nebula-preview+json'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4992'), ('content-length', '1431'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"4ecd2c151a469cfa6cd45e6beff1269b"'), ('date', 'Fri, 01 Jun 2012 19:40:56 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"clone_url":"https://github.com/BeaverSoftware/TestPyGithub.git","has_downloads":true,"watchers":1,"git_url":"git://github.com/BeaverSoftware/TestPyGithub.git","updated_at":"2012-04-25T06:51:38Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/TestPyGithub","has_wiki":true,"has_pages":false,"has_issues":false,"fork":false,"forks":0,"mirror_url":null,"size":112,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/TestPyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png"},"name":"TestPyGithub","language":null,"description":"Guinea-pig for PyGithub testing","ssh_url":"git@github.com:BeaverSoftware/TestPyGithub.git","pushed_at":"2012-03-03T08:57:40Z","created_at":"2012-03-03T07:53:19Z","id":3609352,"html_url":"https://github.com/BeaverSoftware/TestPyGithub","full_name":"BeaverSoftware/TestPyGithub"}

https
PUT
api.github.com
None
/orgs/BeaverSoftware/dependabot/secrets/secret-name/repositories/3609352
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
204
[('status', '204 No Content'), ('x-ratelimit-remaining', '4993'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('cache-control', ''), ('date', 'Fri, 07 Sep 2012 23:12:27 GMT')]
20 changes: 20 additions & 0 deletions tests/ReplayData/Organization.testAddOrganizationSecretToRepo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
https
GET
api.github.com
None
/repos/BeaverSoftware/TestPyGithub
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.nebula-preview+json'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4992'), ('content-length', '1431'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"4ecd2c151a469cfa6cd45e6beff1269b"'), ('date', 'Fri, 01 Jun 2012 19:40:56 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"clone_url":"https://github.com/BeaverSoftware/TestPyGithub.git","has_downloads":true,"watchers":1,"git_url":"git://github.com/BeaverSoftware/TestPyGithub.git","updated_at":"2012-04-25T06:51:38Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/TestPyGithub","has_wiki":true,"has_pages":false,"has_issues":false,"fork":false,"forks":0,"mirror_url":null,"size":112,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/TestPyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png"},"name":"TestPyGithub","language":null,"description":"Guinea-pig for PyGithub testing","ssh_url":"git@github.com:BeaverSoftware/TestPyGithub.git","pushed_at":"2012-03-03T08:57:40Z","created_at":"2012-03-03T07:53:19Z","id":3609352,"html_url":"https://github.com/BeaverSoftware/TestPyGithub","full_name":"BeaverSoftware/TestPyGithub"}

https
PUT
api.github.com
None
/orgs/BeaverSoftware/actions/secrets/secret-name/repositories/3609352
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
204
[('status', '204 No Content'), ('x-ratelimit-remaining', '4993'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('cache-control', ''), ('date', 'Fri, 07 Sep 2012 23:12:27 GMT')]

0 comments on commit ccdcd82

Please sign in to comment.