Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parent_team_id, maintainers and notification_setting for creating and updating teams. #2863

Merged
merged 16 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion github/Organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ def create_team(
permission: Opt[str] = NotSet,
privacy: Opt[str] = NotSet,
description: Opt[str] = NotSet,
parent_team_id: Opt[int] = NotSet,
maintainers: Opt[list[int]] = NotSet,
notification_setting: Opt[str] = NotSet,
) -> Team:
"""
:calls: `POST /orgs/{org}/teams <https://docs.github.com/en/rest/reference/teams#list-teams>`_
Expand All @@ -659,15 +662,29 @@ def create_team(
:param permission: string
:param privacy: string
:param description: string
:param parent_team_id: integer
:param maintainers: list of: integer
:param notification_setting: string
:rtype: :class:`github.Team.Team`
"""
assert isinstance(name, str), name
assert is_optional_list(repo_names, github.Repository.Repository), repo_names
assert is_optional_list(maintainers, int), maintainers
assert is_optional(parent_team_id, int), parent_team_id
assert is_optional(permission, str), permission
assert is_optional(privacy, str), privacy
assert is_optional(description, str), description
assert notification_setting in ["notifications_enabled", "notifications_disabled", NotSet], notification_setting
post_parameters: dict[str, Any] = NotSet.remove_unset_items(
{"name": name, "permission": permission, "privacy": privacy, "description": description}
{
"name": name,
"permission": permission,
"privacy": privacy,
"description": description,
"parent_team_id": parent_team_id,
"maintainers": maintainers,
"notification_setting": notification_setting,
}
)
if is_defined(repo_names):
post_parameters["repo_names"] = [element._identity for element in repo_names]
Expand Down
21 changes: 20 additions & 1 deletion github/Team.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def _initAttributes(self) -> None:
self._members_url: Attribute[str] = NotSet
self._name: Attribute[str] = NotSet
self._description: Attribute[str] = NotSet
self._notification_setting: Attribute[str] = NotSet
self._permission: Attribute[str] = NotSet
self._repos_count: Attribute[int] = NotSet
self._repositories_url: Attribute[str] = NotSet
Expand Down Expand Up @@ -132,6 +133,11 @@ def description(self) -> str:
self._completeIfNotSet(self._description)
return self._description.value

@property
def notification_setting(self) -> str:
self._completeIfNotSet(self._notification_setting)
return self._notification_setting.value

