Skip to content

Commit 7522416

Browse files
author
Chris Wells
authored
Add has_discussions to AuthenticatedUser and Repository classes (PyGithub#3020)
The `has_discussions` feature is exposed in the Github API and is identical in the way it works to something like `has_wiki`. Following a couple previous PR attempts by @amnuts and @heitorPB as well as the existing code for `has_wiki` I added `has_discussions` as well as the test cases. Fixes PyGithub#2733 and PyGithub#2994
1 parent fa16827 commit 7522416

7 files changed

+31
-6
lines changed

Diff for: github/AuthenticatedUser.py

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# Copyright 2023 chantra <[email protected]> #
5050
# Copyright 2024 Enrico Minack <[email protected]> #
5151
# Copyright 2024 Oskar Jansson <[email protected]>#
52+
# Copyright 2024 Chris Wells <[email protected]> #
5253
# #
5354
# This file is part of PyGithub. #
5455
# http://pygithub.readthedocs.io/ #
@@ -567,6 +568,7 @@ def create_repo(
567568
has_wiki: Opt[bool] = NotSet,
568569
has_downloads: Opt[bool] = NotSet,
569570
has_projects: Opt[bool] = NotSet,
571+
has_discussions: Opt[bool] = NotSet,
570572
auto_init: Opt[bool] = NotSet,
571573
license_template: Opt[str] = NotSet,
572574
gitignore_template: Opt[str] = NotSet,
@@ -586,6 +588,7 @@ def create_repo(
586588
assert is_optional(has_wiki, bool), has_wiki
587589
assert is_optional(has_downloads, bool), has_downloads
588590
assert is_optional(has_projects, bool), has_projects
591+
assert is_optional(has_discussions, bool), has_discussions
589592
assert is_optional(auto_init, bool), auto_init
590593
assert is_optional(license_template, str), license_template
591594
assert is_optional(gitignore_template, str), gitignore_template
@@ -603,6 +606,7 @@ def create_repo(
603606
"has_wiki": has_wiki,
604607
"has_downloads": has_downloads,
605608
"has_projects": has_projects,
609+
"has_discussions": has_discussions,
606610
"auto_init": auto_init,
607611
"license_template": license_template,
608612
"gitignore_template": gitignore_template,

Diff for: github/Repository.py

+15
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
# Copyright 2024 Thomas Crowley <[email protected]>#
131131
# Copyright 2024 jodelasur <[email protected]> #
132132
# Copyright 2024 Jacky Lam <[email protected]> #
133+
# Copyright 2024 Chris Wells <[email protected]> #
133134
# #
134135
# This file is part of PyGithub. #
135136
# http://pygithub.readthedocs.io/ #
@@ -640,6 +641,14 @@ def has_wiki(self) -> bool:
640641
self._completeIfNotSet(self._has_wiki)
641642
return self._has_wiki.value
642643

644+
@property
645+
def has_discussions(self) -> bool:
646+
"""
647+
:type: bool
648+
"""
649+
self._completeIfNotSet(self._has_discussions)
650+
return self._has_discussions.value
651+
643652
@property
644653
def homepage(self) -> str:
645654
"""
@@ -1918,6 +1927,7 @@ def edit(
19181927
has_issues: Opt[bool] = NotSet,
19191928
has_projects: Opt[bool] = NotSet,
19201929
has_wiki: Opt[bool] = NotSet,
1930+
has_discussions: Opt[bool] = NotSet,
19211931
is_template: Opt[bool] = NotSet,
19221932
default_branch: Opt[str] = NotSet,
19231933
allow_squash_merge: Opt[bool] = NotSet,
@@ -1948,6 +1958,7 @@ def edit(
19481958
assert is_optional(has_issues, bool), has_issues
19491959
assert is_optional(has_projects, bool), has_projects
19501960
assert is_optional(has_wiki, bool), has_wiki
1961+
assert is_optional(has_discussions, bool), has_discussions
19511962
assert is_optional(is_template, bool), is_template
19521963
assert is_optional(default_branch, str), default_branch
19531964
assert is_optional(allow_squash_merge, bool), allow_squash_merge
@@ -1980,6 +1991,7 @@ def edit(
19801991
"has_issues": has_issues,
19811992
"has_projects": has_projects,
19821993
"has_wiki": has_wiki,
1994+
"has_discussions": has_discussions,
19831995
"is_template": is_template,
19841996
"default_branch": default_branch,
19851997
"allow_squash_merge": allow_squash_merge,
@@ -4168,6 +4180,7 @@ def _initAttributes(self) -> None:
41684180
self._has_pages: Attribute[bool] = NotSet
41694181
self._has_projects: Attribute[bool] = NotSet
41704182
self._has_wiki: Attribute[bool] = NotSet
4183+
self._has_discussions: Attribute[bool] = NotSet
41714184
self._homepage: Attribute[str] = NotSet
41724185
self._hooks_url: Attribute[str] = NotSet
41734186
self._html_url: Attribute[str] = NotSet
@@ -4306,6 +4319,8 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
43064319
self._has_projects = self._makeBoolAttribute(attributes["has_projects"])
43074320
if "has_wiki" in attributes: # pragma no branch
43084321
self._has_wiki = self._makeBoolAttribute(attributes["has_wiki"])
4322+
if "has_discussions" in attributes: # pragma no branch
4323+
self._has_discussions = self._makeBoolAttribute(attributes["has_discussions"])
43094324
if "homepage" in attributes: # pragma no branch
43104325
self._homepage = self._makeStringAttribute(attributes["homepage"])
43114326
if "hooks_url" in attributes: # pragma no branch

Diff for: tests/AuthenticatedUser.py

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# Copyright 2023 Jirka Borovec <[email protected]> #
3131
# Copyright 2024 Enrico Minack <[email protected]> #
3232
# Copyright 2024 Oskar Jansson <[email protected]>#
33+
# Copyright 2024 Chris Wells <[email protected]> #
3334
# #
3435
# This file is part of PyGithub. #
3536
# http://pygithub.readthedocs.io/ #
@@ -365,6 +366,7 @@ def testCreateRepositoryWithAllArguments(self):
365366
has_issues=False,
366367
has_projects=False,
367368
has_wiki=False,
369+
has_discussions=False,
368370
has_downloads=False,
369371
allow_squash_merge=False,
370372
allow_merge_commit=False,

Diff for: tests/ReplayData/AuthenticatedUser.testCreateRepositoryWithAllArguments.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ api.github.com
44
None
55
/user/repos
66
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
7-
{"has_wiki": false, "name": "TestPyGithub", "has_downloads": false, "private": false, "has_issues": false, "homepage": "http://foobar.com", "description": "Repo created by PyGithub", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true, "delete_branch_on_merge": false}
7+
{"has_wiki": false, "name": "TestPyGithub", "has_downloads": false, "private": false, "has_issues": false, "homepage": "http://foobar.com", "description": "Repo created by PyGithub", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true, "delete_branch_on_merge": false, "has_discussions": false}
88
201
99
[('status', '201 Created'), ('x-ratelimit-remaining', '4979'), ('content-length', '1111'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1c6473a60481c33b28a926041f763fce"'), ('date', 'Sat, 26 May 2012 09:55:27 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/TestPyGithub')]
10-
{"clone_url":"https://github.com/jacquev6/TestPyGithub.git","has_downloads":false,"watchers":1,"git_url":"git://github.com/jacquev6/TestPyGithub.git","updated_at":"2012-05-26T09:55:27Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://foobar.com","url":"https://api.github.com/repos/jacquev6/TestPyGithub","has_wiki":false,"has_issues":false,"fork":false,"forks":1,"mirror_url":null,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/jacquev6/TestPyGithub","owner":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"name":"TestPyGithub","language":null,"description":"Repo created by PyGithub","ssh_url":"[email protected]:jacquev6/TestPyGithub.git","pushed_at":"2012-05-26T09:55:27Z","created_at":"2012-05-26T09:55:27Z","id":4454027,"html_url":"https://github.com/jacquev6/TestPyGithub","full_name":"jacquev6/TestPyGithub", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true, "delete_branch_on_merge": false}
10+
{"clone_url":"https://github.com/jacquev6/TestPyGithub.git","has_downloads":false,"watchers":1,"git_url":"git://github.com/jacquev6/TestPyGithub.git","updated_at":"2012-05-26T09:55:27Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://foobar.com","url":"https://api.github.com/repos/jacquev6/TestPyGithub","has_wiki":false,"has_issues":false,"fork":false,"forks":1,"mirror_url":null,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/jacquev6/TestPyGithub","owner":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"name":"TestPyGithub","language":null,"description":"Repo created by PyGithub","ssh_url":"[email protected]:jacquev6/TestPyGithub.git","pushed_at":"2012-05-26T09:55:27Z","created_at":"2012-05-26T09:55:27Z","id":4454027,"html_url":"https://github.com/jacquev6/TestPyGithub","full_name":"jacquev6/TestPyGithub", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true, "delete_branch_on_merge": false, "has_discussions": false}

Diff for: tests/ReplayData/Repository.setUp.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ None
1818
None
1919
200
2020
[('status', '200 OK'), ('x-ratelimit-remaining', '4911'), ('content-length', '1129'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1a93ec821b0bd7094340a9fc34017aa0"'), ('date', 'Sun, 27 May 2012 07:17:09 GMT'), ('content-type', 'application/json; charset=utf-8')]
21-
{"clone_url":"https://github.com/jacquev6/PyGithub.git","has_downloads":true,"watchers":15,"git_url":"git://github.com/jacquev6/PyGithub.git","deployments_url":"https://api.github.com/repos/jacquev6/PyGithub/deployments","releases_url":"https://api.github.com/repos/jacquev6/PyGithub/releases{/id}","updated_at":"2012-05-27T06:55:28Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","mirror_url":null,"has_pages":false,"has_wiki":false,"has_issues":true,"fork":false,"forks":3,"size":308,"private":false,"open_issues":16,"svn_url":"https://github.com/jacquev6/PyGithub","owner":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"[email protected]:jacquev6/PyGithub.git","pushed_at":"2012-05-27T06:00:28Z","created_at":"2012-02-25T12:53:47Z","id":3544490,"html_url":"https://github.com/jacquev6/PyGithub","full_name":"jacquev6/PyGithub", "use_squash_pr_title_as_default": true, "squash_merge_commit_title": "PR_TITLE", "squash_merge_commit_message": "COMMIT_MESSAGES", "merge_commit_title": "PR_TITLE", "merge_commit_message": "PR_BODY", "web_commit_signoff_required": true, "license": {"key": "lgpl-3.0", "name": "GNU Lesser General Public License v3.0", "spdx_id": "LGPL-3.0", "url": "https://api.github.com/licenses/lgpl-3.0", "node_id": "MDc6TGljZW5zZTEy"},"custom_properties": {"foo": "bar"}}
21+
{"clone_url":"https://github.com/jacquev6/PyGithub.git","has_downloads":true,"watchers":15,"git_url":"git://github.com/jacquev6/PyGithub.git","deployments_url":"https://api.github.com/repos/jacquev6/PyGithub/deployments","releases_url":"https://api.github.com/repos/jacquev6/PyGithub/releases{/id}","updated_at":"2012-05-27T06:55:28Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","mirror_url":null,"has_pages":false,"has_wiki":false,"has_issues":true,"fork":false,"forks":3,"size":308,"private":false,"open_issues":16,"svn_url":"https://github.com/jacquev6/PyGithub","owner":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"[email protected]:jacquev6/PyGithub.git","pushed_at":"2012-05-27T06:00:28Z","created_at":"2012-02-25T12:53:47Z","id":3544490,"html_url":"https://github.com/jacquev6/PyGithub","full_name":"jacquev6/PyGithub", "use_squash_pr_title_as_default": true, "squash_merge_commit_title": "PR_TITLE", "squash_merge_commit_message": "COMMIT_MESSAGES", "merge_commit_title": "PR_TITLE", "merge_commit_message": "PR_BODY", "web_commit_signoff_required": true, "license": {"key": "lgpl-3.0", "name": "GNU Lesser General Public License v3.0", "spdx_id": "LGPL-3.0", "url": "https://api.github.com/licenses/lgpl-3.0", "node_id": "MDc6TGljZW5zZTEy"},"custom_properties": {"foo": "bar"}, "has_discussions": false}

0 commit comments

Comments
 (0)