@property
def permission(self) -> str:
self._completeIfNotSet(self._permission)
Expand Down Expand Up @@ -297,6 +303,8 @@ def edit(
description: Opt[str] = NotSet,
permission: Opt[str] = NotSet,
privacy: Opt[str] = NotSet,
parent_team_id: Opt[int] = NotSet,
notification_setting: Opt[str] = NotSet,
) -> None:
"""
:calls: `PATCH /teams/{id} <https://docs.github.com/en/rest/reference/teams#update-a-team>`_
Expand All @@ -305,8 +313,17 @@ def edit(
assert description is NotSet or isinstance(description, str), description
assert permission is NotSet or isinstance(permission, str), permission
assert privacy is NotSet or isinstance(privacy, str), privacy
assert parent_team_id is NotSet or isinstance(parent_team_id, (int, type(None))), parent_team_id
assert notification_setting in ["notifications_enabled", "notifications_disabled", NotSet], notification_setting
post_parameters = NotSet.remove_unset_items(
{"name": name, "description": description, "permission": permission, "privacy": privacy}
{
"name": name,
"description": description,
"permission": permission,
"privacy": privacy,
"parent_team_id": parent_team_id,
"notification_setting": notification_setting,
}
)

headers, data = self._requester.requestJsonAndCheck("PATCH", self.url, input=post_parameters)
Expand Down Expand Up @@ -426,6 +443,8 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._name = self._makeStringAttribute(attributes["name"])
if "description" in attributes: # pragma no branch
self._description = self._makeStringAttribute(attributes["description"])
if "notification_setting" in attributes: # pragma no branch
self._notification_setting = self._makeStringAttribute(attributes["notification_setting"])
if "permission" in attributes: # pragma no branch
self._permission = self._makeStringAttribute(attributes["permission"])
if "repos_count" in attributes: # pragma no branch
Expand Down
7 changes: 7 additions & 0 deletions tests/Organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,22 @@ def testCreateTeam(self):

def testCreateTeamWithAllArguments(self):
repo = self.org.get_repo("FatherBeaver")
parent_team = self.org.get_team(141496)
maintainer = self.g.get_user("jacquev6")
team = self.org.create_team(
"Team also created by PyGithub",
[repo],
"push",
"secret",
"Description also created by PyGithub",
parent_team.id,
[maintainer.id],
"notifications_disabled",
)
self.assertEqual(team.id, 189852)
self.assertEqual(team.description, "Description also created by PyGithub")
Cheshirez marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(team.parent, parent_team)
self.assertEqual(team.notification_setting, "notifications_disabled")

def testDeleteHook(self):
hook = self.org.create_hook("web", {"url": "http://foobar.com"})
Expand Down
26 changes: 24 additions & 2 deletions tests/ReplayData/Organization.testCreateTeamWithAllArguments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,35 @@ None
[('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')]
{"has_downloads":true,"watchers":2,"mirror_url":null,"language":null,"description":"","ssh_url":"git@github.com:BeaverSoftware/FatherBeaver.git","created_at":"2012-02-09T19:32:21Z","url":"https://api.github.com/repos/BeaverSoftware/FatherBeaver","fork":false,"full_name":"BeaverSoftware/FatherBeaver","organization":{"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","url":"https://api.github.com/users/BeaverSoftware","id":1424031},"permissions":{"admin":true,"pull":true,"push":true},"has_wiki":true,"has_issues":true,"forks":1,"size":0,"svn_url":"https://github.com/BeaverSoftware/FatherBeaver","git_url":"git://github.com/BeaverSoftware/FatherBeaver.git","private":false,"visibility":"public","updated_at":"2012-02-16T21:51:15Z","homepage":"","owner":{"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","url":"https://api.github.com/users/BeaverSoftware","id":1424031},"name":"FatherBeaver","open_issues":0,"html_url":"https://github.com/BeaverSoftware/FatherBeaver","id":3400397,"clone_url":"https://github.com/BeaverSoftware/FatherBeaver.git","pushed_at":null}

https
GET
api.github.com
None
/teams/141496
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('x-ratelimit-limit', '5000'), ('content-length', '128'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('etag', '"b93241eaf4384574f38b352b25595e28"'), ('date', 'Fri, 01 Jun 2012 19:35:59 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"repos_count":1,"permission":"push","url":"https://api.github.com/teams/141496","name":"Members","id":141496,"members_count":1}

https
GET
api.github.com
None
/users/jacquev6
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4962'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"fc78d67f262cad756e42354c78ecea4e"'), ('date', 'Tue, 28 Aug 2018 00:16:42 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"public_repos":11,"type":"User","disk_usage":17080,"hireable":false,"blog":"http://vincent-jacques.net","url":"https://api.github.com/users/jacquev6","bio":"","plan":{"collaborators":1,"private_repos":5,"name":"micro","space":614400},"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","total_private_repos":5,"public_gists":2,"company":"Criteo","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","owned_private_repos":5,"private_gists":5,"collaborators":0,"email":"vincent@vincent-jacques.net","followers":13,"name":"Vincent Jacques","created_at":"2010-07-09T06:10:06Z","location":"Paris, France","id":327146,"following":24,"html_url":"https://github.com/jacquev6"}

https
POST
api.github.com
None
/orgs/BeaverSoftware/teams
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"repo_names": ["BeaverSoftware/FatherBeaver"], "name": "Team also created by PyGithub", "permission": "push", "privacy": "secret", "description":"Description also created by PyGithub"}
{"repo_names": ["BeaverSoftware/FatherBeaver"], "name": "Team also created by PyGithub", "permission": "push", "privacy": "secret", "description":"Description also created by PyGithub", "parent_team_id":141496, "maintainers": [327146], "notification_setting": "notifications_disabled"}
201
[('status', '201 Created'), ('x-ratelimit-remaining', '4982'), ('content-length', '150'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"6e3fb00de6ca4c112feee3a1438d6f0e"'), ('date', 'Sat, 26 May 2012 21:00:26 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/teams/189852')]
{"repos_count":1,"url":"https://api.github.com/teams/189852","members_count":0,"name":"Team also created by PyGithub","permission":"push","description":"Description also created by PyGithub","id":189852}
{"repos_count":1,"url":"https://api.github.com/teams/189852","members_count":0,"name":"Team also created by PyGithub","permission":"push","description":"Description also created by PyGithub","id":189852, "notification_setting": "notifications_disabled", "parent":{"repos_count":1,"permission":"push","url":"https://api.github.com/teams/141496","name":"Members","id":141496,"members_count":1}}
15 changes: 13 additions & 2 deletions tests/ReplayData/Team.testEditWithAllArguments.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
https
GET
api.github.com
None
/teams/141496
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('x-ratelimit-limit', '5000'), ('content-length', '128'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('etag', '"b93241eaf4384574f38b352b25595e28"'), ('date', 'Fri, 01 Jun 2012 19:35:59 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"repos_count":1,"permission":"push","url":"https://api.github.com/teams/141496","name":"Members","id":141496,"members_count":1}

https
PATCH
api.github.com
None
/teams/189850
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"name": "Name edited twice by PyGithub", "permission": "admin", "privacy": "secret", "description": "Description edited by PyGithub"}
{"name": "Name edited twice by PyGithub", "permission": "admin", "privacy": "secret", "description": "Description edited by PyGithub", "parent_team_id": 141496, "notification_setting": "notifications_disabled"}
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4949'), ('content-length', '170'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"8856425cedbdf3075576e823f39fc3d6"'), ('date', 'Sat, 26 May 2012 21:14:46 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"permission":"admin","members_count":0,"url":"https://api.github.com/teams/189850","repos_count":0,"privacy":"secret","name":"Name edited twice by PyGithub","id":189850, "description": "Description edited by PyGithub"}
{"permission":"admin","members_count":0,"url":"https://api.github.com/teams/189850","repos_count":0,"privacy":"secret","name":"Name edited twice by PyGithub","id":189850, "description": "Description edited by PyGithub", "notification_setting": "notifications_disabled", "parent": {"repos_count":1,"permission":"push","url":"https://api.github.com/teams/141496","name":"Members","id":141496,"members_count":1}}
5 changes: 5 additions & 0 deletions tests/Team.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,21 @@ def testEditWithoutArguments(self):
self.assertEqual(self.team.name, "Name edited by PyGithub")

def testEditWithAllArguments(self):
parent = self.org.get_team(141496)
self.team.edit(
"Name edited twice by PyGithub",
"Description edited by PyGithub",
"admin",
"secret",
parent.id,
"notifications_disabled",
)
self.assertEqual(self.team.name, "Name edited twice by PyGithub")
self.assertEqual(self.team.description, "Description edited by PyGithub")
Cheshirez marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(self.team.permission, "admin")
self.assertEqual(self.team.privacy, "secret")
self.assertEqual(self.team.parent, parent)
self.assertEqual(self.team.notification_setting, "notifications_disabled")

def testGetTeams(self):
nested_teams = self.team.get_teams()
Expand Down