From 3f54ace5b85920f8010aa872c75886b90e0e99cc Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Tue, 11 Feb 2020 09:57:28 -0300 Subject: [PATCH 01/25] Add create_repo_from_template to Organization and AuthenticatedUser --- github/AuthenticatedUser.py | 41 +++++++++++++++++++++++++++++++++++++ github/Consts.py | 3 +++ github/Organization.py | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 1cb9c3432d..7c64dc1119 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -498,6 +498,47 @@ def create_fork(self, repo): self._requester, headers, data, completed=True ) + def create_repo_from_template( + self, + name, + repo, + description=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:name/generate `_ + :param name: string + :param repo :class:`github.Repository.Repository` + :param description: string + :param private: bool + :rtype: :class:`github.Repository.Repository` + """ + assert isinstance(repo, github.Repository.Repository), repo + assert isinstance(repo, github.Repository.Repository), repo + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + post_parameters = { + "name": name, + "owner": self.login, + } + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if private is not github.GithubObject.NotSet: + post_parameters["private"] = private + headers, data = self._requester.requestJsonAndCheck( + "POST", + "/repos/" + repo.owner.login + "/" + repo.name + "/generate", + input=post_parameters, + headers={"Accept": Consts.mediaTypeTemplatesPreview}, + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True + ) + def create_gist(self, public, files, description=github.GithubObject.NotSet): """ :calls: `POST /gists `_ diff --git a/github/Consts.py b/github/Consts.py index 3532cc9f19..66772a5944 100644 --- a/github/Consts.py +++ b/github/Consts.py @@ -100,6 +100,9 @@ # https://developer.github.com/changes/2018-05-24-user-migration-api/ mediaTypeMigrationPreview = "application/vnd.github.wyandotte-preview+json" +# https://developer.github.com/changes/2019-07-16-repository-templates-api/ +mediaTypeTemplatesPreview = "application/vnd.github.baptiste-preview+json" + # https://developer.github.com/v3/search/#highlighting-code-search-results-1 highLightSearchPreview = "application/vnd.github.v3.text-match+json" diff --git a/github/Organization.py b/github/Organization.py index ffeb79aeda..62e97b2f3b 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -357,6 +357,47 @@ def create_fork(self, repo): self._requester, headers, data, completed=True ) + def create_repo_from_template( + self, + name, + repo, + description=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + ): + """self.name + :calls: `POST /repos/:owner/:name/generate `_ + :param name: string + :param repo :class:`github.Repository.Repository` + :param description: string + :param private: bool + :rtype: :class:`github.Repository.Repository` + """ + assert isinstance(name, str), name + assert isinstance(repo, github.Repository.Repository), repo + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + post_parameters = { + "name": name, + "owner": self.login, + } + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if private is not github.GithubObject.NotSet: + post_parameters["private"] = private + headers, data = self._requester.requestJsonAndCheck( + "POST", + "/repos/" + repo.owner.login + "/" + repo.name + "/generate", + input=post_parameters, + headers={"Accept": Consts.mediaTypeTemplatesPreview}, + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True + ) + def create_hook( self, name, From deea07699d1a348eb6904bb5bbfb36b5e3c2313e Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Tue, 11 Feb 2020 10:29:11 -0300 Subject: [PATCH 02/25] Fix create_repo_from_template docstring url --- github/Organization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/Organization.py b/github/Organization.py index 62e97b2f3b..c24f67dd46 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -365,7 +365,7 @@ def create_repo_from_template( private=github.GithubObject.NotSet, ): """self.name - :calls: `POST /repos/:owner/:name/generate `_ + :calls: `POST /repos/:template_owner/:template_repo/generate `_ :param name: string :param repo :class:`github.Repository.Repository` :param description: string From a91899be0c8549b031d11f19e523ccb7620c36d5 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Tue, 11 Feb 2020 10:31:18 -0300 Subject: [PATCH 03/25] Add is_template attribute to Repository --- github/Repository.py | 11 +++++++++++ scripts/add_attribute.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/github/Repository.py b/github/Repository.py index 082324b15f..b3a27dc4cb 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -450,6 +450,14 @@ def id(self): self._completeIfNotSet(self._id) return self._id.value + @property + def is_template(self): + """ + :type: bool + """ + self._completeIfNotSet(self._is_template) + return self._is_template.value + @property def issue_comment_url(self): """ @@ -3157,6 +3165,7 @@ def _initAttributes(self): self._hooks_url = github.GithubObject.NotSet self._html_url = github.GithubObject.NotSet self._id = github.GithubObject.NotSet + self._is_template = github.GithubObject.NotSet self._issue_comment_url = github.GithubObject.NotSet self._issue_events_url = github.GithubObject.NotSet self._issues_url = github.GithubObject.NotSet @@ -3292,6 +3301,8 @@ def _useAttributes(self, attributes): self._html_url = self._makeStringAttribute(attributes["html_url"]) if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) + if "is_template" in attributes: # pragma no branch + self._is_template = self._makeBoolAttribute(attributes["is_template"]) if "issue_comment_url" in attributes: # pragma no branch self._issue_comment_url = self._makeStringAttribute( attributes["issue_comment_url"] diff --git a/scripts/add_attribute.py b/scripts/add_attribute.py index b905ca2d54..281437d0e5 100644 --- a/scripts/add_attribute.py +++ b/scripts/add_attribute.py @@ -138,4 +138,4 @@ with open(fileName, "wb") as f: for line in newLines: - f.write(line + "\n") + f.write((line + "\n").encode()) From ed363bbbf6331cddb91bb0c332da34acef9aeebc Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 16:11:06 -0300 Subject: [PATCH 04/25] Add tests for the new create_repo_from_template method --- github/AuthenticatedUser.py | 2 +- tests/AuthenticatedUser.py | 16 +++++++++ tests/Organization.py | 16 +++++++++ ...ticatedUser.testCreateRepoFromTemplate.txt | 33 +++++++++++++++++++ ...CreateRepoFromTemplateWithAllArguments.txt | 33 +++++++++++++++++++ ...rganization.testCreateRepoFromTemplate.txt | 22 +++++++++++++ ...CreateRepoFromTemplateWithAllArguments.txt | 22 +++++++++++++ tests/Repository.py | 1 + 8 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt create mode 100644 tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt create mode 100644 tests/ReplayData/Organization.testCreateRepoFromTemplate.txt create mode 100644 tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 7c64dc1119..87eef67b01 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -506,7 +506,7 @@ def create_repo_from_template( private=github.GithubObject.NotSet, ): """ - :calls: `POST /repos/:owner/:name/generate `_ + :calls: `POST /repos/:template_owner/:template_repo/generate ` :param name: string :param repo :class:`github.Repository.Repository` :param description: string diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index a580ce4578..d290d8d0ad 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -659,6 +659,22 @@ def testCreateFork(self): repo = self.user.create_fork(self.g.get_user("nvie").get_repo("gitflow")) self.assertEqual(repo.source.full_name, "nvie/gitflow") + def testCreateRepoFromTemplate(self): + template_repo = self.g.get_repo("actions/hello-world-docker-action") + + repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo) + self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/hello-world-docker-action-new") + self.assertEqual(repo.is_template, False) + + def testCreateRepoFromTemplateWithAllArguments(self): + template_repo = self.g.get_repo("actions/hello-world-docker-action") + + description = "My repo from template" + private = True + repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) + self.assertEqual(repo.description, description) + self.assertEqual(repo.private, private) + def testGetNotification(self): notification = self.user.get_notification("8406712") self.assertEqual(notification.id, "8406712") diff --git a/tests/Organization.py b/tests/Organization.py index 16421d1959..b875d345bd 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -329,6 +329,22 @@ def testCreateFork(self): repo.url, "https://api.github.com/repos/BeaverSoftware/PyGithub" ) + def testCreateRepoFromTemplate(self): + template_repo = self.g.get_repo("actions/hello-world-docker-action") + + repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo) + self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new") + self.assertEqual(repo.is_template, False) + + def testCreateRepoFromTemplateWithAllArguments(self): + template_repo = self.g.get_repo("actions/hello-world-docker-action") + + description = "My repo from template" + private = True + repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) + self.assertEqual(repo.description, description) + self.assertEqual(repo.private, private) + def testInviteUserWithNeither(self): with self.assertRaises(AssertionError) as raisedexp: self.org.invite_user() diff --git a/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt new file mode 100644 index 0000000000..3ab48b9c2e --- /dev/null +++ b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt @@ -0,0 +1,33 @@ +https +GET +api.github.com +None +/repos/actions/hello-world-docker-action +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 16:56:45 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4997'), ('X-RateLimit-Reset', '1581443569'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', 'W/"63c75e6c241c8aa34fa31eaac3091d88"'), ('Last-Modified', 'Fri, 07 Feb 2020 09:28:27 GMT'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '5200:6A2A:85CA2:FC534:5E42DCCD')] +{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","private":false,"owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"admin":false,"push":false,"pull":true},"temp_clone_token":"","organization":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"network_count":30,"subscribers_count":1} + +https +GET +api.github.com +None +/user +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"79f748546e5fc4492505a70de6542183"'), ('date', 'Tue, 08 May 2012 09:51:20 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"public_repos":10,"type":"User","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","followers":13,"bio":"","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","disk_usage":16692,"plan":{"private_repos":5,"space":614400,"name":"micro","collaborators":1},"html_url":"https://github.com/jacquev6","blog":"http://vincent-jacques.net","login":"jacquev6","email":"vincent@vincent-jacques.net","created_at":"2010-07-09T06:10:06Z","company":"Criteo","location":"Paris, France","total_private_repos":5,"public_gists":1,"following":24,"name":"Vincent Jacques","id":327146,"owned_private_repos":5,"private_gists":5,"collaborators":0,"hireable":false,"node_id":"MDQ6VXNlcjMyNzE0Ng=="} + +https +POST +api.github.com +None +/repos/actions/hello-world-docker-action/generate +{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"name": "hello-world-docker-action-new", "owner": "jacquev6"} +201 +[('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 16:56:49 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '11775'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4995'), ('X-RateLimit-Reset', '1581443568'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"eabd6fce61227c57848e030e45c468c3"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/jacquev6/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '8C7A:1AEB:84521:F940F:5E42DCCE')] +{"id":239815940,"node_id":"MDEwOlJlcG9zaXRvcnkyMzk4MTU5NDA=","name":"hello-world-docker-action-new","full_name":"jacquev6/hello-world-docker-action-new","owner":{"login":"jacquev6","id":9718970,"node_id":"MDQ6VXNlcjk3MTg5NzA=","avatar_url":"https://avatars2.githubusercontent.com/u/9718970?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jacquev6/hello-world-docker-action-new","description":null,"fork":false,"url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new","forks_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/forks","keys_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/teams","hooks_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/hooks","issue_events_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues/events{/number}","events_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/events","assignees_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/assignees{/user}","branches_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/branches{/branch}","tags_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/tags","blobs_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/refs{/sha}","trees_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/statuses/{sha}","languages_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/languages","stargazers_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/stargazers","contributors_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/contributors","subscribers_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/subscribers","subscription_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/subscription","commits_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/commits{/sha}","git_commits_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/commits{/sha}","comments_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/comments{/number}","issue_comment_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues/comments{/number}","contents_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/contents/{+path}","compare_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/merges","archive_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/downloads","issues_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues{/number}","pulls_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/pulls{/number}","milestones_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/milestones{/number}","notifications_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/labels{/name}","releases_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/releases{/id}","deployments_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/deployments","created_at":"2020-02-11T16:56:47Z","updated_at":"2020-02-11T16:56:47Z","pushed_at":"2020-02-11T16:56:48Z","git_url":"git://github.com/jacquev6/hello-world-docker-action-new.git","ssh_url":"git@github.com:jacquev6/hello-world-docker-action-new.git","clone_url":"https://github.com/jacquev6/hello-world-docker-action-new.git","svn_url":"https://github.com/jacquev6/hello-world-docker-action-new","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"pull":true,"push":true,"admin":true},"is_template":false,"template_repository":{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"pull":true,"push":false,"admin":false},"is_template":true},"subscribers_count":1,"network_count":1} + diff --git a/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt new file mode 100644 index 0000000000..13bbac4fb8 --- /dev/null +++ b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt @@ -0,0 +1,33 @@ +https +GET +api.github.com +None +/repos/actions/hello-world-docker-action +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 19:18:56 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4996'), ('X-RateLimit-Reset', '1581452316'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', 'W/"63c75e6c241c8aa34fa31eaac3091d88"'), ('Last-Modified', 'Fri, 07 Feb 2020 09:28:27 GMT'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '1BD6:14E8:BA6CC:1C4CAD:5E42FE20')] +{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","private":false,"owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"admin":false,"push":false,"pull":true},"temp_clone_token":"","organization":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"network_count":30,"subscribers_count":1} + +https +GET +api.github.com +None +/user +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"79f748546e5fc4492505a70de6542183"'), ('date', 'Tue, 08 May 2012 09:51:20 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"public_repos":10,"type":"User","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","followers":13,"bio":"","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","disk_usage":16692,"plan":{"private_repos":5,"space":614400,"name":"micro","collaborators":1},"html_url":"https://github.com/jacquev6","blog":"http://vincent-jacques.net","login":"jacquev6","email":"vincent@vincent-jacques.net","created_at":"2010-07-09T06:10:06Z","company":"Criteo","location":"Paris, France","total_private_repos":5,"public_gists":1,"following":24,"name":"Vincent Jacques","id":327146,"owned_private_repos":5,"private_gists":5,"collaborators":0,"hireable":false,"node_id":"MDQ6VXNlcjMyNzE0Ng=="} + +https +POST +api.github.com +None +/repos/actions/hello-world-docker-action/generate +{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"name": "hello-world-docker-action-new", "owner": "jacquev6", "description": "My repo from template", "private": true} +201 +[('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 19:18:59 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '11794'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4994'), ('X-RateLimit-Reset', '1581452316'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"7fe9f51a711de4ffab9b930e33e3d875"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/jacquev6/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '3FB4:2492:632B7:FC388:5E42FE21')] +{"id":239844699,"node_id":"MDEwOlJlcG9zaXRvcnkyMzk4NDQ2OTk=","name":"hello-world-docker-action-new","full_name":"jacquev6/hello-world-docker-action-new","owner":{"login":"jacquev6","id":9718970,"node_id":"MDQ6VXNlcjk3MTg5NzA=","avatar_url":"https://avatars2.githubusercontent.com/u/9718970?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"private":true,"html_url":"https://github.com/jacquev6/hello-world-docker-action-new","description":"My repo from template","fork":false,"url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new","forks_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/forks","keys_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/teams","hooks_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/hooks","issue_events_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues/events{/number}","events_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/events","assignees_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/assignees{/user}","branches_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/branches{/branch}","tags_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/tags","blobs_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/refs{/sha}","trees_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/statuses/{sha}","languages_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/languages","stargazers_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/stargazers","contributors_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/contributors","subscribers_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/subscribers","subscription_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/subscription","commits_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/commits{/sha}","git_commits_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/commits{/sha}","comments_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/comments{/number}","issue_comment_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues/comments{/number}","contents_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/contents/{+path}","compare_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/merges","archive_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/downloads","issues_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues{/number}","pulls_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/pulls{/number}","milestones_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/milestones{/number}","notifications_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/labels{/name}","releases_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/releases{/id}","deployments_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/deployments","created_at":"2020-02-11T19:18:57Z","updated_at":"2020-02-11T19:18:57Z","pushed_at":"2020-02-11T19:18:59Z","git_url":"git://github.com/jacquev6/hello-world-docker-action-new.git","ssh_url":"git@github.com:jacquev6/hello-world-docker-action-new.git","clone_url":"https://github.com/jacquev6/hello-world-docker-action-new.git","svn_url":"https://github.com/jacquev6/hello-world-docker-action-new","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"pull":true,"push":true,"admin":true},"is_template":false,"template_repository":{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"pull":true,"push":false,"admin":false},"is_template":true},"subscribers_count":1,"network_count":1} + diff --git a/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt b/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt new file mode 100644 index 0000000000..9d97746918 --- /dev/null +++ b/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt @@ -0,0 +1,22 @@ +https +GET +api.github.com +None +/repos/actions/hello-world-docker-action +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 13:54:27 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4998'), ('X-RateLimit-Reset', '1581519266'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', 'W/"63c75e6c241c8aa34fa31eaac3091d88"'), ('Last-Modified', 'Fri, 07 Feb 2020 09:28:27 GMT'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '4A6A:20CC:7983B:E89EF:5E440392')] +{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","private":false,"owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"admin":false,"push":false,"pull":true},"temp_clone_token":"","organization":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"network_count":30,"subscribers_count":1} + +https +POST +api.github.com +None +/repos/actions/hello-world-docker-action/generate +{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"name": "hello-world-docker-action-new", "owner": "BeaverSoftware"} +201 +[('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 13:54:29 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '12600'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4997'), ('X-RateLimit-Reset', '1581519266'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"36abdc4630fb044196d6efbfc0f644e0"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '8C3C:2BF7:ACD4:17C45:5E440393')] +{"id":240025159,"node_id":"MDEwOlJlcG9zaXRvcnkyNDAwMjUxNTk=","name":"hello-world-docker-action-new","full_name":"BeaverSoftware/hello-world-docker-action-new","owner":{"login":"BeaverSoftware","id":60894054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwODk0MDU0","avatar_url":"https://avatars2.githubusercontent.com/u/60894054?v=4","gravatar_id":"","url":"https://api.github.com/users/BeaverSoftware","html_url":"https://github.com/BeaverSoftware","followers_url":"https://api.github.com/users/BeaverSoftware/followers","following_url":"https://api.github.com/users/BeaverSoftware/following{/other_user}","gists_url":"https://api.github.com/users/BeaverSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/BeaverSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeaverSoftware/subscriptions","organizations_url":"https://api.github.com/users/BeaverSoftware/orgs","repos_url":"https://api.github.com/users/BeaverSoftware/repos","events_url":"https://api.github.com/users/BeaverSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/BeaverSoftware/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new","description":null,"fork":false,"url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new","forks_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/forks","keys_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/teams","hooks_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/hooks","issue_events_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues/events{/number}","events_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/events","assignees_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/assignees{/user}","branches_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/branches{/branch}","tags_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/tags","blobs_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/refs{/sha}","trees_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/statuses/{sha}","languages_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/languages","stargazers_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/stargazers","contributors_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/contributors","subscribers_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/subscribers","subscription_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/subscription","commits_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/commits{/sha}","git_commits_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/commits{/sha}","comments_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/comments{/number}","issue_comment_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues/comments{/number}","contents_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/contents/{+path}","compare_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/merges","archive_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/downloads","issues_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues{/number}","pulls_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/pulls{/number}","milestones_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/milestones{/number}","notifications_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/labels{/name}","releases_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/releases{/id}","deployments_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/deployments","created_at":"2020-02-12T13:54:28Z","updated_at":"2020-02-12T13:54:28Z","pushed_at":"2020-02-12T13:54:29Z","git_url":"git://github.com/BeaverSoftware/hello-world-docker-action-new.git","ssh_url":"git@github.com:BeaverSoftware/hello-world-docker-action-new.git","clone_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new.git","svn_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"pull":true,"push":true,"admin":true},"is_template":false,"template_repository":{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"pull":true,"push":false,"admin":false},"is_template":true},"organization":{"login":"BeaverSoftware","id":60894054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwODk0MDU0","avatar_url":"https://avatars2.githubusercontent.com/u/60894054?v=4","gravatar_id":"","url":"https://api.github.com/users/BeaverSoftware","html_url":"https://github.com/BeaverSoftware","followers_url":"https://api.github.com/users/BeaverSoftware/followers","following_url":"https://api.github.com/users/BeaverSoftware/following{/other_user}","gists_url":"https://api.github.com/users/BeaverSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/BeaverSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeaverSoftware/subscriptions","organizations_url":"https://api.github.com/users/BeaverSoftware/orgs","repos_url":"https://api.github.com/users/BeaverSoftware/repos","events_url":"https://api.github.com/users/BeaverSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/BeaverSoftware/received_events","type":"Organization","site_admin":false},"subscribers_count":0,"network_count":1} + diff --git a/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt b/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt new file mode 100644 index 0000000000..8e45505ef5 --- /dev/null +++ b/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt @@ -0,0 +1,22 @@ +https +GET +api.github.com +None +/repos/actions/hello-world-docker-action +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 18:18:10 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4992'), ('X-RateLimit-Reset', '1581534987'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', 'W/"63c75e6c241c8aa34fa31eaac3091d88"'), ('Last-Modified', 'Fri, 07 Feb 2020 09:28:27 GMT'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '41AB:41D3:1FFAAB:3C0DBC:5E444162')] +{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","private":false,"owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"admin":false,"push":false,"pull":true},"temp_clone_token":"","organization":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"network_count":30,"subscribers_count":1} + +https +POST +api.github.com +None +/repos/actions/hello-world-docker-action/generate +{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"name": "hello-world-docker-action-new", "owner": "BeaverSoftware", "description": "My repo from template", "private": true} +201 +[('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 18:18:12 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '12619'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4991'), ('X-RateLimit-Reset', '1581534987'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"7ab10890a25b4661a4310dc8dbf4491f"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', 'C35C:1792:11E12C:2D04D2:5E444162')] +{"id":240083127,"node_id":"MDEwOlJlcG9zaXRvcnkyNDAwODMxMjc=","name":"hello-world-docker-action-new","full_name":"BeaverSoftware/hello-world-docker-action-new","owner":{"login":"BeaverSoftware","id":60894054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwODk0MDU0","avatar_url":"https://avatars2.githubusercontent.com/u/60894054?v=4","gravatar_id":"","url":"https://api.github.com/users/BeaverSoftware","html_url":"https://github.com/BeaverSoftware","followers_url":"https://api.github.com/users/BeaverSoftware/followers","following_url":"https://api.github.com/users/BeaverSoftware/following{/other_user}","gists_url":"https://api.github.com/users/BeaverSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/BeaverSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeaverSoftware/subscriptions","organizations_url":"https://api.github.com/users/BeaverSoftware/orgs","repos_url":"https://api.github.com/users/BeaverSoftware/repos","events_url":"https://api.github.com/users/BeaverSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/BeaverSoftware/received_events","type":"Organization","site_admin":false},"private":true,"html_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new","description":"My repo from template","fork":false,"url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new","forks_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/forks","keys_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/teams","hooks_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/hooks","issue_events_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues/events{/number}","events_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/events","assignees_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/assignees{/user}","branches_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/branches{/branch}","tags_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/tags","blobs_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/refs{/sha}","trees_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/statuses/{sha}","languages_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/languages","stargazers_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/stargazers","contributors_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/contributors","subscribers_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/subscribers","subscription_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/subscription","commits_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/commits{/sha}","git_commits_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/commits{/sha}","comments_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/comments{/number}","issue_comment_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues/comments{/number}","contents_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/contents/{+path}","compare_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/merges","archive_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/downloads","issues_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues{/number}","pulls_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/pulls{/number}","milestones_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/milestones{/number}","notifications_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/labels{/name}","releases_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/releases{/id}","deployments_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/deployments","created_at":"2020-02-12T18:18:11Z","updated_at":"2020-02-12T18:18:11Z","pushed_at":"2020-02-12T18:18:12Z","git_url":"git://github.com/BeaverSoftware/hello-world-docker-action-new.git","ssh_url":"git@github.com:BeaverSoftware/hello-world-docker-action-new.git","clone_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new.git","svn_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"pull":true,"push":true,"admin":true},"is_template":false,"template_repository":{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"pull":true,"push":false,"admin":false},"is_template":true},"organization":{"login":"BeaverSoftware","id":60894054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwODk0MDU0","avatar_url":"https://avatars2.githubusercontent.com/u/60894054?v=4","gravatar_id":"","url":"https://api.github.com/users/BeaverSoftware","html_url":"https://github.com/BeaverSoftware","followers_url":"https://api.github.com/users/BeaverSoftware/followers","following_url":"https://api.github.com/users/BeaverSoftware/following{/other_user}","gists_url":"https://api.github.com/users/BeaverSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/BeaverSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeaverSoftware/subscriptions","organizations_url":"https://api.github.com/users/BeaverSoftware/orgs","repos_url":"https://api.github.com/users/BeaverSoftware/repos","events_url":"https://api.github.com/users/BeaverSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/BeaverSoftware/received_events","type":"Organization","site_admin":false},"subscribers_count":0,"network_count":1} + diff --git a/tests/Repository.py b/tests/Repository.py index f3a569f9c2..0c88bb05b5 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -80,6 +80,7 @@ def testAttributes(self): self.assertEqual(self.repo.homepage, "http://vincent-jacques.net/PyGithub") self.assertEqual(self.repo.html_url, "https://github.com/jacquev6/PyGithub") self.assertEqual(self.repo.id, 3544490) + self.assertEqual(self.repo.is_template, None) self.assertEqual(self.repo.language, "Python") self.assertEqual(self.repo.master_branch, None) self.assertEqual(self.repo.name, "PyGithub") From ec44a8ba89bf3448b8dccfeb835375cba92eaa3d Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 17:16:29 -0300 Subject: [PATCH 05/25] Fix name assertion --- github/AuthenticatedUser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 87eef67b01..0c3249a5aa 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -513,7 +513,7 @@ def create_repo_from_template( :param private: bool :rtype: :class:`github.Repository.Repository` """ - assert isinstance(repo, github.Repository.Repository), repo + assert isinstance(name, str), name assert isinstance(repo, github.Repository.Repository), repo assert description is github.GithubObject.NotSet or isinstance( description, str From 1aac6e9dab1dbf51027d413d142cbcd2f151bd02 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 22:08:46 -0300 Subject: [PATCH 06/25] fix flake8 violation --- github/AuthenticatedUser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 0c3249a5aa..6eeb83463b 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -534,7 +534,7 @@ def create_repo_from_template( "/repos/" + repo.owner.login + "/" + repo.name + "/generate", input=post_parameters, headers={"Accept": Consts.mediaTypeTemplatesPreview}, - ) + ) return github.Repository.Repository( self._requester, headers, data, completed=True ) From 1e4e60502a2ed48695813384595366a1f3b1a115 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 22:32:01 -0300 Subject: [PATCH 07/25] refactor assertions --- tests/AuthenticatedUser.py | 2 +- tests/Organization.py | 2 +- tests/Repository.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index d290d8d0ad..709422f9b5 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -673,7 +673,7 @@ def testCreateRepoFromTemplateWithAllArguments(self): private = True repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) self.assertEqual(repo.description, description) - self.assertEqual(repo.private, private) + self.assertTrue(repo.private) def testGetNotification(self): notification = self.user.get_notification("8406712") diff --git a/tests/Organization.py b/tests/Organization.py index b875d345bd..40409a1f6f 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -343,7 +343,7 @@ def testCreateRepoFromTemplateWithAllArguments(self): private = True repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) self.assertEqual(repo.description, description) - self.assertEqual(repo.private, private) + self.assertTrue(repo.private) def testInviteUserWithNeither(self): with self.assertRaises(AssertionError) as raisedexp: diff --git a/tests/Repository.py b/tests/Repository.py index 0c88bb05b5..5b5f798b4e 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -80,7 +80,7 @@ def testAttributes(self): self.assertEqual(self.repo.homepage, "http://vincent-jacques.net/PyGithub") self.assertEqual(self.repo.html_url, "https://github.com/jacquev6/PyGithub") self.assertEqual(self.repo.id, 3544490) - self.assertEqual(self.repo.is_template, None) + self.assertIs(self.repo.is_template, None) self.assertEqual(self.repo.language, "Python") self.assertEqual(self.repo.master_branch, None) self.assertEqual(self.repo.name, "PyGithub") From a29b3c43010cdc8b8b5e64a6f6d29113026c496f Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 22:32:45 -0300 Subject: [PATCH 08/25] Revert scripts/add_attribute.py change --- github/Repository.py | 3413 -------------------------------------- scripts/add_attribute.py | 2 +- 2 files changed, 1 insertion(+), 3414 deletions(-) diff --git a/github/Repository.py b/github/Repository.py index b3a27dc4cb..e69de29bb2 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -1,3413 +0,0 @@ -# -*- coding: utf-8 -*- - -############################ Copyrights and license ############################ -# # -# Copyright 2012 Christopher Gilbert # -# Copyright 2012 Steve English # -# Copyright 2012 Vincent Jacques # -# Copyright 2012 Zearin # -# Copyright 2013 AKFish # -# Copyright 2013 Adrian Petrescu # -# Copyright 2013 Cameron White # -# Copyright 2013 David Farr # -# Copyright 2013 Mark Roddy # -# Copyright 2013 Vincent Jacques # -# Copyright 2013 martinqt # -# Copyright 2014 Vincent Jacques # -# Copyright 2015 Aaron Levine # -# Copyright 2015 Christopher Wilcox # -# Copyright 2015 Dan Vanderkam # -# Copyright 2015 Ed Holland # -# Copyright 2015 Enix Yu # -# Copyright 2015 Jay # -# Copyright 2015 Jimmy Zelinskie # -# Copyright 2015 Jonathan Debonis # -# Copyright 2015 Kevin Lewandowski # -# Copyright 2015 Kyle Hornberg # -# Copyright 2015 edhollandAL # -# Copyright 2016 @tmshn # -# Copyright 2016 Dustin Spicuzza # -# Copyright 2016 Enix Yu # -# Copyright 2016 Jannis Gebauer # -# Copyright 2016 Per Øyvind Karlsen # -# Copyright 2016 Peter Buckley # -# Copyright 2016 Sylvus # -# Copyright 2016 fukatani # -# Copyright 2016 ghfan # -# Copyright 2017 Andreas Lutro # -# Copyright 2017 Ben Firshman # -# Copyright 2017 Chris McBride # -# Copyright 2017 Hugo # -# Copyright 2017 Jannis Gebauer # -# Copyright 2017 Jason White # -# Copyright 2017 Jimmy Zelinskie # -# Copyright 2017 Nhomar Hernández [Vauxoo] # -# Copyright 2017 Simon # -# Copyright 2018 Andrew Smith # -# Copyright 2018 Brian Torres-Gil # -# Copyright 2018 Hayden Fuss # -# Copyright 2018 Ilya Konstantinov # -# Copyright 2018 Jacopo Notarstefano # -# Copyright 2018 John Hui # -# Copyright 2018 Mateusz Loskot # -# Copyright 2018 Michael Behrisch # -# Copyright 2018 Nicholas Buse # -# Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> # -# Copyright 2018 Shinichi TAMURA # -# Copyright 2018 Steve Kowalik # -# Copyright 2018 Wan Liuyang # -# Copyright 2018 Will Yardley # -# Copyright 2018 per1234 # -# Copyright 2018 sechastain # -# Copyright 2018 sfdye # -# Copyright 2018 Vinay Hegde # -# Copyright 2018 Justin Kufro # -# Copyright 2018 Ivan Minno # -# Copyright 2018 Zilei Gu # -# Copyright 2018 Yves Zumbach # -# Copyright 2018 Leying Chen # -# # -# This file is part of PyGithub. # -# http://pygithub.readthedocs.io/ # -# # -# PyGithub is free software: you can redistribute it and/or modify it under # -# the terms of the GNU Lesser General Public License as published by the Free # -# Software Foundation, either version 3 of the License, or (at your option) # -# any later version. # -# # -# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # -# details. # -# # -# You should have received a copy of the GNU Lesser General Public License # -# along with PyGithub. If not, see . # -# # -################################################################################ - -import collections -import datetime -import urllib.parse -from base64 import b64encode - -from deprecated import deprecated - -import github.Branch -import github.Clones -import github.Commit -import github.CommitComment -import github.Comparison -import github.ContentFile -import github.Download -import github.Event -import github.GitBlob -import github.GitCommit -import github.GithubObject -import github.GitRef -import github.GitRelease -import github.GitReleaseAsset -import github.GitTag -import github.GitTree -import github.Hook -import github.Invitation -import github.Issue -import github.IssueEvent -import github.Label -import github.Milestone -import github.NamedUser -import github.Organization -import github.PaginatedList -import github.Path -import github.Permissions -import github.Project -import github.PullRequest -import github.Referrer -import github.Repository -import github.RepositoryKey -import github.SourceImport -import github.Stargazer -import github.StatsCodeFrequency -import github.StatsCommitActivity -import github.StatsContributor -import github.StatsParticipation -import github.StatsPunchCard -import github.Tag -import github.Team -import github.View - -from . import Consts - - -class Repository(github.GithubObject.CompletableGithubObject): - """ - This class represents Repositories. The reference can be found here http://developer.github.com/v3/repos/ - """ - - def __repr__(self): - return self.get__repr__({"full_name": self._full_name.value}) - - @property - def allow_merge_commit(self): - """ - :type: bool - """ - self._completeIfNotSet(self._allow_merge_commit) - return self._allow_merge_commit.value - - @property - def allow_rebase_merge(self): - """ - :type: bool - """ - self._completeIfNotSet(self._allow_rebase_merge) - return self._allow_rebase_merge.value - - @property - def allow_squash_merge(self): - """ - :type: bool - """ - self._completeIfNotSet(self._allow_squash_merge) - return self._allow_squash_merge.value - - @property - def archived(self): - """ - :type: bool - """ - self._completeIfNotSet(self._archived) - return self._archived.value - - @property - def archive_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._archive_url) - return self._archive_url.value - - @property - def assignees_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._assignees_url) - return self._assignees_url.value - - @property - def blobs_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._blobs_url) - return self._blobs_url.value - - @property - def branches_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._branches_url) - return self._branches_url.value - - @property - def clone_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._clone_url) - return self._clone_url.value - - @property - def collaborators_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._collaborators_url) - return self._collaborators_url.value - - @property - def comments_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._comments_url) - return self._comments_url.value - - @property - def commits_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._commits_url) - return self._commits_url.value - - @property - def compare_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._compare_url) - return self._compare_url.value - - @property - def contents_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._contents_url) - return self._contents_url.value - - @property - def contributors_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._contributors_url) - return self._contributors_url.value - - @property - def created_at(self): - """ - :type: datetime.datetime - """ - self._completeIfNotSet(self._created_at) - return self._created_at.value - - @property - def default_branch(self): - """ - :type: string - """ - self._completeIfNotSet(self._default_branch) - return self._default_branch.value - - @property - def delete_branch_on_merge(self): - """ - :type: bool - """ - self._completeIfNotSet(self._delete_branch_on_merge) - return self._delete_branch_on_merge.value - - @property - def description(self): - """ - :type: string - """ - self._completeIfNotSet(self._description) - return self._description.value - - @property - def downloads_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._downloads_url) - return self._downloads_url.value - - @property - def events_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._events_url) - return self._events_url.value - - @property - def fork(self): - """ - :type: bool - """ - self._completeIfNotSet(self._fork) - return self._fork.value - - @property - def forks(self): - """ - :type: integer - """ - self._completeIfNotSet(self._forks) - return self._forks.value - - @property - def forks_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._forks_count) - return self._forks_count.value - - @property - def forks_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._forks_url) - return self._forks_url.value - - @property - def full_name(self): - """ - :type: string - """ - self._completeIfNotSet(self._full_name) - return self._full_name.value - - @property - def git_commits_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._git_commits_url) - return self._git_commits_url.value - - @property - def git_refs_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._git_refs_url) - return self._git_refs_url.value - - @property - def git_tags_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._git_tags_url) - return self._git_tags_url.value - - @property - def git_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._git_url) - return self._git_url.value - - @property - def has_downloads(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_downloads) - return self._has_downloads.value - - @property - def has_issues(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_issues) - return self._has_issues.value - - @property - def has_projects(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_projects) - return self._has_projects.value - - @property - def has_wiki(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_wiki) - return self._has_wiki.value - - @property - def homepage(self): - """ - :type: string - """ - self._completeIfNotSet(self._homepage) - return self._homepage.value - - @property - def hooks_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._hooks_url) - return self._hooks_url.value - - @property - def html_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._html_url) - return self._html_url.value - - @property - def id(self): - """ - :type: integer - """ - self._completeIfNotSet(self._id) - return self._id.value - - @property - def is_template(self): - """ - :type: bool - """ - self._completeIfNotSet(self._is_template) - return self._is_template.value - - @property - def issue_comment_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._issue_comment_url) - return self._issue_comment_url.value - - @property - def issue_events_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._issue_events_url) - return self._issue_events_url.value - - @property - def issues_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._issues_url) - return self._issues_url.value - - @property - def keys_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._keys_url) - return self._keys_url.value - - @property - def labels_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._labels_url) - return self._labels_url.value - - @property - def language(self): - """ - :type: string - """ - self._completeIfNotSet(self._language) - return self._language.value - - @property - def languages_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._languages_url) - return self._languages_url.value - - @property - def master_branch(self): - """ - :type: string - """ - self._completeIfNotSet(self._master_branch) - return self._master_branch.value - - @property - def merges_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._merges_url) - return self._merges_url.value - - @property - def milestones_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._milestones_url) - return self._milestones_url.value - - @property - def mirror_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._mirror_url) - return self._mirror_url.value - - @property - def name(self): - """ - :type: string - """ - self._completeIfNotSet(self._name) - return self._name.value - - @property - def network_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._network_count) - return self._network_count.value - - @property - def notifications_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._notifications_url) - return self._notifications_url.value - - @property - def open_issues(self): - """ - :type: integer - """ - self._completeIfNotSet(self._open_issues) - return self._open_issues.value - - @property - def open_issues_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._open_issues_count) - return self._open_issues_count.value - - @property - def organization(self): - """ - :type: :class:`github.Organization.Organization` - """ - self._completeIfNotSet(self._organization) - return self._organization.value - - @property - def owner(self): - """ - :type: :class:`github.NamedUser.NamedUser` - """ - self._completeIfNotSet(self._owner) - return self._owner.value - - @property - def parent(self): - """ - :type: :class:`github.Repository.Repository` - """ - self._completeIfNotSet(self._parent) - return self._parent.value - - @property - def permissions(self): - """ - :type: :class:`github.Permissions.Permissions` - """ - self._completeIfNotSet(self._permissions) - return self._permissions.value - - @property - def private(self): - """ - :type: bool - """ - self._completeIfNotSet(self._private) - return self._private.value - - @property - def pulls_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._pulls_url) - return self._pulls_url.value - - @property - def pushed_at(self): - """ - :type: datetime.datetime - """ - self._completeIfNotSet(self._pushed_at) - return self._pushed_at.value - - @property - def size(self): - """ - :type: integer - """ - self._completeIfNotSet(self._size) - return self._size.value - - @property - def source(self): - """ - :type: :class:`github.Repository.Repository` - """ - self._completeIfNotSet(self._source) - return self._source.value - - @property - def ssh_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._ssh_url) - return self._ssh_url.value - - @property - def stargazers_count(self): - """ - :type: integer - """ - self._completeIfNotSet( - self._stargazers_count - ) # pragma no cover (Should be covered) - return self._stargazers_count.value # pragma no cover (Should be covered) - - @property - def stargazers_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._stargazers_url) - return self._stargazers_url.value - - @property - def statuses_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._statuses_url) - return self._statuses_url.value - - @property - def subscribers_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._subscribers_url) - return self._subscribers_url.value - - @property - def subscribers_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._subscribers_count) - return self._subscribers_count.value - - @property - def subscription_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._subscription_url) - return self._subscription_url.value - - @property - def svn_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._svn_url) - return self._svn_url.value - - @property - def tags_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._tags_url) - return self._tags_url.value - - @property - def teams_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._teams_url) - return self._teams_url.value - - @property - def topics(self): - """ - :type: list of strings - """ - self._completeIfNotSet(self._topics) - return self._topics.value - - @property - def trees_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._trees_url) - return self._trees_url.value - - @property - def updated_at(self): - """ - :type: datetime.datetime - """ - self._completeIfNotSet(self._updated_at) - return self._updated_at.value - - @property - def url(self): - """ - :type: string - """ - self._completeIfNotSet(self._url) - return self._url.value - - @property - def watchers(self): - """ - :type: integer - """ - self._completeIfNotSet(self._watchers) - return self._watchers.value - - @property - def watchers_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._watchers_count) - return self._watchers_count.value - - def add_to_collaborators(self, collaborator, permission=github.GithubObject.NotSet): - """ - :calls: `PUT /repos/:owner/:repo/collaborators/:user `_ - :param collaborator: string or :class:`github.NamedUser.NamedUser` - :param permission: string 'pull', 'push' or 'admin' - :rtype: None - """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( - collaborator, str - ), collaborator - assert permission is github.GithubObject.NotSet or isinstance( - permission, str - ), permission - - if isinstance(collaborator, github.NamedUser.NamedUser): - collaborator = collaborator._identity - - if permission is not github.GithubObject.NotSet: - put_parameters = {"permission": permission} - else: - put_parameters = None - - headers, data = self._requester.requestJsonAndCheck( - "PUT", self.url + "/collaborators/" + collaborator, input=put_parameters - ) - # return an invitation object if there's data returned by the API. If data is empty - # there's a pending invitation for the given user. - return ( - github.Invitation.Invitation(self._requester, headers, data, completed=True) - if data is not None - else None - ) - - def get_collaborator_permission(self, collaborator): - """ - :calls: `GET /repos/:owner/:repo/collaborators/:username/permission `_ - :param collaborator: string or :class:`github.NamedUser.NamedUser` - :rtype: string - """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( - collaborator, str - ), collaborator - if isinstance(collaborator, github.NamedUser.NamedUser): - collaborator = collaborator._identity - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/collaborators/" + collaborator + "/permission", - ) - return data["permission"] - - def get_pending_invitations(self): - """ - :calls: `GET /repos/:owner/:repo/invitations `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Invitation.Invitation` - """ - return github.PaginatedList.PaginatedList( - github.Invitation.Invitation, - self._requester, - self.url + "/invitations", - None, - ) - - def remove_invitation(self, invite_id): - """ - :calls: `DELETE /repos/:owner/:repo/invitations/:invitation_id `_ - :rtype: None - """ - assert isinstance(invite_id, int), invite_id - - headers, data = self._requester.requestJsonAndCheck( - "DELETE", self.url + "/invitations/" + str(invite_id) - ) - - def compare(self, base, head): - """ - :calls: `GET /repos/:owner/:repo/compare/:base...:head `_ - :param base: string - :param head: string - :rtype: :class:`github.Comparison.Comparison` - """ - assert isinstance(base, str), base - assert isinstance(head, str), head - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/compare/" + base + "..." + head - ) - return github.Comparison.Comparison( - self._requester, headers, data, completed=True - ) - - def create_git_blob(self, content, encoding): - """ - :calls: `POST /repos/:owner/:repo/git/blobs `_ - :param content: string - :param encoding: string - :rtype: :class:`github.GitBlob.GitBlob` - """ - assert isinstance(content, str), content - assert isinstance(encoding, str), encoding - post_parameters = { - "content": content, - "encoding": encoding, - } - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/blobs", input=post_parameters - ) - return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) - - def create_git_commit( - self, - message, - tree, - parents, - author=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/:owner/:repo/git/commits `_ - :param message: string - :param tree: :class:`github.GitTree.GitTree` - :param parents: list of :class:`github.GitCommit.GitCommit` - :param author: :class:`github.InputGitAuthor.InputGitAuthor` - :param committer: :class:`github.InputGitAuthor.InputGitAuthor` - :rtype: :class:`github.GitCommit.GitCommit` - """ - assert isinstance(message, str), message - assert isinstance(tree, github.GitTree.GitTree), tree - assert all( - isinstance(element, github.GitCommit.GitCommit) for element in parents - ), parents - assert author is github.GithubObject.NotSet or isinstance( - author, github.InputGitAuthor - ), author - assert committer is github.GithubObject.NotSet or isinstance( - committer, github.InputGitAuthor - ), committer - post_parameters = { - "message": message, - "tree": tree._identity, - "parents": [element._identity for element in parents], - } - if author is not github.GithubObject.NotSet: - post_parameters["author"] = author._identity - if committer is not github.GithubObject.NotSet: - post_parameters["committer"] = committer._identity - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/commits", input=post_parameters - ) - return github.GitCommit.GitCommit( - self._requester, headers, data, completed=True - ) - - def create_git_ref(self, ref, sha): - """ - :calls: `POST /repos/:owner/:repo/git/refs `_ - :param ref: string - :param sha: string - :rtype: :class:`github.GitRef.GitRef` - """ - assert isinstance(ref, str), ref - assert isinstance(sha, str), sha - post_parameters = { - "ref": ref, - "sha": sha, - } - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/refs", input=post_parameters - ) - return github.GitRef.GitRef(self._requester, headers, data, completed=True) - - def create_git_tag_and_release( - self, - tag, - tag_message, - release_name, - release_message, - object, - type, - tagger=github.GithubObject.NotSet, - draft=False, - prerelease=False, - ): - self.create_git_tag(tag, tag_message, object, type, tagger) - return self.create_git_release( - tag, - release_name, - release_message, - draft, - prerelease, - target_commitish=object, - ) - - def create_git_release( - self, - tag, - name, - message, - draft=False, - prerelease=False, - target_commitish=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/:owner/:repo/releases `_ - :param tag: string - :param name: string - :param message: string - :param draft: bool - :param prerelease: bool - :param target_commitish: string or :class:`github.Branch.Branch` or :class:`github.Commit.Commit` or :class:`github.GitCommit.GitCommit` - :rtype: :class:`github.GitRelease.GitRelease` - """ - assert isinstance(tag, str), tag - assert isinstance(name, str), name - assert isinstance(message, str), message - assert isinstance(draft, bool), draft - assert isinstance(prerelease, bool), prerelease - assert target_commitish is github.GithubObject.NotSet or isinstance( - target_commitish, - ( - str, - github.Branch.Branch, - github.Commit.Commit, - github.GitCommit.GitCommit, - ), - ), target_commitish - post_parameters = { - "tag_name": tag, - "name": name, - "body": message, - "draft": draft, - "prerelease": prerelease, - } - if isinstance(target_commitish, str): - post_parameters["target_commitish"] = target_commitish - elif isinstance(target_commitish, github.Branch.Branch): - post_parameters["target_commitish"] = target_commitish.name - elif isinstance( - target_commitish, (github.Commit.Commit, github.GitCommit.GitCommit) - ): - post_parameters["target_commitish"] = target_commitish.sha - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/releases", input=post_parameters - ) - return github.GitRelease.GitRelease( - self._requester, headers, data, completed=True - ) - - def create_git_tag( - self, tag, message, object, type, tagger=github.GithubObject.NotSet - ): - """ - :calls: `POST /repos/:owner/:repo/git/tags `_ - :param tag: string - :param message: string - :param object: string - :param type: string - :param tagger: :class:`github.InputGitAuthor.InputGitAuthor` - :rtype: :class:`github.GitTag.GitTag` - """ - assert isinstance(tag, str), tag - assert isinstance(message, str), message - assert isinstance(object, str), object - assert isinstance(type, str), type - assert tagger is github.GithubObject.NotSet or isinstance( - tagger, github.InputGitAuthor - ), tagger - post_parameters = { - "tag": tag, - "message": message, - "object": object, - "type": type, - } - if tagger is not github.GithubObject.NotSet: - post_parameters["tagger"] = tagger._identity - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/tags", input=post_parameters - ) - return github.GitTag.GitTag(self._requester, headers, data, completed=True) - - def create_git_tree(self, tree, base_tree=github.GithubObject.NotSet): - """ - :calls: `POST /repos/:owner/:repo/git/trees `_ - :param tree: list of :class:`github.InputGitTreeElement.InputGitTreeElement` - :param base_tree: :class:`github.GitTree.GitTree` - :rtype: :class:`github.GitTree.GitTree` - """ - assert all( - isinstance(element, github.InputGitTreeElement) for element in tree - ), tree - assert base_tree is github.GithubObject.NotSet or isinstance( - base_tree, github.GitTree.GitTree - ), base_tree - post_parameters = { - "tree": [element._identity for element in tree], - } - if base_tree is not github.GithubObject.NotSet: - post_parameters["base_tree"] = base_tree._identity - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/trees", input=post_parameters - ) - return github.GitTree.GitTree(self._requester, headers, data, completed=True) - - def create_hook( - self, - name, - config, - events=github.GithubObject.NotSet, - active=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/:owner/:repo/hooks `_ - :param name: string - :param config: dict - :param events: list of string - :param active: bool - :rtype: :class:`github.Hook.Hook` - """ - assert isinstance(name, str), name - assert isinstance(config, dict), config - assert events is github.GithubObject.NotSet or all( - isinstance(element, str) for element in events - ), events - assert active is github.GithubObject.NotSet or isinstance(active, bool), active - post_parameters = { - "name": name, - "config": config, - } - if events is not github.GithubObject.NotSet: - post_parameters["events"] = events - if active is not github.GithubObject.NotSet: - post_parameters["active"] = active - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/hooks", input=post_parameters - ) - return github.Hook.Hook(self._requester, headers, data, completed=True) - - def create_issue( - self, - title, - body=github.GithubObject.NotSet, - assignee=github.GithubObject.NotSet, - milestone=github.GithubObject.NotSet, - labels=github.GithubObject.NotSet, - assignees=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/:owner/:repo/issues `_ - :param title: string - :param body: string - :param assignee: string or :class:`github.NamedUser.NamedUser` - :param assignees: list of string or :class:`github.NamedUser.NamedUser` - :param milestone: :class:`github.Milestone.Milestone` - :param labels: list of :class:`github.Label.Label` - :rtype: :class:`github.Issue.Issue` - """ - assert isinstance(title, str), title - assert body is github.GithubObject.NotSet or isinstance(body, str), body - assert ( - assignee is github.GithubObject.NotSet - or isinstance(assignee, github.NamedUser.NamedUser) - or isinstance(assignee, str) - ), assignee - assert assignees is github.GithubObject.NotSet or all( - isinstance(element, github.NamedUser.NamedUser) or isinstance(element, str) - for element in assignees - ), assignees - assert milestone is github.GithubObject.NotSet or isinstance( - milestone, github.Milestone.Milestone - ), milestone - assert labels is github.GithubObject.NotSet or all( - isinstance(element, github.Label.Label) or isinstance(element, str) - for element in labels - ), labels - - post_parameters = { - "title": title, - } - if body is not github.GithubObject.NotSet: - post_parameters["body"] = body - if assignee is not github.GithubObject.NotSet: - if isinstance(assignee, str): - post_parameters["assignee"] = assignee - else: - post_parameters["assignee"] = assignee._identity - if assignees is not github.GithubObject.NotSet: - post_parameters["assignees"] = [ - element._identity - if isinstance(element, github.NamedUser.NamedUser) - else element - for element in assignees - ] - if milestone is not github.GithubObject.NotSet: - post_parameters["milestone"] = milestone._identity - if labels is not github.GithubObject.NotSet: - post_parameters["labels"] = [ - element.name if isinstance(element, github.Label.Label) else element - for element in labels - ] - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/issues", input=post_parameters - ) - return github.Issue.Issue(self._requester, headers, data, completed=True) - - def create_key(self, title, key, read_only=False): - """ - :calls: `POST /repos/:owner/:repo/keys `_ - :param title: string - :param key: string - :param read_only: bool - :rtype: :class:`github.RepositoryKey.RepositoryKey` - """ - assert isinstance(title, str), title - assert isinstance(key, str), key - assert isinstance(read_only, bool), read_only - post_parameters = { - "title": title, - "key": key, - "read_only": read_only, - } - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/keys", input=post_parameters - ) - return github.RepositoryKey.RepositoryKey( - self._requester, headers, data, completed=True - ) - - def create_label(self, name, color, description=github.GithubObject.NotSet): - """ - :calls: `POST /repos/:owner/:repo/labels `_ - :param name: string - :param color: string - :param description: string - :rtype: :class:`github.Label.Label` - """ - assert isinstance(name, str), name - assert isinstance(color, str), color - assert description is github.GithubObject.NotSet or isinstance( - description, str - ), description - post_parameters = { - "name": name, - "color": color, - } - if description is not github.GithubObject.NotSet: - post_parameters["description"] = description - headers, data = self._requester.requestJsonAndCheck( - "POST", - self.url + "/labels", - input=post_parameters, - headers={"Accept": Consts.mediaTypeLabelDescriptionSearchPreview}, - ) - return github.Label.Label(self._requester, headers, data, completed=True) - - def create_milestone( - self, - title, - state=github.GithubObject.NotSet, - description=github.GithubObject.NotSet, - due_on=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/:owner/:repo/milestones `_ - :param title: string - :param state: string - :param description: string - :param due_on: datetime - :rtype: :class:`github.Milestone.Milestone` - """ - assert isinstance(title, str), title - assert state is github.GithubObject.NotSet or isinstance(state, str), state - assert description is github.GithubObject.NotSet or isinstance( - description, str - ), description - assert due_on is github.GithubObject.NotSet or isinstance( - due_on, (datetime.datetime, datetime.date) - ), due_on - post_parameters = { - "title": title, - } - if state is not github.GithubObject.NotSet: - post_parameters["state"] = state - if description is not github.GithubObject.NotSet: - post_parameters["description"] = description - if due_on is not github.GithubObject.NotSet: - if isinstance(due_on, datetime.date): - post_parameters["due_on"] = due_on.strftime("%Y-%m-%dT%H:%M:%SZ") - else: - post_parameters["due_on"] = due_on.isoformat() - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/milestones", input=post_parameters - ) - return github.Milestone.Milestone( - self._requester, headers, data, completed=True - ) - - def create_project(self, name, body=github.GithubObject.NotSet): - """ - :calls: `POST /repos/:owner/:repo/projects `_ - :param name: string - :param body: string - :rtype: :class:`github.Project.Project` - """ - assert isinstance(name, str), name - assert body is github.GithubObject.NotSet or isinstance(body, str), body - post_parameters = { - "name": name, - } - import_header = {"Accept": Consts.mediaTypeProjectsPreview} - if body is not github.GithubObject.NotSet: - post_parameters["body"] = body - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/projects", headers=import_header, input=post_parameters - ) - return github.Project.Project(self._requester, headers, data, completed=True) - - def create_pull(self, *args, **kwds): - """ - :calls: `POST /repos/:owner/:repo/pulls `_ - :param title: string - :param body: string - :param issue: :class:`github.Issue.Issue` - :param base: string - :param head: string - :param maintainer_can_modify: bool - :rtype: :class:`github.PullRequest.PullRequest` - """ - if len(args) + len(kwds) >= 4: - return self.__create_pull_1(*args, **kwds) - else: - return self.__create_pull_2(*args, **kwds) - - def __create_pull_1( - self, title, body, base, head, maintainer_can_modify=github.GithubObject.NotSet - ): - assert isinstance(title, str), title - assert isinstance(body, str), body - assert isinstance(base, str), base - assert isinstance(head, str), head - assert maintainer_can_modify is github.GithubObject.NotSet or isinstance( - maintainer_can_modify, bool - ), maintainer_can_modify - if maintainer_can_modify is not github.GithubObject.NotSet: - return self.__create_pull( - title=title, - body=body, - base=base, - head=head, - maintainer_can_modify=maintainer_can_modify, - ) - else: - return self.__create_pull(title=title, body=body, base=base, head=head) - - def __create_pull_2(self, issue, base, head): - assert isinstance(issue, github.Issue.Issue), issue - assert isinstance(base, str), base - assert isinstance(head, str), head - return self.__create_pull(issue=issue._identity, base=base, head=head) - - def __create_pull(self, **kwds): - post_parameters = kwds - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/pulls", input=post_parameters - ) - return github.PullRequest.PullRequest( - self._requester, headers, data, completed=True - ) - - def create_source_import( - self, - vcs, - vcs_url, - vcs_username=github.GithubObject.NotSet, - vcs_password=github.GithubObject.NotSet, - ): - """ - :calls: `PUT /repos/:owner/:repo/import `_ - :param vcs: string - :param vcs_url: string - :param vcs_username: string - :param vcs_password: string - :rtype: :class:`github.SourceImport.SourceImport` - """ - assert isinstance(vcs, str), vcs - assert isinstance(vcs_url, str), vcs_url - assert vcs_username is github.GithubObject.NotSet or isinstance( - vcs_username, str - ), vcs_username - assert vcs_password is github.GithubObject.NotSet or isinstance( - vcs_password, str - ), vcs_password - put_parameters = {"vcs": vcs, "vcs_url": vcs_url} - - if vcs_username is not github.GithubObject.NotSet: - put_parameters["vcs_username"] = vcs_username - - if vcs_password is not github.GithubObject.NotSet: - put_parameters["vcs_password"] = vcs_password - - import_header = {"Accept": Consts.mediaTypeImportPreview} - - headers, data = self._requester.requestJsonAndCheck( - "PUT", self.url + "/import", headers=import_header, input=put_parameters - ) - - return github.SourceImport.SourceImport( - self._requester, headers, data, completed=False - ) - - def delete(self): - """ - :calls: `DELETE /repos/:owner/:repo `_ - :rtype: None - """ - headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - - def edit( - self, - name=None, - description=github.GithubObject.NotSet, - homepage=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, - has_issues=github.GithubObject.NotSet, - has_projects=github.GithubObject.NotSet, - has_wiki=github.GithubObject.NotSet, - has_downloads=github.GithubObject.NotSet, - default_branch=github.GithubObject.NotSet, - allow_squash_merge=github.GithubObject.NotSet, - allow_merge_commit=github.GithubObject.NotSet, - allow_rebase_merge=github.GithubObject.NotSet, - delete_branch_on_merge=github.GithubObject.NotSet, - archived=github.GithubObject.NotSet, - ): - """ - :calls: `PATCH /repos/:owner/:repo `_ - :param name: string - :param description: string - :param homepage: string - :param private: bool - :param has_issues: bool - :param has_projects: bool - :param has_wiki: bool - :param has_downloads: bool - :param default_branch: string - :param allow_squash_merge: bool - :param allow_merge_commit: bool - :param allow_rebase_merge: bool - :param delete_branch_on_merge: bool - :param archived: bool. Unarchiving repositories is currently not supported through API (https://developer.github.com/v3/repos/#edit) - :rtype: None - """ - if name is None: - name = self.name - assert isinstance(name, str), name - assert description is github.GithubObject.NotSet or isinstance( - description, str - ), description - assert homepage is github.GithubObject.NotSet or isinstance( - homepage, str - ), homepage - assert private is github.GithubObject.NotSet or isinstance( - private, bool - ), private - assert has_issues is github.GithubObject.NotSet or isinstance( - has_issues, bool - ), has_issues - assert has_projects is github.GithubObject.NotSet or isinstance( - has_projects, bool - ), has_projects - assert has_wiki is github.GithubObject.NotSet or isinstance( - has_wiki, bool - ), has_wiki - assert has_downloads is github.GithubObject.NotSet or isinstance( - has_downloads, bool - ), has_downloads - assert default_branch is github.GithubObject.NotSet or isinstance( - default_branch, str - ), default_branch - assert allow_squash_merge is github.GithubObject.NotSet or isinstance( - allow_squash_merge, bool - ), allow_squash_merge - assert allow_merge_commit is github.GithubObject.NotSet or isinstance( - allow_merge_commit, bool - ), allow_merge_commit - assert allow_rebase_merge is github.GithubObject.NotSet or isinstance( - allow_rebase_merge, bool - ), allow_rebase_merge - assert delete_branch_on_merge is github.GithubObject.NotSet or isinstance( - delete_branch_on_merge, bool - ), delete_branch_on_merge - assert archived is github.GithubObject.NotSet or ( - isinstance(archived, bool) and archived is True - ), archived - post_parameters = { - "name": name, - } - if description is not github.GithubObject.NotSet: - post_parameters["description"] = description - if homepage is not github.GithubObject.NotSet: - post_parameters["homepage"] = homepage - if private is not github.GithubObject.NotSet: - post_parameters["private"] = private - if has_issues is not github.GithubObject.NotSet: - post_parameters["has_issues"] = has_issues - if has_projects is not github.GithubObject.NotSet: - post_parameters["has_projects"] = has_projects - if has_wiki is not github.GithubObject.NotSet: - post_parameters["has_wiki"] = has_wiki - if has_downloads is not github.GithubObject.NotSet: - post_parameters["has_downloads"] = has_downloads - if default_branch is not github.GithubObject.NotSet: - post_parameters["default_branch"] = default_branch - if allow_squash_merge is not github.GithubObject.NotSet: - post_parameters["allow_squash_merge"] = allow_squash_merge - if allow_merge_commit is not github.GithubObject.NotSet: - post_parameters["allow_merge_commit"] = allow_merge_commit - if allow_rebase_merge is not github.GithubObject.NotSet: - post_parameters["allow_rebase_merge"] = allow_rebase_merge - if delete_branch_on_merge is not github.GithubObject.NotSet: - post_parameters["delete_branch_on_merge"] = delete_branch_on_merge - if archived is not github.GithubObject.NotSet: - post_parameters["archived"] = archived - headers, data = self._requester.requestJsonAndCheck( - "PATCH", self.url, input=post_parameters - ) - self._useAttributes(data) - - def get_archive_link(self, archive_format, ref=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/:archive_format/:ref `_ - :param archive_format: string - :param ref: string - :rtype: string - """ - assert isinstance(archive_format, str), archive_format - assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref - url = self.url + "/" + archive_format - if ref is not github.GithubObject.NotSet: - url += "/" + ref - headers, data = self._requester.requestJsonAndCheck("GET", url) - return headers["location"] - - def get_assignees(self): - """ - :calls: `GET /repos/:owner/:repo/assignees `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, self.url + "/assignees", None - ) - - def get_branch(self, branch): - """ - :calls: `GET /repos/:owner/:repo/branches/:branch `_ - :param branch: string - :rtype: :class:`github.Branch.Branch` - """ - assert isinstance(branch, str), branch - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/branches/" + branch - ) - return github.Branch.Branch(self._requester, headers, data, completed=True) - - def get_branches(self): - """ - :calls: `GET /repos/:owner/:repo/branches `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Branch.Branch` - """ - return github.PaginatedList.PaginatedList( - github.Branch.Branch, self._requester, self.url + "/branches", None - ) - - def get_collaborators(self, affiliation=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/collaborators `_ - :param affiliation: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - - url_parameters = dict() - allowed_affiliations = ["outside", "direct", "all"] - if affiliation is not github.GithubObject.NotSet: - assert isinstance(affiliation, str), affiliation - assert ( - affiliation in allowed_affiliations - ), "Affiliation can be one of " + ", ".join(allowed_affiliations) - url_parameters["affiliation"] = affiliation - - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - self.url + "/collaborators", - url_parameters, - ) - - def get_comment(self, id): - """ - :calls: `GET /repos/:owner/:repo/comments/:id `_ - :param id: integer - :rtype: :class:`github.CommitComment.CommitComment` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/comments/" + str(id) - ) - return github.CommitComment.CommitComment( - self._requester, headers, data, completed=True - ) - - def get_comments(self): - """ - :calls: `GET /repos/:owner/:repo/comments `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CommitComment.CommitComment` - """ - return github.PaginatedList.PaginatedList( - github.CommitComment.CommitComment, - self._requester, - self.url + "/comments", - None, - ) - - def get_commit(self, sha): - """ - :calls: `GET /repos/:owner/:repo/commits/:sha `_ - :param sha: string - :rtype: :class:`github.Commit.Commit` - """ - assert isinstance(sha, str), sha - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/commits/" + sha - ) - return github.Commit.Commit(self._requester, headers, data, completed=True) - - def get_commits( - self, - sha=github.GithubObject.NotSet, - path=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - until=github.GithubObject.NotSet, - author=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/:owner/:repo/commits `_ - :param sha: string - :param path: string - :param since: datetime.datetime - :param until: datetime.datetime - :param author: string or :class:`github.NamedUser.NamedUser` or :class:`github.AuthenticatedUser.AuthenticatedUser` - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit` - """ - assert sha is github.GithubObject.NotSet or isinstance(sha, str), sha - assert path is github.GithubObject.NotSet or isinstance(path, str), path - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - assert until is github.GithubObject.NotSet or isinstance( - until, datetime.datetime - ), until - assert author is github.GithubObject.NotSet or isinstance( - author, - ( - str, - github.NamedUser.NamedUser, - github.AuthenticatedUser.AuthenticatedUser, - ), - ), author - url_parameters = dict() - if sha is not github.GithubObject.NotSet: - url_parameters["sha"] = sha - if path is not github.GithubObject.NotSet: - url_parameters["path"] = path - if since is not github.GithubObject.NotSet: - url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - if until is not github.GithubObject.NotSet: - url_parameters["until"] = until.strftime("%Y-%m-%dT%H:%M:%SZ") - if author is not github.GithubObject.NotSet: - if isinstance( - author, - ( - github.NamedUser.NamedUser, - github.AuthenticatedUser.AuthenticatedUser, - ), - ): - url_parameters["author"] = author.login - else: - url_parameters["author"] = author - return github.PaginatedList.PaginatedList( - github.Commit.Commit, self._requester, self.url + "/commits", url_parameters - ) - - def get_contents(self, path, ref=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/contents/:path `_ - :param path: string - :param ref: string - :rtype: :class:`github.ContentFile.ContentFile` or a list of them - """ - assert isinstance(path, str), path - assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref - # Path of '/' should be the empty string. - if path == "/": - path = "" - url_parameters = dict() - if ref is not github.GithubObject.NotSet: - url_parameters["ref"] = ref - headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/contents/" + urllib.parse.quote(path), - parameters=url_parameters, - ) - - # Handle 302 redirect response - if headers.get("status") == "302 Found" and headers.get("location"): - headers, data = self._requester.requestJsonAndCheck( - "GET", headers["location"], parameters=url_parameters - ) - - if isinstance(data, list): - return [ - # Lazy completion only makes sense for files. See discussion - # here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130 - github.ContentFile.ContentFile( - self._requester, headers, item, completed=(item["type"] != "file") - ) - for item in data - ] - return github.ContentFile.ContentFile( - self._requester, headers, data, completed=True - ) - - def get_top_referrers(self): - """ - :calls: `GET /repos/:owner/:repo/traffic/popular/referrers `_ - :rtype: :class:`list` of :class:`github.Referrer.Referrer` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/traffic/popular/referrers" - ) - if isinstance(data, list): - return [ - github.Referrer.Referrer(self._requester, headers, item, completed=True) - for item in data - ] - - def get_top_paths(self): - """ - :calls: `GET /repos/:owner/:repo/traffic/popular/paths `_ - :rtype: :class:`list` of :class:`github.Path.Path` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/traffic/popular/paths" - ) - if isinstance(data, list): - return [ - github.Path.Path(self._requester, headers, item, completed=True) - for item in data - ] - - def get_views_traffic(self, per=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/traffic/views `_ - :param per: string, must be one of day or week, day by default - :rtype: None or list of :class:`github.View.View` - """ - assert per is github.GithubObject.NotSet or ( - isinstance(per, str) and (per == "day" or per == "week") - ), "per must be day or week, day by default" - url_parameters = dict() - if per is not github.GithubObject.NotSet: - url_parameters["per"] = per - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/traffic/views", parameters=url_parameters - ) - if ( - (isinstance(data, dict)) - and ("views" in data) - and (isinstance(data["views"], list)) - ): - data["views"] = [ - github.View.View(self._requester, headers, item, completed=True) - for item in data["views"] - ] - return data - - def get_clones_traffic(self, per=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/traffic/clones `_ - :param per: string, must be one of day or week, day by default - :rtype: None or list of :class:`github.Clone.Clone` - """ - assert per is github.GithubObject.NotSet or ( - isinstance(per, str) and (per == "day" or per == "week") - ), "per must be day or week, day by default" - url_parameters = dict() - if per is not github.GithubObject.NotSet: - url_parameters["per"] = per - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/traffic/clones", parameters=url_parameters - ) - if ( - (isinstance(data, dict)) - and ("clones" in data) - and (isinstance(data["clones"], list)) - ): - data["clones"] = [ - github.Clones.Clones(self._requester, headers, item, completed=True) - for item in data["clones"] - ] - return data - - def get_projects(self, state=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/projects `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Project.Project` - :param state: string - """ - - url_parameters = dict() - if state is not github.GithubObject.NotSet: - url_parameters["state"] = state - - return github.PaginatedList.PaginatedList( - github.Project.Project, - self._requester, - self.url + "/projects", - url_parameters, - {"Accept": Consts.mediaTypeProjectsPreview}, - ) - - def create_file( - self, - path, - message, - content, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet, - ): - """Create a file in this repository. - - :calls: `PUT /repos/:owner/:repo/contents/:path `_ - :param path: string, (required), path of the file in the repository - :param message: string, (required), commit message - :param content: string, (required), the actual data in the file - :param branch: string, (optional), branch to create the commit on. Defaults to the default branch of the repository - :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. - :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. - :rtype: { - 'content': :class:`ContentFile `:, - 'commit': :class:`Commit `} - """ - assert isinstance(path, str) - assert isinstance(message, str) - assert isinstance(content, (str, bytes)) - assert branch is github.GithubObject.NotSet or isinstance(branch, str) - assert author is github.GithubObject.NotSet or isinstance( - author, github.InputGitAuthor - ) - assert committer is github.GithubObject.NotSet or isinstance( - committer, github.InputGitAuthor - ) - - if not isinstance(content, bytes): - content = content.encode("utf-8") - content = b64encode(content).decode("utf-8") - put_parameters = {"message": message, "content": content} - - if branch is not github.GithubObject.NotSet: - put_parameters["branch"] = branch - if author is not github.GithubObject.NotSet: - put_parameters["author"] = author._identity - if committer is not github.GithubObject.NotSet: - put_parameters["committer"] = committer._identity - - headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/contents/" + urllib.parse.quote(path), - input=put_parameters, - ) - - return { - "content": github.ContentFile.ContentFile( - self._requester, headers, data["content"], completed=False - ), - "commit": github.Commit.Commit( - self._requester, headers, data["commit"], completed=True - ), - } - - def update_file( - self, - path, - message, - content, - sha, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet, - ): - """This method updates a file in a repository - - :calls: `PUT /repos/:owner/:repo/contents/:path `_ - :param path: string, Required. The content path. - :param message: string, Required. The commit message. - :param content: string, Required. The updated file content, either base64 encoded, or ready to be encoded. - :param sha: string, Required. The blob SHA of the file being replaced. - :param branch: string. The branch name. Default: the repository’s default branch (usually master) - :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. - :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. - :rtype: { - 'content': :class:`ContentFile `:, - 'commit': :class:`Commit `} - """ - assert isinstance(path, str) - assert isinstance(message, str) - assert isinstance(content, (str, bytes)) - assert isinstance(sha, str) - assert branch is github.GithubObject.NotSet or isinstance(branch, str) - assert author is github.GithubObject.NotSet or isinstance( - author, github.InputGitAuthor - ) - assert committer is github.GithubObject.NotSet or isinstance( - committer, github.InputGitAuthor - ) - - if not isinstance(content, bytes): - content = content.encode("utf-8") - content = b64encode(content).decode("utf-8") - - put_parameters = {"message": message, "content": content, "sha": sha} - - if branch is not github.GithubObject.NotSet: - put_parameters["branch"] = branch - if author is not github.GithubObject.NotSet: - put_parameters["author"] = author._identity - if committer is not github.GithubObject.NotSet: - put_parameters["committer"] = committer._identity - - headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/contents/" + urllib.parse.quote(path), - input=put_parameters, - ) - - return { - "commit": github.Commit.Commit( - self._requester, headers, data["commit"], completed=True - ), - "content": github.ContentFile.ContentFile( - self._requester, headers, data["content"], completed=False - ), - } - - def delete_file( - self, - path, - message, - sha, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet, - ): - """This method deletes a file in a repository - - :calls: `DELETE /repos/:owner/:repo/contents/:path `_ - :param path: string, Required. The content path. - :param message: string, Required. The commit message. - :param sha: string, Required. The blob SHA of the file being replaced. - :param branch: string. The branch name. Default: the repository’s default branch (usually master) - :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. - :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. - :rtype: { - 'content': :class:`null `:, - 'commit': :class:`Commit `} - """ - assert isinstance(path, str), "path must be str/unicode object" - assert isinstance(message, str), "message must be str/unicode object" - assert isinstance(sha, str), "sha must be a str/unicode object" - assert branch is github.GithubObject.NotSet or isinstance( - branch, str - ), "branch must be a str/unicode object" - assert author is github.GithubObject.NotSet or isinstance( - author, github.InputGitAuthor - ), "author must be a github.InputGitAuthor object" - assert committer is github.GithubObject.NotSet or isinstance( - committer, github.InputGitAuthor - ), "committer must be a github.InputGitAuthor object" - - url_parameters = {"message": message, "sha": sha} - if branch is not github.GithubObject.NotSet: - url_parameters["branch"] = branch - if author is not github.GithubObject.NotSet: - url_parameters["author"] = author._identity - if committer is not github.GithubObject.NotSet: - url_parameters["committer"] = committer._identity - - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - self.url + "/contents/" + urllib.parse.quote(path), - input=url_parameters, - ) - - return { - "commit": github.Commit.Commit( - self._requester, headers, data["commit"], completed=True - ), - "content": github.GithubObject.NotSet, - } - - @deprecated( - reason=""" - Repository.get_dir_contents() is deprecated, use - Repository.get_contents() instead. - """ - ) - def get_dir_contents(self, path, ref=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/contents/:path `_ - :param path: string - :param ref: string - :rtype: list of :class:`github.ContentFile.ContentFile` - """ - return self.get_contents(path, ref=ref) - - def get_contributors(self, anon=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/contributors `_ - :param anon: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - url_parameters = dict() - if anon is not github.GithubObject.NotSet: - url_parameters["anon"] = anon - - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - self.url + "/contributors", - url_parameters, - ) - - def get_download(self, id): - """ - :calls: `GET /repos/:owner/:repo/downloads/:id `_ - :param id: integer - :rtype: :class:`github.Download.Download` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/downloads/" + str(id) - ) - return github.Download.Download(self._requester, headers, data, completed=True) - - def get_downloads(self): - """ - :calls: `GET /repos/:owner/:repo/downloads `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Download.Download` - """ - return github.PaginatedList.PaginatedList( - github.Download.Download, self._requester, self.url + "/downloads", None - ) - - def get_events(self): - """ - :calls: `GET /repos/:owner/:repo/events `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` - """ - return github.PaginatedList.PaginatedList( - github.Event.Event, self._requester, self.url + "/events", None - ) - - def get_forks(self): - """ - :calls: `GET /repos/:owner/:repo/forks `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` - """ - return github.PaginatedList.PaginatedList( - Repository, self._requester, self.url + "/forks", None - ) - - def create_fork(self, organization=github.GithubObject.NotSet): - """ - :calls: `POST /repos/:owner/:repo/forks `_ - :param organization: string or "none" or "*" - :rtype: :class:`github.Repository.Repository` - """ - assert organization is github.GithubObject.NotSet or isinstance( - organization, str - ), organization - post_parameters = {} - if organization is not github.GithubObject.NotSet: - post_parameters["organization"] = organization - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/forks", input=post_parameters, - ) - return Repository(self._requester, headers, data, completed=True) - - def get_git_blob(self, sha): - """ - :calls: `GET /repos/:owner/:repo/git/blobs/:sha `_ - :param sha: string - :rtype: :class:`github.GitBlob.GitBlob` - """ - assert isinstance(sha, str), sha - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/git/blobs/" + sha - ) - return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) - - def get_git_commit(self, sha): - """ - :calls: `GET /repos/:owner/:repo/git/commits/:sha `_ - :param sha: string - :rtype: :class:`github.GitCommit.GitCommit` - """ - assert isinstance(sha, str), sha - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/git/commits/" + sha - ) - return github.GitCommit.GitCommit( - self._requester, headers, data, completed=True - ) - - def get_git_ref(self, ref): - """ - :calls: `GET /repos/:owner/:repo/git/refs/:ref `_ - :param ref: string - :rtype: :class:`github.GitRef.GitRef` - """ - prefix = "/git/refs/" - if not self._requester.FIX_REPO_GET_GIT_REF: - prefix = "/git/" - assert isinstance(ref, str), ref - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + prefix + ref - ) - return github.GitRef.GitRef(self._requester, headers, data, completed=True) - - def get_git_refs(self): - """ - :calls: `GET /repos/:owner/:repo/git/refs `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRef.GitRef` - """ - return github.PaginatedList.PaginatedList( - github.GitRef.GitRef, self._requester, self.url + "/git/refs", None - ) - - def get_git_tag(self, sha): - """ - :calls: `GET /repos/:owner/:repo/git/tags/:sha `_ - :param sha: string - :rtype: :class:`github.GitTag.GitTag` - """ - assert isinstance(sha, str), sha - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/git/tags/" + sha - ) - return github.GitTag.GitTag(self._requester, headers, data, completed=True) - - def get_git_tree(self, sha, recursive=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/git/trees/:sha `_ - :param sha: string - :param recursive: bool - :rtype: :class:`github.GitTree.GitTree` - """ - assert isinstance(sha, str), sha - assert recursive is github.GithubObject.NotSet or isinstance( - recursive, bool - ), recursive - url_parameters = dict() - if recursive is not github.GithubObject.NotSet and recursive: - # GitHub API requires the recursive parameter be set to 1. - url_parameters["recursive"] = 1 - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/git/trees/" + sha, parameters=url_parameters - ) - return github.GitTree.GitTree(self._requester, headers, data, completed=True) - - def get_hook(self, id): - """ - :calls: `GET /repos/:owner/:repo/hooks/:id `_ - :param id: integer - :rtype: :class:`github.Hook.Hook` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/hooks/" + str(id) - ) - return github.Hook.Hook(self._requester, headers, data, completed=True) - - def get_hooks(self): - """ - :calls: `GET /repos/:owner/:repo/hooks `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook` - """ - return github.PaginatedList.PaginatedList( - github.Hook.Hook, self._requester, self.url + "/hooks", None - ) - - def get_issue(self, number): - """ - :calls: `GET /repos/:owner/:repo/issues/:number `_ - :param number: integer - :rtype: :class:`github.Issue.Issue` - """ - assert isinstance(number, int), number - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/issues/" + str(number) - ) - return github.Issue.Issue(self._requester, headers, data, completed=True) - - def get_issues( - self, - milestone=github.GithubObject.NotSet, - state=github.GithubObject.NotSet, - assignee=github.GithubObject.NotSet, - mentioned=github.GithubObject.NotSet, - labels=github.GithubObject.NotSet, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - creator=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/:owner/:repo/issues `_ - :param milestone: :class:`github.Milestone.Milestone` or "none" or "*" - :param state: string. `open`, `closed`, or `all`. If this is not set the GitHub API default behavior will be used. At the moment this is to return only open issues. This might change anytime on GitHub API side and it could be clever to explicitly specify the state value. - :param assignee: string or :class:`github.NamedUser.NamedUser` or "none" or "*" - :param mentioned: :class:`github.NamedUser.NamedUser` - :param labels: list of string or :class:`github.Label.Label` - :param sort: string - :param direction: string - :param since: datetime.datetime - :param creator: string or :class:`github.NamedUser.NamedUser` - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` - """ - assert ( - milestone is github.GithubObject.NotSet - or milestone == "*" - or milestone == "none" - or isinstance(milestone, github.Milestone.Milestone) - ), milestone - assert state is github.GithubObject.NotSet or isinstance(state, str), state - assert ( - assignee is github.GithubObject.NotSet - or isinstance(assignee, github.NamedUser.NamedUser) - or isinstance(assignee, str) - ), assignee - assert mentioned is github.GithubObject.NotSet or isinstance( - mentioned, github.NamedUser.NamedUser - ), mentioned - assert labels is github.GithubObject.NotSet or all( - isinstance(element, github.Label.Label) or isinstance(element, str) - for element in labels - ), labels - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - assert ( - creator is github.GithubObject.NotSet - or isinstance(creator, github.NamedUser.NamedUser) - or isinstance(creator, str) - ), creator - url_parameters = dict() - if milestone is not github.GithubObject.NotSet: - if isinstance(milestone, str): - url_parameters["milestone"] = milestone - else: - url_parameters["milestone"] = milestone._identity - if state is not github.GithubObject.NotSet: - url_parameters["state"] = state - if assignee is not github.GithubObject.NotSet: - if isinstance(assignee, str): - url_parameters["assignee"] = assignee - else: - url_parameters["assignee"] = assignee._identity - if mentioned is not github.GithubObject.NotSet: - url_parameters["mentioned"] = mentioned._identity - if labels is not github.GithubObject.NotSet: - url_parameters["labels"] = ",".join( - [ - label.name if isinstance(label, github.Label.Label) else label - for label in labels - ] - ) - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - if since is not github.GithubObject.NotSet: - url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - if creator is not github.GithubObject.NotSet: - if isinstance(creator, str): - url_parameters["creator"] = creator - else: - url_parameters["creator"] = creator._identity - return github.PaginatedList.PaginatedList( - github.Issue.Issue, self._requester, self.url + "/issues", url_parameters - ) - - def get_issues_comments( - self, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/:owner/:repo/issues/comments `_ - :param sort: string - :param direction: string - :param since: datetime.datetime - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment` - """ - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - url_parameters = dict() - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - if since is not github.GithubObject.NotSet: - url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - return github.PaginatedList.PaginatedList( - github.IssueComment.IssueComment, - self._requester, - self.url + "/issues/comments", - url_parameters, - ) - - def get_issues_event(self, id): - """ - :calls: `GET /repos/:owner/:repo/issues/events/:id `_ - :param id: integer - :rtype: :class:`github.IssueEvent.IssueEvent` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/issues/events/" + str(id), - headers={"Accept": Consts.mediaTypeLockReasonPreview}, - ) - return github.IssueEvent.IssueEvent( - self._requester, headers, data, completed=True - ) - - def get_issues_events(self): - """ - :calls: `GET /repos/:owner/:repo/issues/events `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueEvent.IssueEvent` - """ - return github.PaginatedList.PaginatedList( - github.IssueEvent.IssueEvent, - self._requester, - self.url + "/issues/events", - None, - headers={"Accept": Consts.mediaTypeLockReasonPreview}, - ) - - def get_key(self, id): - """ - :calls: `GET /repos/:owner/:repo/keys/:id `_ - :param id: integer - :rtype: :class:`github.RepositoryKey.RepositoryKey` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/keys/" + str(id) - ) - return github.RepositoryKey.RepositoryKey( - self._requester, headers, data, completed=True - ) - - def get_keys(self): - """ - :calls: `GET /repos/:owner/:repo/keys `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.RepositoryKey.RepositoryKey` - """ - return github.PaginatedList.PaginatedList( - github.RepositoryKey.RepositoryKey, - self._requester, - self.url + "/keys", - None, - ) - - def get_label(self, name): - """ - :calls: `GET /repos/:owner/:repo/labels/:name `_ - :param name: string - :rtype: :class:`github.Label.Label` - """ - assert isinstance(name, str), name - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/labels/" + urllib.parse.quote(name) - ) - return github.Label.Label(self._requester, headers, data, completed=True) - - def get_labels(self): - """ - :calls: `GET /repos/:owner/:repo/labels `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` - """ - return github.PaginatedList.PaginatedList( - github.Label.Label, self._requester, self.url + "/labels", None - ) - - def get_languages(self): - """ - :calls: `GET /repos/:owner/:repo/languages `_ - :rtype: dict of string to integer - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/languages" - ) - return data - - def get_license(self): - """ - :calls: `GET /repos/:owner/:repo/license `_ - :rtype: :class:`github.ContentFile.ContentFile` - """ - - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/license" - ) - return github.ContentFile.ContentFile( - self._requester, headers, data, completed=True - ) - - def get_milestone(self, number): - """ - :calls: `GET /repos/:owner/:repo/milestones/:number `_ - :param number: integer - :rtype: :class:`github.Milestone.Milestone` - """ - assert isinstance(number, int), number - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/milestones/" + str(number) - ) - return github.Milestone.Milestone( - self._requester, headers, data, completed=True - ) - - def get_milestones( - self, - state=github.GithubObject.NotSet, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/:owner/:repo/milestones `_ - :param state: string - :param sort: string - :param direction: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Milestone.Milestone` - """ - assert state is github.GithubObject.NotSet or isinstance(state, str), state - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - url_parameters = dict() - if state is not github.GithubObject.NotSet: - url_parameters["state"] = state - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - return github.PaginatedList.PaginatedList( - github.Milestone.Milestone, - self._requester, - self.url + "/milestones", - url_parameters, - ) - - def get_network_events(self): - """ - :calls: `GET /networks/:owner/:repo/events `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` - """ - return github.PaginatedList.PaginatedList( - github.Event.Event, - self._requester, - "/networks/" + self.owner.login + "/" + self.name + "/events", - None, - ) - - def get_pull(self, number): - """ - :calls: `GET /repos/:owner/:repo/pulls/:number `_ - :param number: integer - :rtype: :class:`github.PullRequest.PullRequest` - """ - assert isinstance(number, int), number - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/pulls/" + str(number) - ) - return github.PullRequest.PullRequest( - self._requester, headers, data, completed=True - ) - - def get_pulls( - self, - state=github.GithubObject.NotSet, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - base=github.GithubObject.NotSet, - head=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/:owner/:repo/pulls `_ - :param state: string - :param sort: string - :param direction: string - :param base: string - :param head: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequest.PullRequest` - """ - assert state is github.GithubObject.NotSet or isinstance(state, str), state - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert base is github.GithubObject.NotSet or isinstance(base, str), base - assert head is github.GithubObject.NotSet or isinstance(head, str), head - url_parameters = dict() - if state is not github.GithubObject.NotSet: - url_parameters["state"] = state - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - if base is not github.GithubObject.NotSet: - url_parameters["base"] = base - if head is not github.GithubObject.NotSet: - url_parameters["head"] = head - return github.PaginatedList.PaginatedList( - github.PullRequest.PullRequest, - self._requester, - self.url + "/pulls", - url_parameters, - ) - - def get_pulls_comments( - self, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/:owner/:repo/pulls/comments `_ - :param sort: string - :param direction: string - :param since: datetime.datetime - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` - """ - return self.get_pulls_review_comments(sort, direction, since) - - def get_pulls_review_comments( - self, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/:owner/:repo/pulls/comments `_ - :param sort: string - :param direction: string - :param since: datetime.datetime - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` - """ - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - url_parameters = dict() - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - if since is not github.GithubObject.NotSet: - url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - return github.PaginatedList.PaginatedList( - github.PullRequestComment.PullRequestComment, - self._requester, - self.url + "/pulls/comments", - url_parameters, - ) - - def get_readme(self, ref=github.GithubObject.NotSet): - """ - :calls: `GET /repos/:owner/:repo/readme `_ - :param ref: string - :rtype: :class:`github.ContentFile.ContentFile` - """ - assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref - url_parameters = dict() - if ref is not github.GithubObject.NotSet: - url_parameters["ref"] = ref - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/readme", parameters=url_parameters - ) - return github.ContentFile.ContentFile( - self._requester, headers, data, completed=True - ) - - def get_source_import(self): - """ - :calls: `GET /repos/:owner/:repo/import `_ - :rtype: :class:`github.SourceImport.SourceImport` - """ - import_header = {"Accept": Consts.mediaTypeImportPreview} - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/import", headers=import_header, - ) - if not data: - return None - else: - return github.SourceImport.SourceImport( - self._requester, headers, data, completed=True - ) - - def get_stargazers(self): - """ - :calls: `GET /repos/:owner/:repo/stargazers `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, self.url + "/stargazers", None - ) - - def get_stargazers_with_dates(self): - """ - :calls: `GET /repos/:owner/:repo/stargazers `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Stargazer.Stargazer` - """ - return github.PaginatedList.PaginatedList( - github.Stargazer.Stargazer, - self._requester, - self.url + "/stargazers", - None, - headers={"Accept": Consts.mediaTypeStarringPreview}, - ) - - def get_stats_contributors(self): - """ - :calls: `GET /repos/:owner/:repo/stats/contributors `_ - :rtype: None or list of :class:`github.StatsContributor.StatsContributor` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/contributors" - ) - if not data: - return None - else: - return [ - github.StatsContributor.StatsContributor( - self._requester, headers, attributes, completed=True - ) - for attributes in data - ] - - def get_stats_commit_activity(self): - """ - :calls: `GET /repos/:owner/:repo/stats/commit_activity `_ - :rtype: None or list of :class:`github.StatsCommitActivity.StatsCommitActivity` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/commit_activity" - ) - if not data: - return None - else: - return [ - github.StatsCommitActivity.StatsCommitActivity( - self._requester, headers, attributes, completed=True - ) - for attributes in data - ] - - def get_stats_code_frequency(self): - """ - :calls: `GET /repos/:owner/:repo/stats/code_frequency `_ - :rtype: None or list of :class:`github.StatsCodeFrequency.StatsCodeFrequency` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/code_frequency" - ) - if not data: - return None - else: - return [ - github.StatsCodeFrequency.StatsCodeFrequency( - self._requester, headers, attributes, completed=True - ) - for attributes in data - ] - - def get_stats_participation(self): - """ - :calls: `GET /repos/:owner/:repo/stats/participation `_ - :rtype: None or :class:`github.StatsParticipation.StatsParticipation` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/participation" - ) - if not data: - return None - else: - return github.StatsParticipation.StatsParticipation( - self._requester, headers, data, completed=True - ) - - def get_stats_punch_card(self): - """ - :calls: `GET /repos/:owner/:repo/stats/punch_card `_ - :rtype: None or :class:`github.StatsPunchCard.StatsPunchCard` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/punch_card" - ) - if not data: - return None - else: - return github.StatsPunchCard.StatsPunchCard( - self._requester, headers, data, completed=True - ) - - def get_subscribers(self): - """ - :calls: `GET /repos/:owner/:repo/subscribers `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, self.url + "/subscribers", None - ) - - def get_tags(self): - """ - :calls: `GET /repos/:owner/:repo/tags `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Tag.Tag` - """ - return github.PaginatedList.PaginatedList( - github.Tag.Tag, self._requester, self.url + "/tags", None - ) - - def get_releases(self): - """ - :calls: `GET /repos/:owner/:repo/releases `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRelease.GitRelease` - """ - return github.PaginatedList.PaginatedList( - github.GitRelease.GitRelease, self._requester, self.url + "/releases", None - ) - - def get_release(self, id): - """ - :calls: `GET /repos/:owner/:repo/releases/:id `_ - :param id: int (release id), str (tag name) - :rtype: None or :class:`github.GitRelease.GitRelease` - """ - if isinstance(id, int): - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/releases/" + str(id) - ) - return github.GitRelease.GitRelease( - self._requester, headers, data, completed=True - ) - elif isinstance(id, str): - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/releases/tags/" + id - ) - return github.GitRelease.GitRelease( - self._requester, headers, data, completed=True - ) - - def get_latest_release(self): - """ - :calls: `GET /repos/:owner/:repo/releases/latest `_ - :rtype: :class:`github.GitRelease.GitRelease` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/releases/latest" - ) - return github.GitRelease.GitRelease( - self._requester, headers, data, completed=True - ) - - def get_teams(self): - """ - :calls: `GET /repos/:owner/:repo/teams `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` - """ - return github.PaginatedList.PaginatedList( - github.Team.Team, self._requester, self.url + "/teams", None - ) - - def get_topics(self): - """ - :calls: `GET /repos/:owner/:repo/topics `_ - :rtype: list of strings - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", - self.url + "/topics", - headers={"Accept": Consts.mediaTypeTopicsPreview}, - ) - return data["names"] - - def get_watchers(self): - """ - :calls: `GET /repos/:owner/:repo/watchers `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, self.url + "/watchers", None - ) - - def has_in_assignees(self, assignee): - """ - :calls: `GET /repos/:owner/:repo/assignees/:assignee `_ - :param assignee: string or :class:`github.NamedUser.NamedUser` - :rtype: bool - """ - assert isinstance(assignee, github.NamedUser.NamedUser) or isinstance( - assignee, str - ), assignee - - if isinstance(assignee, github.NamedUser.NamedUser): - assignee = assignee._identity - - status, headers, data = self._requester.requestJson( - "GET", self.url + "/assignees/" + assignee - ) - return status == 204 - - def has_in_collaborators(self, collaborator): - """ - :calls: `GET /repos/:owner/:repo/collaborators/:user `_ - :param collaborator: string or :class:`github.NamedUser.NamedUser` - :rtype: bool - """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( - collaborator, str - ), collaborator - - if isinstance(collaborator, github.NamedUser.NamedUser): - collaborator = collaborator._identity - - status, headers, data = self._requester.requestJson( - "GET", self.url + "/collaborators/" + collaborator - ) - return status == 204 - - def _legacy_convert_issue(self, attributes): - convertedAttributes = { - "number": attributes["number"], - "url": "/repos" + urllib.parse.urlparse(attributes["html_url"]).path, - "user": { - "login": attributes["user"], - "url": "/users/" + attributes["user"], - }, - } - if "labels" in attributes: # pragma no branch - convertedAttributes["labels"] = [ - {"name": label} for label in attributes["labels"] - ] - for attr in ("title", "created_at", "comments", "body", "updated_at", "state"): - if attr in attributes: # pragma no branch - convertedAttributes[attr] = attributes[attr] - return convertedAttributes - - def legacy_search_issues(self, state, keyword): - """ - :calls: `GET /legacy/issues/search/:owner/:repository/:state/:keyword `_ - :param state: "open" or "closed" - :param keyword: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` - """ - assert state in ["open", "closed"], state - assert isinstance(keyword, str), keyword - headers, data = self._requester.requestJsonAndCheck( - "GET", - "/legacy/issues/search/" - + self.owner.login - + "/" - + self.name - + "/" - + state - + "/" - + urllib.parse.quote(keyword), - ) - return [ - github.Issue.Issue( - self._requester, - headers, - self._legacy_convert_issue(element), - completed=False, - ) - for element in data["issues"] - ] - - def get_notifications( - self, - all=github.GithubObject.NotSet, - participating=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - before=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/:owner/:repo/notifications `_ - :param all: bool - :param participating: bool - :param since: datetime.datetime - :param before: datetime.datetime - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification` - """ - - assert all is github.GithubObject.NotSet or isinstance(all, bool), all - assert participating is github.GithubObject.NotSet or isinstance( - participating, bool - ), participating - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - assert before is github.GithubObject.NotSet or isinstance( - before, datetime.datetime - ), before - - params = dict() - if all is not github.GithubObject.NotSet: - params["all"] = all - if participating is not github.GithubObject.NotSet: - params["participating"] = participating - if since is not github.GithubObject.NotSet: - params["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - if before is not github.GithubObject.NotSet: - params["before"] = before.strftime("%Y-%m-%dT%H:%M:%SZ") - - return github.PaginatedList.PaginatedList( - github.Notification.Notification, - self._requester, - self.url + "/notifications", - params, - ) - - def mark_notifications_as_read(self, last_read_at=datetime.datetime.utcnow()): - """ - :calls: `PUT /repos/:owner/:repo/notifications `_ - :param last_read_at: datetime - """ - assert isinstance(last_read_at, datetime.datetime) - put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} - - headers, data = self._requester.requestJsonAndCheck( - "PUT", self.url + "/notifications", input=put_parameters - ) - - def merge(self, base, head, commit_message=github.GithubObject.NotSet): - """ - :calls: `POST /repos/:owner/:repo/merges `_ - :param base: string - :param head: string - :param commit_message: string - :rtype: :class:`github.Commit.Commit` - """ - assert isinstance(base, str), base - assert isinstance(head, str), head - assert commit_message is github.GithubObject.NotSet or isinstance( - commit_message, str - ), commit_message - post_parameters = { - "base": base, - "head": head, - } - if commit_message is not github.GithubObject.NotSet: - post_parameters["commit_message"] = commit_message - headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/merges", input=post_parameters - ) - if data is None: - return None - else: - return github.Commit.Commit(self._requester, headers, data, completed=True) - - def replace_topics(self, topics): - """ - :calls: `PUT /repos/:owner/:repo/topics `_ - :param topics: list of strings - :rtype: None - """ - post_parameters = {"names": topics} - headers, data = self._requester.requestJsonAndCheck( - "PUT", - self.url + "/topics", - headers={"Accept": Consts.mediaTypeTopicsPreview}, - input=post_parameters, - ) - - def get_vulnerability_alert(self): - """ - :calls: `GET /repos/:owner/:repo/vulnerability-alerts `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "GET", - self.url + "/vulnerability-alerts", - headers={"Accept": Consts.vulnerabilityAlertsPreview}, - ) - return status == 204 - - def enable_vulnerability_alert(self): - """ - :calls: `PUT /repos/:owner/:repo/vulnerability-alerts `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "PUT", - self.url + "/vulnerability-alerts", - headers={"Accept": Consts.vulnerabilityAlertsPreview}, - ) - return status == 204 - - def disable_vulnerability_alert(self): - """ - :calls: `DELETE /repos/:owner/:repo/vulnerability-alerts `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "DELETE", - self.url + "/vulnerability-alerts", - headers={"Accept": Consts.vulnerabilityAlertsPreview}, - ) - return status == 204 - - def enable_automated_security_fixes(self): - """ - :calls: `PUT /repos/:owner/:repo/automated-security-fixes `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "PUT", - self.url + "/automated-security-fixes", - headers={"Accept": Consts.automatedSecurityFixes}, - ) - return status == 204 - - def disable_automated_security_fixes(self): - """ - :calls: `DELETE /repos/:owner/:repo/automated-security-fixes `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "DELETE", - self.url + "/automated-security-fixes", - headers={"Accept": Consts.automatedSecurityFixes}, - ) - return status == 204 - - def remove_from_collaborators(self, collaborator): - """ - :calls: `DELETE /repos/:owner/:repo/collaborators/:user `_ - :param collaborator: string or :class:`github.NamedUser.NamedUser` - :rtype: None - """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( - collaborator, str - ), collaborator - - if isinstance(collaborator, github.NamedUser.NamedUser): - collaborator = collaborator._identity - - headers, data = self._requester.requestJsonAndCheck( - "DELETE", self.url + "/collaborators/" + collaborator - ) - - def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet): - """ - :calls: `POST /hub `_ - :param event: string - :param callback: string - :param secret: string - :rtype: None - """ - return self._hub("subscribe", event, callback, secret) - - def unsubscribe_from_hub(self, event, callback): - """ - :calls: `POST /hub `_ - :param event: string - :param callback: string - :param secret: string - :rtype: None - """ - return self._hub("unsubscribe", event, callback, github.GithubObject.NotSet) - - def _hub(self, mode, event, callback, secret): - assert isinstance(mode, str), mode - assert isinstance(event, str), event - assert isinstance(callback, str), callback - assert secret is github.GithubObject.NotSet or isinstance(secret, str), secret - - post_parameters = collections.OrderedDict() - post_parameters["hub.callback"] = callback - post_parameters["hub.topic"] = ( - "https://github.com/" + self.full_name + "/events/" + event - ) - post_parameters["hub.mode"] = mode - if secret is not github.GithubObject.NotSet: - post_parameters["hub.secret"] = secret - - headers, output = self._requester.requestMultipartAndCheck( - "POST", "/hub", input=post_parameters - ) - - @property - def _identity(self): - return self.owner.login + "/" + self.name - - def get_release_asset(self, id): - assert isinstance(id, (int)), id - - resp_headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/releases/assets/" + str(id) - ) - return github.GitReleaseAsset.GitReleaseAsset( - self._requester, resp_headers, data, completed=True - ) - - def _initAttributes(self): - self._allow_merge_commit = github.GithubObject.NotSet - self._allow_rebase_merge = github.GithubObject.NotSet - self._allow_squash_merge = github.GithubObject.NotSet - self._archived = github.GithubObject.NotSet - self._archive_url = github.GithubObject.NotSet - self._assignees_url = github.GithubObject.NotSet - self._blobs_url = github.GithubObject.NotSet - self._branches_url = github.GithubObject.NotSet - self._clone_url = github.GithubObject.NotSet - self._collaborators_url = github.GithubObject.NotSet - self._comments_url = github.GithubObject.NotSet - self._commits_url = github.GithubObject.NotSet - self._compare_url = github.GithubObject.NotSet - self._contents_url = github.GithubObject.NotSet - self._contributors_url = github.GithubObject.NotSet - self._created_at = github.GithubObject.NotSet - self._default_branch = github.GithubObject.NotSet - self._delete_branch_on_merge = github.GithubObject.NotSet - self._description = github.GithubObject.NotSet - self._downloads_url = github.GithubObject.NotSet - self._events_url = github.GithubObject.NotSet - self._fork = github.GithubObject.NotSet - self._forks = github.GithubObject.NotSet - self._forks_count = github.GithubObject.NotSet - self._forks_url = github.GithubObject.NotSet - self._full_name = github.GithubObject.NotSet - self._git_commits_url = github.GithubObject.NotSet - self._git_refs_url = github.GithubObject.NotSet - self._git_tags_url = github.GithubObject.NotSet - self._git_url = github.GithubObject.NotSet - self._has_downloads = github.GithubObject.NotSet - self._has_issues = github.GithubObject.NotSet - self._has_projects = github.GithubObject.NotSet - self._has_wiki = github.GithubObject.NotSet - self._homepage = github.GithubObject.NotSet - self._hooks_url = github.GithubObject.NotSet - self._html_url = github.GithubObject.NotSet - self._id = github.GithubObject.NotSet - self._is_template = github.GithubObject.NotSet - self._issue_comment_url = github.GithubObject.NotSet - self._issue_events_url = github.GithubObject.NotSet - self._issues_url = github.GithubObject.NotSet - self._keys_url = github.GithubObject.NotSet - self._labels_url = github.GithubObject.NotSet - self._language = github.GithubObject.NotSet - self._languages_url = github.GithubObject.NotSet - self._master_branch = github.GithubObject.NotSet - self._merges_url = github.GithubObject.NotSet - self._milestones_url = github.GithubObject.NotSet - self._mirror_url = github.GithubObject.NotSet - self._name = github.GithubObject.NotSet - self._network_count = github.GithubObject.NotSet - self._notifications_url = github.GithubObject.NotSet - self._open_issues = github.GithubObject.NotSet - self._open_issues_count = github.GithubObject.NotSet - self._organization = github.GithubObject.NotSet - self._owner = github.GithubObject.NotSet - self._parent = github.GithubObject.NotSet - self._permissions = github.GithubObject.NotSet - self._private = github.GithubObject.NotSet - self._pulls_url = github.GithubObject.NotSet - self._pushed_at = github.GithubObject.NotSet - self._size = github.GithubObject.NotSet - self._source = github.GithubObject.NotSet - self._ssh_url = github.GithubObject.NotSet - self._stargazers_count = github.GithubObject.NotSet - self._stargazers_url = github.GithubObject.NotSet - self._statuses_url = github.GithubObject.NotSet - self._subscribers_url = github.GithubObject.NotSet - self._subscribers_count = github.GithubObject.NotSet - self._subscription_url = github.GithubObject.NotSet - self._svn_url = github.GithubObject.NotSet - self._tags_url = github.GithubObject.NotSet - self._teams_url = github.GithubObject.NotSet - self._topics = github.GithubObject.NotSet - self._trees_url = github.GithubObject.NotSet - self._updated_at = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - self._watchers = github.GithubObject.NotSet - self._watchers_count = github.GithubObject.NotSet - - def _useAttributes(self, attributes): - if "allow_merge_commit" in attributes: # pragma no branch - self._allow_merge_commit = self._makeBoolAttribute( - attributes["allow_merge_commit"] - ) - if "allow_rebase_merge" in attributes: # pragma no branch - self._allow_rebase_merge = self._makeBoolAttribute( - attributes["allow_rebase_merge"] - ) - if "allow_squash_merge" in attributes: # pragma no branch - self._allow_squash_merge = self._makeBoolAttribute( - attributes["allow_squash_merge"] - ) - if "archived" in attributes: # pragma no branch - self._archived = self._makeBoolAttribute(attributes["archived"]) - if "archive_url" in attributes: # pragma no branch - self._archive_url = self._makeStringAttribute(attributes["archive_url"]) - if "assignees_url" in attributes: # pragma no branch - self._assignees_url = self._makeStringAttribute(attributes["assignees_url"]) - if "blobs_url" in attributes: # pragma no branch - self._blobs_url = self._makeStringAttribute(attributes["blobs_url"]) - if "branches_url" in attributes: # pragma no branch - self._branches_url = self._makeStringAttribute(attributes["branches_url"]) - if "clone_url" in attributes: # pragma no branch - self._clone_url = self._makeStringAttribute(attributes["clone_url"]) - if "collaborators_url" in attributes: # pragma no branch - self._collaborators_url = self._makeStringAttribute( - attributes["collaborators_url"] - ) - if "comments_url" in attributes: # pragma no branch - self._comments_url = self._makeStringAttribute(attributes["comments_url"]) - if "commits_url" in attributes: # pragma no branch - self._commits_url = self._makeStringAttribute(attributes["commits_url"]) - if "compare_url" in attributes: # pragma no branch - self._compare_url = self._makeStringAttribute(attributes["compare_url"]) - if "contents_url" in attributes: # pragma no branch - self._contents_url = self._makeStringAttribute(attributes["contents_url"]) - if "contributors_url" in attributes: # pragma no branch - self._contributors_url = self._makeStringAttribute( - attributes["contributors_url"] - ) - if "created_at" in attributes: # pragma no branch - self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) - if "default_branch" in attributes: # pragma no branch - self._default_branch = self._makeStringAttribute( - attributes["default_branch"] - ) - if "delete_branch_on_merge" in attributes: # pragma no branch - self._delete_branch_on_merge = self._makeBoolAttribute( - attributes["delete_branch_on_merge"] - ) - if "description" in attributes: # pragma no branch - self._description = self._makeStringAttribute(attributes["description"]) - if "downloads_url" in attributes: # pragma no branch - self._downloads_url = self._makeStringAttribute(attributes["downloads_url"]) - if "events_url" in attributes: # pragma no branch - self._events_url = self._makeStringAttribute(attributes["events_url"]) - if "fork" in attributes: # pragma no branch - self._fork = self._makeBoolAttribute(attributes["fork"]) - if "forks" in attributes: # pragma no branch - self._forks = self._makeIntAttribute(attributes["forks"]) - if "forks_count" in attributes: # pragma no branch - self._forks_count = self._makeIntAttribute(attributes["forks_count"]) - if "forks_url" in attributes: # pragma no branch - self._forks_url = self._makeStringAttribute(attributes["forks_url"]) - if "full_name" in attributes: # pragma no branch - self._full_name = self._makeStringAttribute(attributes["full_name"]) - if "git_commits_url" in attributes: # pragma no branch - self._git_commits_url = self._makeStringAttribute( - attributes["git_commits_url"] - ) - if "git_refs_url" in attributes: # pragma no branch - self._git_refs_url = self._makeStringAttribute(attributes["git_refs_url"]) - if "git_tags_url" in attributes: # pragma no branch - self._git_tags_url = self._makeStringAttribute(attributes["git_tags_url"]) - if "git_url" in attributes: # pragma no branch - self._git_url = self._makeStringAttribute(attributes["git_url"]) - if "has_downloads" in attributes: # pragma no branch - self._has_downloads = self._makeBoolAttribute(attributes["has_downloads"]) - if "has_issues" in attributes: # pragma no branch - self._has_issues = self._makeBoolAttribute(attributes["has_issues"]) - if "has_projects" in attributes: # pragma no branch - self._has_projects = self._makeBoolAttribute(attributes["has_projects"]) - if "has_wiki" in attributes: # pragma no branch - self._has_wiki = self._makeBoolAttribute(attributes["has_wiki"]) - if "homepage" in attributes: # pragma no branch - self._homepage = self._makeStringAttribute(attributes["homepage"]) - if "hooks_url" in attributes: # pragma no branch - self._hooks_url = self._makeStringAttribute(attributes["hooks_url"]) - if "html_url" in attributes: # pragma no branch - self._html_url = self._makeStringAttribute(attributes["html_url"]) - if "id" in attributes: # pragma no branch - self._id = self._makeIntAttribute(attributes["id"]) - if "is_template" in attributes: # pragma no branch - self._is_template = self._makeBoolAttribute(attributes["is_template"]) - if "issue_comment_url" in attributes: # pragma no branch - self._issue_comment_url = self._makeStringAttribute( - attributes["issue_comment_url"] - ) - if "issue_events_url" in attributes: # pragma no branch - self._issue_events_url = self._makeStringAttribute( - attributes["issue_events_url"] - ) - if "issues_url" in attributes: # pragma no branch - self._issues_url = self._makeStringAttribute(attributes["issues_url"]) - if "keys_url" in attributes: # pragma no branch - self._keys_url = self._makeStringAttribute(attributes["keys_url"]) - if "labels_url" in attributes: # pragma no branch - self._labels_url = self._makeStringAttribute(attributes["labels_url"]) - if "language" in attributes: # pragma no branch - self._language = self._makeStringAttribute(attributes["language"]) - if "languages_url" in attributes: # pragma no branch - self._languages_url = self._makeStringAttribute(attributes["languages_url"]) - if "master_branch" in attributes: # pragma no branch - self._master_branch = self._makeStringAttribute(attributes["master_branch"]) - if "merges_url" in attributes: # pragma no branch - self._merges_url = self._makeStringAttribute(attributes["merges_url"]) - if "milestones_url" in attributes: # pragma no branch - self._milestones_url = self._makeStringAttribute( - attributes["milestones_url"] - ) - if "mirror_url" in attributes: # pragma no branch - self._mirror_url = self._makeStringAttribute(attributes["mirror_url"]) - if "name" in attributes: # pragma no branch - self._name = self._makeStringAttribute(attributes["name"]) - if "network_count" in attributes: # pragma no branch - self._network_count = self._makeIntAttribute(attributes["network_count"]) - if "notifications_url" in attributes: # pragma no branch - self._notifications_url = self._makeStringAttribute( - attributes["notifications_url"] - ) - if "open_issues" in attributes: # pragma no branch - self._open_issues = self._makeIntAttribute(attributes["open_issues"]) - if "open_issues_count" in attributes: # pragma no branch - self._open_issues_count = self._makeIntAttribute( - attributes["open_issues_count"] - ) - if "organization" in attributes: # pragma no branch - self._organization = self._makeClassAttribute( - github.Organization.Organization, attributes["organization"] - ) - if "owner" in attributes: # pragma no branch - self._owner = self._makeClassAttribute( - github.NamedUser.NamedUser, attributes["owner"] - ) - if "parent" in attributes: # pragma no branch - self._parent = self._makeClassAttribute(Repository, attributes["parent"]) - if "permissions" in attributes: # pragma no branch - self._permissions = self._makeClassAttribute( - github.Permissions.Permissions, attributes["permissions"] - ) - if "private" in attributes: # pragma no branch - self._private = self._makeBoolAttribute(attributes["private"]) - if "pulls_url" in attributes: # pragma no branch - self._pulls_url = self._makeStringAttribute(attributes["pulls_url"]) - if "pushed_at" in attributes: # pragma no branch - self._pushed_at = self._makeDatetimeAttribute(attributes["pushed_at"]) - if "size" in attributes: # pragma no branch - self._size = self._makeIntAttribute(attributes["size"]) - if "source" in attributes: # pragma no branch - self._source = self._makeClassAttribute(Repository, attributes["source"]) - if "ssh_url" in attributes: # pragma no branch - self._ssh_url = self._makeStringAttribute(attributes["ssh_url"]) - if "stargazers_count" in attributes: # pragma no branch - self._stargazers_count = self._makeIntAttribute( - attributes["stargazers_count"] - ) - if "stargazers_url" in attributes: # pragma no branch - self._stargazers_url = self._makeStringAttribute( - attributes["stargazers_url"] - ) - if "statuses_url" in attributes: # pragma no branch - self._statuses_url = self._makeStringAttribute(attributes["statuses_url"]) - if "subscribers_url" in attributes: # pragma no branch - self._subscribers_url = self._makeStringAttribute( - attributes["subscribers_url"] - ) - if "subscribers_count" in attributes: # pragma no branch - self._subscribers_count = self._makeIntAttribute( - attributes["subscribers_count"] - ) - if "subscription_url" in attributes: # pragma no branch - self._subscription_url = self._makeStringAttribute( - attributes["subscription_url"] - ) - if "svn_url" in attributes: # pragma no branch - self._svn_url = self._makeStringAttribute(attributes["svn_url"]) - if "tags_url" in attributes: # pragma no branch - self._tags_url = self._makeStringAttribute(attributes["tags_url"]) - if "teams_url" in attributes: # pragma no branch - self._teams_url = self._makeStringAttribute(attributes["teams_url"]) - if "trees_url" in attributes: # pragma no branch - self._trees_url = self._makeStringAttribute(attributes["trees_url"]) - if "topics" in attributes: # pragma no branch - self._topics = self._makeListOfStringsAttribute(attributes["topics"]) - if "updated_at" in attributes: # pragma no branch - self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) - if "url" in attributes: # pragma no branch - self._url = self._makeStringAttribute(attributes["url"]) - if "watchers" in attributes: # pragma no branch - self._watchers = self._makeIntAttribute(attributes["watchers"]) - if "watchers_count" in attributes: # pragma no branch - self._watchers_count = self._makeIntAttribute(attributes["watchers_count"]) diff --git a/scripts/add_attribute.py b/scripts/add_attribute.py index 281437d0e5..b905ca2d54 100644 --- a/scripts/add_attribute.py +++ b/scripts/add_attribute.py @@ -138,4 +138,4 @@ with open(fileName, "wb") as f: for line in newLines: - f.write((line + "\n").encode()) + f.write(line + "\n") From b4f5991eb139bfa12dd953399afccc8a6e4d81d3 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 22:41:33 -0300 Subject: [PATCH 09/25] Restore file delete by mistake --- github/Repository.py | 3413 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3413 insertions(+) diff --git a/github/Repository.py b/github/Repository.py index e69de29bb2..b3a27dc4cb 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -0,0 +1,3413 @@ +# -*- coding: utf-8 -*- + +############################ Copyrights and license ############################ +# # +# Copyright 2012 Christopher Gilbert # +# Copyright 2012 Steve English # +# Copyright 2012 Vincent Jacques # +# Copyright 2012 Zearin # +# Copyright 2013 AKFish # +# Copyright 2013 Adrian Petrescu # +# Copyright 2013 Cameron White # +# Copyright 2013 David Farr # +# Copyright 2013 Mark Roddy # +# Copyright 2013 Vincent Jacques # +# Copyright 2013 martinqt # +# Copyright 2014 Vincent Jacques # +# Copyright 2015 Aaron Levine # +# Copyright 2015 Christopher Wilcox # +# Copyright 2015 Dan Vanderkam # +# Copyright 2015 Ed Holland # +# Copyright 2015 Enix Yu # +# Copyright 2015 Jay # +# Copyright 2015 Jimmy Zelinskie # +# Copyright 2015 Jonathan Debonis # +# Copyright 2015 Kevin Lewandowski # +# Copyright 2015 Kyle Hornberg # +# Copyright 2015 edhollandAL # +# Copyright 2016 @tmshn # +# Copyright 2016 Dustin Spicuzza # +# Copyright 2016 Enix Yu # +# Copyright 2016 Jannis Gebauer # +# Copyright 2016 Per Øyvind Karlsen # +# Copyright 2016 Peter Buckley # +# Copyright 2016 Sylvus # +# Copyright 2016 fukatani # +# Copyright 2016 ghfan # +# Copyright 2017 Andreas Lutro # +# Copyright 2017 Ben Firshman # +# Copyright 2017 Chris McBride # +# Copyright 2017 Hugo # +# Copyright 2017 Jannis Gebauer # +# Copyright 2017 Jason White # +# Copyright 2017 Jimmy Zelinskie # +# Copyright 2017 Nhomar Hernández [Vauxoo] # +# Copyright 2017 Simon # +# Copyright 2018 Andrew Smith # +# Copyright 2018 Brian Torres-Gil # +# Copyright 2018 Hayden Fuss # +# Copyright 2018 Ilya Konstantinov # +# Copyright 2018 Jacopo Notarstefano # +# Copyright 2018 John Hui # +# Copyright 2018 Mateusz Loskot # +# Copyright 2018 Michael Behrisch # +# Copyright 2018 Nicholas Buse # +# Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> # +# Copyright 2018 Shinichi TAMURA # +# Copyright 2018 Steve Kowalik # +# Copyright 2018 Wan Liuyang # +# Copyright 2018 Will Yardley # +# Copyright 2018 per1234 # +# Copyright 2018 sechastain # +# Copyright 2018 sfdye # +# Copyright 2018 Vinay Hegde # +# Copyright 2018 Justin Kufro # +# Copyright 2018 Ivan Minno # +# Copyright 2018 Zilei Gu # +# Copyright 2018 Yves Zumbach # +# Copyright 2018 Leying Chen # +# # +# This file is part of PyGithub. # +# http://pygithub.readthedocs.io/ # +# # +# PyGithub is free software: you can redistribute it and/or modify it under # +# the terms of the GNU Lesser General Public License as published by the Free # +# Software Foundation, either version 3 of the License, or (at your option) # +# any later version. # +# # +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # +# details. # +# # +# You should have received a copy of the GNU Lesser General Public License # +# along with PyGithub. If not, see . # +# # +################################################################################ + +import collections +import datetime +import urllib.parse +from base64 import b64encode + +from deprecated import deprecated + +import github.Branch +import github.Clones +import github.Commit +import github.CommitComment +import github.Comparison +import github.ContentFile +import github.Download +import github.Event +import github.GitBlob +import github.GitCommit +import github.GithubObject +import github.GitRef +import github.GitRelease +import github.GitReleaseAsset +import github.GitTag +import github.GitTree +import github.Hook +import github.Invitation +import github.Issue +import github.IssueEvent +import github.Label +import github.Milestone +import github.NamedUser +import github.Organization +import github.PaginatedList +import github.Path +import github.Permissions +import github.Project +import github.PullRequest +import github.Referrer +import github.Repository +import github.RepositoryKey +import github.SourceImport +import github.Stargazer +import github.StatsCodeFrequency +import github.StatsCommitActivity +import github.StatsContributor +import github.StatsParticipation +import github.StatsPunchCard +import github.Tag +import github.Team +import github.View + +from . import Consts + + +class Repository(github.GithubObject.CompletableGithubObject): + """ + This class represents Repositories. The reference can be found here http://developer.github.com/v3/repos/ + """ + + def __repr__(self): + return self.get__repr__({"full_name": self._full_name.value}) + + @property + def allow_merge_commit(self): + """ + :type: bool + """ + self._completeIfNotSet(self._allow_merge_commit) + return self._allow_merge_commit.value + + @property + def allow_rebase_merge(self): + """ + :type: bool + """ + self._completeIfNotSet(self._allow_rebase_merge) + return self._allow_rebase_merge.value + + @property + def allow_squash_merge(self): + """ + :type: bool + """ + self._completeIfNotSet(self._allow_squash_merge) + return self._allow_squash_merge.value + + @property + def archived(self): + """ + :type: bool + """ + self._completeIfNotSet(self._archived) + return self._archived.value + + @property + def archive_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._archive_url) + return self._archive_url.value + + @property + def assignees_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._assignees_url) + return self._assignees_url.value + + @property + def blobs_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._blobs_url) + return self._blobs_url.value + + @property + def branches_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._branches_url) + return self._branches_url.value + + @property + def clone_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._clone_url) + return self._clone_url.value + + @property + def collaborators_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._collaborators_url) + return self._collaborators_url.value + + @property + def comments_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._comments_url) + return self._comments_url.value + + @property + def commits_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._commits_url) + return self._commits_url.value + + @property + def compare_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._compare_url) + return self._compare_url.value + + @property + def contents_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._contents_url) + return self._contents_url.value + + @property + def contributors_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._contributors_url) + return self._contributors_url.value + + @property + def created_at(self): + """ + :type: datetime.datetime + """ + self._completeIfNotSet(self._created_at) + return self._created_at.value + + @property + def default_branch(self): + """ + :type: string + """ + self._completeIfNotSet(self._default_branch) + return self._default_branch.value + + @property + def delete_branch_on_merge(self): + """ + :type: bool + """ + self._completeIfNotSet(self._delete_branch_on_merge) + return self._delete_branch_on_merge.value + + @property + def description(self): + """ + :type: string + """ + self._completeIfNotSet(self._description) + return self._description.value + + @property + def downloads_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._downloads_url) + return self._downloads_url.value + + @property + def events_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._events_url) + return self._events_url.value + + @property + def fork(self): + """ + :type: bool + """ + self._completeIfNotSet(self._fork) + return self._fork.value + + @property + def forks(self): + """ + :type: integer + """ + self._completeIfNotSet(self._forks) + return self._forks.value + + @property + def forks_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._forks_count) + return self._forks_count.value + + @property + def forks_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._forks_url) + return self._forks_url.value + + @property + def full_name(self): + """ + :type: string + """ + self._completeIfNotSet(self._full_name) + return self._full_name.value + + @property + def git_commits_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._git_commits_url) + return self._git_commits_url.value + + @property + def git_refs_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._git_refs_url) + return self._git_refs_url.value + + @property + def git_tags_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._git_tags_url) + return self._git_tags_url.value + + @property + def git_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._git_url) + return self._git_url.value + + @property + def has_downloads(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_downloads) + return self._has_downloads.value + + @property + def has_issues(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_issues) + return self._has_issues.value + + @property + def has_projects(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_projects) + return self._has_projects.value + + @property + def has_wiki(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_wiki) + return self._has_wiki.value + + @property + def homepage(self): + """ + :type: string + """ + self._completeIfNotSet(self._homepage) + return self._homepage.value + + @property + def hooks_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._hooks_url) + return self._hooks_url.value + + @property + def html_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._html_url) + return self._html_url.value + + @property + def id(self): + """ + :type: integer + """ + self._completeIfNotSet(self._id) + return self._id.value + + @property + def is_template(self): + """ + :type: bool + """ + self._completeIfNotSet(self._is_template) + return self._is_template.value + + @property + def issue_comment_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._issue_comment_url) + return self._issue_comment_url.value + + @property + def issue_events_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._issue_events_url) + return self._issue_events_url.value + + @property + def issues_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._issues_url) + return self._issues_url.value + + @property + def keys_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._keys_url) + return self._keys_url.value + + @property + def labels_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._labels_url) + return self._labels_url.value + + @property + def language(self): + """ + :type: string + """ + self._completeIfNotSet(self._language) + return self._language.value + + @property + def languages_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._languages_url) + return self._languages_url.value + + @property + def master_branch(self): + """ + :type: string + """ + self._completeIfNotSet(self._master_branch) + return self._master_branch.value + + @property + def merges_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._merges_url) + return self._merges_url.value + + @property + def milestones_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._milestones_url) + return self._milestones_url.value + + @property + def mirror_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._mirror_url) + return self._mirror_url.value + + @property + def name(self): + """ + :type: string + """ + self._completeIfNotSet(self._name) + return self._name.value + + @property + def network_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._network_count) + return self._network_count.value + + @property + def notifications_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._notifications_url) + return self._notifications_url.value + + @property + def open_issues(self): + """ + :type: integer + """ + self._completeIfNotSet(self._open_issues) + return self._open_issues.value + + @property + def open_issues_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._open_issues_count) + return self._open_issues_count.value + + @property + def organization(self): + """ + :type: :class:`github.Organization.Organization` + """ + self._completeIfNotSet(self._organization) + return self._organization.value + + @property + def owner(self): + """ + :type: :class:`github.NamedUser.NamedUser` + """ + self._completeIfNotSet(self._owner) + return self._owner.value + + @property + def parent(self): + """ + :type: :class:`github.Repository.Repository` + """ + self._completeIfNotSet(self._parent) + return self._parent.value + + @property + def permissions(self): + """ + :type: :class:`github.Permissions.Permissions` + """ + self._completeIfNotSet(self._permissions) + return self._permissions.value + + @property + def private(self): + """ + :type: bool + """ + self._completeIfNotSet(self._private) + return self._private.value + + @property + def pulls_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._pulls_url) + return self._pulls_url.value + + @property + def pushed_at(self): + """ + :type: datetime.datetime + """ + self._completeIfNotSet(self._pushed_at) + return self._pushed_at.value + + @property + def size(self): + """ + :type: integer + """ + self._completeIfNotSet(self._size) + return self._size.value + + @property + def source(self): + """ + :type: :class:`github.Repository.Repository` + """ + self._completeIfNotSet(self._source) + return self._source.value + + @property + def ssh_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._ssh_url) + return self._ssh_url.value + + @property + def stargazers_count(self): + """ + :type: integer + """ + self._completeIfNotSet( + self._stargazers_count + ) # pragma no cover (Should be covered) + return self._stargazers_count.value # pragma no cover (Should be covered) + + @property + def stargazers_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._stargazers_url) + return self._stargazers_url.value + + @property + def statuses_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._statuses_url) + return self._statuses_url.value + + @property + def subscribers_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._subscribers_url) + return self._subscribers_url.value + + @property + def subscribers_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._subscribers_count) + return self._subscribers_count.value + + @property + def subscription_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._subscription_url) + return self._subscription_url.value + + @property + def svn_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._svn_url) + return self._svn_url.value + + @property + def tags_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._tags_url) + return self._tags_url.value + + @property + def teams_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._teams_url) + return self._teams_url.value + + @property + def topics(self): + """ + :type: list of strings + """ + self._completeIfNotSet(self._topics) + return self._topics.value + + @property + def trees_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._trees_url) + return self._trees_url.value + + @property + def updated_at(self): + """ + :type: datetime.datetime + """ + self._completeIfNotSet(self._updated_at) + return self._updated_at.value + + @property + def url(self): + """ + :type: string + """ + self._completeIfNotSet(self._url) + return self._url.value + + @property + def watchers(self): + """ + :type: integer + """ + self._completeIfNotSet(self._watchers) + return self._watchers.value + + @property + def watchers_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._watchers_count) + return self._watchers_count.value + + def add_to_collaborators(self, collaborator, permission=github.GithubObject.NotSet): + """ + :calls: `PUT /repos/:owner/:repo/collaborators/:user `_ + :param collaborator: string or :class:`github.NamedUser.NamedUser` + :param permission: string 'pull', 'push' or 'admin' + :rtype: None + """ + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, str + ), collaborator + assert permission is github.GithubObject.NotSet or isinstance( + permission, str + ), permission + + if isinstance(collaborator, github.NamedUser.NamedUser): + collaborator = collaborator._identity + + if permission is not github.GithubObject.NotSet: + put_parameters = {"permission": permission} + else: + put_parameters = None + + headers, data = self._requester.requestJsonAndCheck( + "PUT", self.url + "/collaborators/" + collaborator, input=put_parameters + ) + # return an invitation object if there's data returned by the API. If data is empty + # there's a pending invitation for the given user. + return ( + github.Invitation.Invitation(self._requester, headers, data, completed=True) + if data is not None + else None + ) + + def get_collaborator_permission(self, collaborator): + """ + :calls: `GET /repos/:owner/:repo/collaborators/:username/permission `_ + :param collaborator: string or :class:`github.NamedUser.NamedUser` + :rtype: string + """ + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, str + ), collaborator + if isinstance(collaborator, github.NamedUser.NamedUser): + collaborator = collaborator._identity + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/collaborators/" + collaborator + "/permission", + ) + return data["permission"] + + def get_pending_invitations(self): + """ + :calls: `GET /repos/:owner/:repo/invitations `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Invitation.Invitation` + """ + return github.PaginatedList.PaginatedList( + github.Invitation.Invitation, + self._requester, + self.url + "/invitations", + None, + ) + + def remove_invitation(self, invite_id): + """ + :calls: `DELETE /repos/:owner/:repo/invitations/:invitation_id `_ + :rtype: None + """ + assert isinstance(invite_id, int), invite_id + + headers, data = self._requester.requestJsonAndCheck( + "DELETE", self.url + "/invitations/" + str(invite_id) + ) + + def compare(self, base, head): + """ + :calls: `GET /repos/:owner/:repo/compare/:base...:head `_ + :param base: string + :param head: string + :rtype: :class:`github.Comparison.Comparison` + """ + assert isinstance(base, str), base + assert isinstance(head, str), head + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/compare/" + base + "..." + head + ) + return github.Comparison.Comparison( + self._requester, headers, data, completed=True + ) + + def create_git_blob(self, content, encoding): + """ + :calls: `POST /repos/:owner/:repo/git/blobs `_ + :param content: string + :param encoding: string + :rtype: :class:`github.GitBlob.GitBlob` + """ + assert isinstance(content, str), content + assert isinstance(encoding, str), encoding + post_parameters = { + "content": content, + "encoding": encoding, + } + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/blobs", input=post_parameters + ) + return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) + + def create_git_commit( + self, + message, + tree, + parents, + author=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/git/commits `_ + :param message: string + :param tree: :class:`github.GitTree.GitTree` + :param parents: list of :class:`github.GitCommit.GitCommit` + :param author: :class:`github.InputGitAuthor.InputGitAuthor` + :param committer: :class:`github.InputGitAuthor.InputGitAuthor` + :rtype: :class:`github.GitCommit.GitCommit` + """ + assert isinstance(message, str), message + assert isinstance(tree, github.GitTree.GitTree), tree + assert all( + isinstance(element, github.GitCommit.GitCommit) for element in parents + ), parents + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ), author + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ), committer + post_parameters = { + "message": message, + "tree": tree._identity, + "parents": [element._identity for element in parents], + } + if author is not github.GithubObject.NotSet: + post_parameters["author"] = author._identity + if committer is not github.GithubObject.NotSet: + post_parameters["committer"] = committer._identity + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/commits", input=post_parameters + ) + return github.GitCommit.GitCommit( + self._requester, headers, data, completed=True + ) + + def create_git_ref(self, ref, sha): + """ + :calls: `POST /repos/:owner/:repo/git/refs `_ + :param ref: string + :param sha: string + :rtype: :class:`github.GitRef.GitRef` + """ + assert isinstance(ref, str), ref + assert isinstance(sha, str), sha + post_parameters = { + "ref": ref, + "sha": sha, + } + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/refs", input=post_parameters + ) + return github.GitRef.GitRef(self._requester, headers, data, completed=True) + + def create_git_tag_and_release( + self, + tag, + tag_message, + release_name, + release_message, + object, + type, + tagger=github.GithubObject.NotSet, + draft=False, + prerelease=False, + ): + self.create_git_tag(tag, tag_message, object, type, tagger) + return self.create_git_release( + tag, + release_name, + release_message, + draft, + prerelease, + target_commitish=object, + ) + + def create_git_release( + self, + tag, + name, + message, + draft=False, + prerelease=False, + target_commitish=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/releases `_ + :param tag: string + :param name: string + :param message: string + :param draft: bool + :param prerelease: bool + :param target_commitish: string or :class:`github.Branch.Branch` or :class:`github.Commit.Commit` or :class:`github.GitCommit.GitCommit` + :rtype: :class:`github.GitRelease.GitRelease` + """ + assert isinstance(tag, str), tag + assert isinstance(name, str), name + assert isinstance(message, str), message + assert isinstance(draft, bool), draft + assert isinstance(prerelease, bool), prerelease + assert target_commitish is github.GithubObject.NotSet or isinstance( + target_commitish, + ( + str, + github.Branch.Branch, + github.Commit.Commit, + github.GitCommit.GitCommit, + ), + ), target_commitish + post_parameters = { + "tag_name": tag, + "name": name, + "body": message, + "draft": draft, + "prerelease": prerelease, + } + if isinstance(target_commitish, str): + post_parameters["target_commitish"] = target_commitish + elif isinstance(target_commitish, github.Branch.Branch): + post_parameters["target_commitish"] = target_commitish.name + elif isinstance( + target_commitish, (github.Commit.Commit, github.GitCommit.GitCommit) + ): + post_parameters["target_commitish"] = target_commitish.sha + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/releases", input=post_parameters + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True + ) + + def create_git_tag( + self, tag, message, object, type, tagger=github.GithubObject.NotSet + ): + """ + :calls: `POST /repos/:owner/:repo/git/tags `_ + :param tag: string + :param message: string + :param object: string + :param type: string + :param tagger: :class:`github.InputGitAuthor.InputGitAuthor` + :rtype: :class:`github.GitTag.GitTag` + """ + assert isinstance(tag, str), tag + assert isinstance(message, str), message + assert isinstance(object, str), object + assert isinstance(type, str), type + assert tagger is github.GithubObject.NotSet or isinstance( + tagger, github.InputGitAuthor + ), tagger + post_parameters = { + "tag": tag, + "message": message, + "object": object, + "type": type, + } + if tagger is not github.GithubObject.NotSet: + post_parameters["tagger"] = tagger._identity + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/tags", input=post_parameters + ) + return github.GitTag.GitTag(self._requester, headers, data, completed=True) + + def create_git_tree(self, tree, base_tree=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/git/trees `_ + :param tree: list of :class:`github.InputGitTreeElement.InputGitTreeElement` + :param base_tree: :class:`github.GitTree.GitTree` + :rtype: :class:`github.GitTree.GitTree` + """ + assert all( + isinstance(element, github.InputGitTreeElement) for element in tree + ), tree + assert base_tree is github.GithubObject.NotSet or isinstance( + base_tree, github.GitTree.GitTree + ), base_tree + post_parameters = { + "tree": [element._identity for element in tree], + } + if base_tree is not github.GithubObject.NotSet: + post_parameters["base_tree"] = base_tree._identity + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/trees", input=post_parameters + ) + return github.GitTree.GitTree(self._requester, headers, data, completed=True) + + def create_hook( + self, + name, + config, + events=github.GithubObject.NotSet, + active=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/hooks `_ + :param name: string + :param config: dict + :param events: list of string + :param active: bool + :rtype: :class:`github.Hook.Hook` + """ + assert isinstance(name, str), name + assert isinstance(config, dict), config + assert events is github.GithubObject.NotSet or all( + isinstance(element, str) for element in events + ), events + assert active is github.GithubObject.NotSet or isinstance(active, bool), active + post_parameters = { + "name": name, + "config": config, + } + if events is not github.GithubObject.NotSet: + post_parameters["events"] = events + if active is not github.GithubObject.NotSet: + post_parameters["active"] = active + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/hooks", input=post_parameters + ) + return github.Hook.Hook(self._requester, headers, data, completed=True) + + def create_issue( + self, + title, + body=github.GithubObject.NotSet, + assignee=github.GithubObject.NotSet, + milestone=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + assignees=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/issues `_ + :param title: string + :param body: string + :param assignee: string or :class:`github.NamedUser.NamedUser` + :param assignees: list of string or :class:`github.NamedUser.NamedUser` + :param milestone: :class:`github.Milestone.Milestone` + :param labels: list of :class:`github.Label.Label` + :rtype: :class:`github.Issue.Issue` + """ + assert isinstance(title, str), title + assert body is github.GithubObject.NotSet or isinstance(body, str), body + assert ( + assignee is github.GithubObject.NotSet + or isinstance(assignee, github.NamedUser.NamedUser) + or isinstance(assignee, str) + ), assignee + assert assignees is github.GithubObject.NotSet or all( + isinstance(element, github.NamedUser.NamedUser) or isinstance(element, str) + for element in assignees + ), assignees + assert milestone is github.GithubObject.NotSet or isinstance( + milestone, github.Milestone.Milestone + ), milestone + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) or isinstance(element, str) + for element in labels + ), labels + + post_parameters = { + "title": title, + } + if body is not github.GithubObject.NotSet: + post_parameters["body"] = body + if assignee is not github.GithubObject.NotSet: + if isinstance(assignee, str): + post_parameters["assignee"] = assignee + else: + post_parameters["assignee"] = assignee._identity + if assignees is not github.GithubObject.NotSet: + post_parameters["assignees"] = [ + element._identity + if isinstance(element, github.NamedUser.NamedUser) + else element + for element in assignees + ] + if milestone is not github.GithubObject.NotSet: + post_parameters["milestone"] = milestone._identity + if labels is not github.GithubObject.NotSet: + post_parameters["labels"] = [ + element.name if isinstance(element, github.Label.Label) else element + for element in labels + ] + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/issues", input=post_parameters + ) + return github.Issue.Issue(self._requester, headers, data, completed=True) + + def create_key(self, title, key, read_only=False): + """ + :calls: `POST /repos/:owner/:repo/keys `_ + :param title: string + :param key: string + :param read_only: bool + :rtype: :class:`github.RepositoryKey.RepositoryKey` + """ + assert isinstance(title, str), title + assert isinstance(key, str), key + assert isinstance(read_only, bool), read_only + post_parameters = { + "title": title, + "key": key, + "read_only": read_only, + } + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/keys", input=post_parameters + ) + return github.RepositoryKey.RepositoryKey( + self._requester, headers, data, completed=True + ) + + def create_label(self, name, color, description=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/labels `_ + :param name: string + :param color: string + :param description: string + :rtype: :class:`github.Label.Label` + """ + assert isinstance(name, str), name + assert isinstance(color, str), color + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + post_parameters = { + "name": name, + "color": color, + } + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + headers, data = self._requester.requestJsonAndCheck( + "POST", + self.url + "/labels", + input=post_parameters, + headers={"Accept": Consts.mediaTypeLabelDescriptionSearchPreview}, + ) + return github.Label.Label(self._requester, headers, data, completed=True) + + def create_milestone( + self, + title, + state=github.GithubObject.NotSet, + description=github.GithubObject.NotSet, + due_on=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/milestones `_ + :param title: string + :param state: string + :param description: string + :param due_on: datetime + :rtype: :class:`github.Milestone.Milestone` + """ + assert isinstance(title, str), title + assert state is github.GithubObject.NotSet or isinstance(state, str), state + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert due_on is github.GithubObject.NotSet or isinstance( + due_on, (datetime.datetime, datetime.date) + ), due_on + post_parameters = { + "title": title, + } + if state is not github.GithubObject.NotSet: + post_parameters["state"] = state + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if due_on is not github.GithubObject.NotSet: + if isinstance(due_on, datetime.date): + post_parameters["due_on"] = due_on.strftime("%Y-%m-%dT%H:%M:%SZ") + else: + post_parameters["due_on"] = due_on.isoformat() + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/milestones", input=post_parameters + ) + return github.Milestone.Milestone( + self._requester, headers, data, completed=True + ) + + def create_project(self, name, body=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/projects `_ + :param name: string + :param body: string + :rtype: :class:`github.Project.Project` + """ + assert isinstance(name, str), name + assert body is github.GithubObject.NotSet or isinstance(body, str), body + post_parameters = { + "name": name, + } + import_header = {"Accept": Consts.mediaTypeProjectsPreview} + if body is not github.GithubObject.NotSet: + post_parameters["body"] = body + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/projects", headers=import_header, input=post_parameters + ) + return github.Project.Project(self._requester, headers, data, completed=True) + + def create_pull(self, *args, **kwds): + """ + :calls: `POST /repos/:owner/:repo/pulls `_ + :param title: string + :param body: string + :param issue: :class:`github.Issue.Issue` + :param base: string + :param head: string + :param maintainer_can_modify: bool + :rtype: :class:`github.PullRequest.PullRequest` + """ + if len(args) + len(kwds) >= 4: + return self.__create_pull_1(*args, **kwds) + else: + return self.__create_pull_2(*args, **kwds) + + def __create_pull_1( + self, title, body, base, head, maintainer_can_modify=github.GithubObject.NotSet + ): + assert isinstance(title, str), title + assert isinstance(body, str), body + assert isinstance(base, str), base + assert isinstance(head, str), head + assert maintainer_can_modify is github.GithubObject.NotSet or isinstance( + maintainer_can_modify, bool + ), maintainer_can_modify + if maintainer_can_modify is not github.GithubObject.NotSet: + return self.__create_pull( + title=title, + body=body, + base=base, + head=head, + maintainer_can_modify=maintainer_can_modify, + ) + else: + return self.__create_pull(title=title, body=body, base=base, head=head) + + def __create_pull_2(self, issue, base, head): + assert isinstance(issue, github.Issue.Issue), issue + assert isinstance(base, str), base + assert isinstance(head, str), head + return self.__create_pull(issue=issue._identity, base=base, head=head) + + def __create_pull(self, **kwds): + post_parameters = kwds + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/pulls", input=post_parameters + ) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True + ) + + def create_source_import( + self, + vcs, + vcs_url, + vcs_username=github.GithubObject.NotSet, + vcs_password=github.GithubObject.NotSet, + ): + """ + :calls: `PUT /repos/:owner/:repo/import `_ + :param vcs: string + :param vcs_url: string + :param vcs_username: string + :param vcs_password: string + :rtype: :class:`github.SourceImport.SourceImport` + """ + assert isinstance(vcs, str), vcs + assert isinstance(vcs_url, str), vcs_url + assert vcs_username is github.GithubObject.NotSet or isinstance( + vcs_username, str + ), vcs_username + assert vcs_password is github.GithubObject.NotSet or isinstance( + vcs_password, str + ), vcs_password + put_parameters = {"vcs": vcs, "vcs_url": vcs_url} + + if vcs_username is not github.GithubObject.NotSet: + put_parameters["vcs_username"] = vcs_username + + if vcs_password is not github.GithubObject.NotSet: + put_parameters["vcs_password"] = vcs_password + + import_header = {"Accept": Consts.mediaTypeImportPreview} + + headers, data = self._requester.requestJsonAndCheck( + "PUT", self.url + "/import", headers=import_header, input=put_parameters + ) + + return github.SourceImport.SourceImport( + self._requester, headers, data, completed=False + ) + + def delete(self): + """ + :calls: `DELETE /repos/:owner/:repo `_ + :rtype: None + """ + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) + + def edit( + self, + name=None, + description=github.GithubObject.NotSet, + homepage=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + has_issues=github.GithubObject.NotSet, + has_projects=github.GithubObject.NotSet, + has_wiki=github.GithubObject.NotSet, + has_downloads=github.GithubObject.NotSet, + default_branch=github.GithubObject.NotSet, + allow_squash_merge=github.GithubObject.NotSet, + allow_merge_commit=github.GithubObject.NotSet, + allow_rebase_merge=github.GithubObject.NotSet, + delete_branch_on_merge=github.GithubObject.NotSet, + archived=github.GithubObject.NotSet, + ): + """ + :calls: `PATCH /repos/:owner/:repo `_ + :param name: string + :param description: string + :param homepage: string + :param private: bool + :param has_issues: bool + :param has_projects: bool + :param has_wiki: bool + :param has_downloads: bool + :param default_branch: string + :param allow_squash_merge: bool + :param allow_merge_commit: bool + :param allow_rebase_merge: bool + :param delete_branch_on_merge: bool + :param archived: bool. Unarchiving repositories is currently not supported through API (https://developer.github.com/v3/repos/#edit) + :rtype: None + """ + if name is None: + name = self.name + assert isinstance(name, str), name + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert homepage is github.GithubObject.NotSet or isinstance( + homepage, str + ), homepage + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + assert has_issues is github.GithubObject.NotSet or isinstance( + has_issues, bool + ), has_issues + assert has_projects is github.GithubObject.NotSet or isinstance( + has_projects, bool + ), has_projects + assert has_wiki is github.GithubObject.NotSet or isinstance( + has_wiki, bool + ), has_wiki + assert has_downloads is github.GithubObject.NotSet or isinstance( + has_downloads, bool + ), has_downloads + assert default_branch is github.GithubObject.NotSet or isinstance( + default_branch, str + ), default_branch + assert allow_squash_merge is github.GithubObject.NotSet or isinstance( + allow_squash_merge, bool + ), allow_squash_merge + assert allow_merge_commit is github.GithubObject.NotSet or isinstance( + allow_merge_commit, bool + ), allow_merge_commit + assert allow_rebase_merge is github.GithubObject.NotSet or isinstance( + allow_rebase_merge, bool + ), allow_rebase_merge + assert delete_branch_on_merge is github.GithubObject.NotSet or isinstance( + delete_branch_on_merge, bool + ), delete_branch_on_merge + assert archived is github.GithubObject.NotSet or ( + isinstance(archived, bool) and archived is True + ), archived + post_parameters = { + "name": name, + } + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if homepage is not github.GithubObject.NotSet: + post_parameters["homepage"] = homepage + if private is not github.GithubObject.NotSet: + post_parameters["private"] = private + if has_issues is not github.GithubObject.NotSet: + post_parameters["has_issues"] = has_issues + if has_projects is not github.GithubObject.NotSet: + post_parameters["has_projects"] = has_projects + if has_wiki is not github.GithubObject.NotSet: + post_parameters["has_wiki"] = has_wiki + if has_downloads is not github.GithubObject.NotSet: + post_parameters["has_downloads"] = has_downloads + if default_branch is not github.GithubObject.NotSet: + post_parameters["default_branch"] = default_branch + if allow_squash_merge is not github.GithubObject.NotSet: + post_parameters["allow_squash_merge"] = allow_squash_merge + if allow_merge_commit is not github.GithubObject.NotSet: + post_parameters["allow_merge_commit"] = allow_merge_commit + if allow_rebase_merge is not github.GithubObject.NotSet: + post_parameters["allow_rebase_merge"] = allow_rebase_merge + if delete_branch_on_merge is not github.GithubObject.NotSet: + post_parameters["delete_branch_on_merge"] = delete_branch_on_merge + if archived is not github.GithubObject.NotSet: + post_parameters["archived"] = archived + headers, data = self._requester.requestJsonAndCheck( + "PATCH", self.url, input=post_parameters + ) + self._useAttributes(data) + + def get_archive_link(self, archive_format, ref=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/:archive_format/:ref `_ + :param archive_format: string + :param ref: string + :rtype: string + """ + assert isinstance(archive_format, str), archive_format + assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref + url = self.url + "/" + archive_format + if ref is not github.GithubObject.NotSet: + url += "/" + ref + headers, data = self._requester.requestJsonAndCheck("GET", url) + return headers["location"] + + def get_assignees(self): + """ + :calls: `GET /repos/:owner/:repo/assignees `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, self._requester, self.url + "/assignees", None + ) + + def get_branch(self, branch): + """ + :calls: `GET /repos/:owner/:repo/branches/:branch `_ + :param branch: string + :rtype: :class:`github.Branch.Branch` + """ + assert isinstance(branch, str), branch + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/branches/" + branch + ) + return github.Branch.Branch(self._requester, headers, data, completed=True) + + def get_branches(self): + """ + :calls: `GET /repos/:owner/:repo/branches `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Branch.Branch` + """ + return github.PaginatedList.PaginatedList( + github.Branch.Branch, self._requester, self.url + "/branches", None + ) + + def get_collaborators(self, affiliation=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/collaborators `_ + :param affiliation: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + + url_parameters = dict() + allowed_affiliations = ["outside", "direct", "all"] + if affiliation is not github.GithubObject.NotSet: + assert isinstance(affiliation, str), affiliation + assert ( + affiliation in allowed_affiliations + ), "Affiliation can be one of " + ", ".join(allowed_affiliations) + url_parameters["affiliation"] = affiliation + + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, + self._requester, + self.url + "/collaborators", + url_parameters, + ) + + def get_comment(self, id): + """ + :calls: `GET /repos/:owner/:repo/comments/:id `_ + :param id: integer + :rtype: :class:`github.CommitComment.CommitComment` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/comments/" + str(id) + ) + return github.CommitComment.CommitComment( + self._requester, headers, data, completed=True + ) + + def get_comments(self): + """ + :calls: `GET /repos/:owner/:repo/comments `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CommitComment.CommitComment` + """ + return github.PaginatedList.PaginatedList( + github.CommitComment.CommitComment, + self._requester, + self.url + "/comments", + None, + ) + + def get_commit(self, sha): + """ + :calls: `GET /repos/:owner/:repo/commits/:sha `_ + :param sha: string + :rtype: :class:`github.Commit.Commit` + """ + assert isinstance(sha, str), sha + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/commits/" + sha + ) + return github.Commit.Commit(self._requester, headers, data, completed=True) + + def get_commits( + self, + sha=github.GithubObject.NotSet, + path=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + until=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/commits `_ + :param sha: string + :param path: string + :param since: datetime.datetime + :param until: datetime.datetime + :param author: string or :class:`github.NamedUser.NamedUser` or :class:`github.AuthenticatedUser.AuthenticatedUser` + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit` + """ + assert sha is github.GithubObject.NotSet or isinstance(sha, str), sha + assert path is github.GithubObject.NotSet or isinstance(path, str), path + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert until is github.GithubObject.NotSet or isinstance( + until, datetime.datetime + ), until + assert author is github.GithubObject.NotSet or isinstance( + author, + ( + str, + github.NamedUser.NamedUser, + github.AuthenticatedUser.AuthenticatedUser, + ), + ), author + url_parameters = dict() + if sha is not github.GithubObject.NotSet: + url_parameters["sha"] = sha + if path is not github.GithubObject.NotSet: + url_parameters["path"] = path + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + if until is not github.GithubObject.NotSet: + url_parameters["until"] = until.strftime("%Y-%m-%dT%H:%M:%SZ") + if author is not github.GithubObject.NotSet: + if isinstance( + author, + ( + github.NamedUser.NamedUser, + github.AuthenticatedUser.AuthenticatedUser, + ), + ): + url_parameters["author"] = author.login + else: + url_parameters["author"] = author + return github.PaginatedList.PaginatedList( + github.Commit.Commit, self._requester, self.url + "/commits", url_parameters + ) + + def get_contents(self, path, ref=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/contents/:path `_ + :param path: string + :param ref: string + :rtype: :class:`github.ContentFile.ContentFile` or a list of them + """ + assert isinstance(path, str), path + assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref + # Path of '/' should be the empty string. + if path == "/": + path = "" + url_parameters = dict() + if ref is not github.GithubObject.NotSet: + url_parameters["ref"] = ref + headers, data = self._requester.requestJsonAndCheck( + "GET", + self.url + "/contents/" + urllib.parse.quote(path), + parameters=url_parameters, + ) + + # Handle 302 redirect response + if headers.get("status") == "302 Found" and headers.get("location"): + headers, data = self._requester.requestJsonAndCheck( + "GET", headers["location"], parameters=url_parameters + ) + + if isinstance(data, list): + return [ + # Lazy completion only makes sense for files. See discussion + # here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130 + github.ContentFile.ContentFile( + self._requester, headers, item, completed=(item["type"] != "file") + ) + for item in data + ] + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True + ) + + def get_top_referrers(self): + """ + :calls: `GET /repos/:owner/:repo/traffic/popular/referrers `_ + :rtype: :class:`list` of :class:`github.Referrer.Referrer` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/traffic/popular/referrers" + ) + if isinstance(data, list): + return [ + github.Referrer.Referrer(self._requester, headers, item, completed=True) + for item in data + ] + + def get_top_paths(self): + """ + :calls: `GET /repos/:owner/:repo/traffic/popular/paths `_ + :rtype: :class:`list` of :class:`github.Path.Path` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/traffic/popular/paths" + ) + if isinstance(data, list): + return [ + github.Path.Path(self._requester, headers, item, completed=True) + for item in data + ] + + def get_views_traffic(self, per=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/traffic/views `_ + :param per: string, must be one of day or week, day by default + :rtype: None or list of :class:`github.View.View` + """ + assert per is github.GithubObject.NotSet or ( + isinstance(per, str) and (per == "day" or per == "week") + ), "per must be day or week, day by default" + url_parameters = dict() + if per is not github.GithubObject.NotSet: + url_parameters["per"] = per + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/traffic/views", parameters=url_parameters + ) + if ( + (isinstance(data, dict)) + and ("views" in data) + and (isinstance(data["views"], list)) + ): + data["views"] = [ + github.View.View(self._requester, headers, item, completed=True) + for item in data["views"] + ] + return data + + def get_clones_traffic(self, per=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/traffic/clones `_ + :param per: string, must be one of day or week, day by default + :rtype: None or list of :class:`github.Clone.Clone` + """ + assert per is github.GithubObject.NotSet or ( + isinstance(per, str) and (per == "day" or per == "week") + ), "per must be day or week, day by default" + url_parameters = dict() + if per is not github.GithubObject.NotSet: + url_parameters["per"] = per + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/traffic/clones", parameters=url_parameters + ) + if ( + (isinstance(data, dict)) + and ("clones" in data) + and (isinstance(data["clones"], list)) + ): + data["clones"] = [ + github.Clones.Clones(self._requester, headers, item, completed=True) + for item in data["clones"] + ] + return data + + def get_projects(self, state=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/projects `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Project.Project` + :param state: string + """ + + url_parameters = dict() + if state is not github.GithubObject.NotSet: + url_parameters["state"] = state + + return github.PaginatedList.PaginatedList( + github.Project.Project, + self._requester, + self.url + "/projects", + url_parameters, + {"Accept": Consts.mediaTypeProjectsPreview}, + ) + + def create_file( + self, + path, + message, + content, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): + """Create a file in this repository. + + :calls: `PUT /repos/:owner/:repo/contents/:path `_ + :param path: string, (required), path of the file in the repository + :param message: string, (required), commit message + :param content: string, (required), the actual data in the file + :param branch: string, (optional), branch to create the commit on. Defaults to the default branch of the repository + :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. + :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. + :rtype: { + 'content': :class:`ContentFile `:, + 'commit': :class:`Commit `} + """ + assert isinstance(path, str) + assert isinstance(message, str) + assert isinstance(content, (str, bytes)) + assert branch is github.GithubObject.NotSet or isinstance(branch, str) + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ) + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ) + + if not isinstance(content, bytes): + content = content.encode("utf-8") + content = b64encode(content).decode("utf-8") + put_parameters = {"message": message, "content": content} + + if branch is not github.GithubObject.NotSet: + put_parameters["branch"] = branch + if author is not github.GithubObject.NotSet: + put_parameters["author"] = author._identity + if committer is not github.GithubObject.NotSet: + put_parameters["committer"] = committer._identity + + headers, data = self._requester.requestJsonAndCheck( + "PUT", + self.url + "/contents/" + urllib.parse.quote(path), + input=put_parameters, + ) + + return { + "content": github.ContentFile.ContentFile( + self._requester, headers, data["content"], completed=False + ), + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + } + + def update_file( + self, + path, + message, + content, + sha, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): + """This method updates a file in a repository + + :calls: `PUT /repos/:owner/:repo/contents/:path `_ + :param path: string, Required. The content path. + :param message: string, Required. The commit message. + :param content: string, Required. The updated file content, either base64 encoded, or ready to be encoded. + :param sha: string, Required. The blob SHA of the file being replaced. + :param branch: string. The branch name. Default: the repository’s default branch (usually master) + :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. + :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. + :rtype: { + 'content': :class:`ContentFile `:, + 'commit': :class:`Commit `} + """ + assert isinstance(path, str) + assert isinstance(message, str) + assert isinstance(content, (str, bytes)) + assert isinstance(sha, str) + assert branch is github.GithubObject.NotSet or isinstance(branch, str) + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ) + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ) + + if not isinstance(content, bytes): + content = content.encode("utf-8") + content = b64encode(content).decode("utf-8") + + put_parameters = {"message": message, "content": content, "sha": sha} + + if branch is not github.GithubObject.NotSet: + put_parameters["branch"] = branch + if author is not github.GithubObject.NotSet: + put_parameters["author"] = author._identity + if committer is not github.GithubObject.NotSet: + put_parameters["committer"] = committer._identity + + headers, data = self._requester.requestJsonAndCheck( + "PUT", + self.url + "/contents/" + urllib.parse.quote(path), + input=put_parameters, + ) + + return { + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + "content": github.ContentFile.ContentFile( + self._requester, headers, data["content"], completed=False + ), + } + + def delete_file( + self, + path, + message, + sha, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): + """This method deletes a file in a repository + + :calls: `DELETE /repos/:owner/:repo/contents/:path `_ + :param path: string, Required. The content path. + :param message: string, Required. The commit message. + :param sha: string, Required. The blob SHA of the file being replaced. + :param branch: string. The branch name. Default: the repository’s default branch (usually master) + :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. + :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. + :rtype: { + 'content': :class:`null `:, + 'commit': :class:`Commit `} + """ + assert isinstance(path, str), "path must be str/unicode object" + assert isinstance(message, str), "message must be str/unicode object" + assert isinstance(sha, str), "sha must be a str/unicode object" + assert branch is github.GithubObject.NotSet or isinstance( + branch, str + ), "branch must be a str/unicode object" + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ), "author must be a github.InputGitAuthor object" + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ), "committer must be a github.InputGitAuthor object" + + url_parameters = {"message": message, "sha": sha} + if branch is not github.GithubObject.NotSet: + url_parameters["branch"] = branch + if author is not github.GithubObject.NotSet: + url_parameters["author"] = author._identity + if committer is not github.GithubObject.NotSet: + url_parameters["committer"] = committer._identity + + headers, data = self._requester.requestJsonAndCheck( + "DELETE", + self.url + "/contents/" + urllib.parse.quote(path), + input=url_parameters, + ) + + return { + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + "content": github.GithubObject.NotSet, + } + + @deprecated( + reason=""" + Repository.get_dir_contents() is deprecated, use + Repository.get_contents() instead. + """ + ) + def get_dir_contents(self, path, ref=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/contents/:path `_ + :param path: string + :param ref: string + :rtype: list of :class:`github.ContentFile.ContentFile` + """ + return self.get_contents(path, ref=ref) + + def get_contributors(self, anon=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/contributors `_ + :param anon: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + url_parameters = dict() + if anon is not github.GithubObject.NotSet: + url_parameters["anon"] = anon + + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, + self._requester, + self.url + "/contributors", + url_parameters, + ) + + def get_download(self, id): + """ + :calls: `GET /repos/:owner/:repo/downloads/:id `_ + :param id: integer + :rtype: :class:`github.Download.Download` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/downloads/" + str(id) + ) + return github.Download.Download(self._requester, headers, data, completed=True) + + def get_downloads(self): + """ + :calls: `GET /repos/:owner/:repo/downloads `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Download.Download` + """ + return github.PaginatedList.PaginatedList( + github.Download.Download, self._requester, self.url + "/downloads", None + ) + + def get_events(self): + """ + :calls: `GET /repos/:owner/:repo/events `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` + """ + return github.PaginatedList.PaginatedList( + github.Event.Event, self._requester, self.url + "/events", None + ) + + def get_forks(self): + """ + :calls: `GET /repos/:owner/:repo/forks `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` + """ + return github.PaginatedList.PaginatedList( + Repository, self._requester, self.url + "/forks", None + ) + + def create_fork(self, organization=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/forks `_ + :param organization: string or "none" or "*" + :rtype: :class:`github.Repository.Repository` + """ + assert organization is github.GithubObject.NotSet or isinstance( + organization, str + ), organization + post_parameters = {} + if organization is not github.GithubObject.NotSet: + post_parameters["organization"] = organization + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/forks", input=post_parameters, + ) + return Repository(self._requester, headers, data, completed=True) + + def get_git_blob(self, sha): + """ + :calls: `GET /repos/:owner/:repo/git/blobs/:sha `_ + :param sha: string + :rtype: :class:`github.GitBlob.GitBlob` + """ + assert isinstance(sha, str), sha + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/git/blobs/" + sha + ) + return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) + + def get_git_commit(self, sha): + """ + :calls: `GET /repos/:owner/:repo/git/commits/:sha `_ + :param sha: string + :rtype: :class:`github.GitCommit.GitCommit` + """ + assert isinstance(sha, str), sha + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/git/commits/" + sha + ) + return github.GitCommit.GitCommit( + self._requester, headers, data, completed=True + ) + + def get_git_ref(self, ref): + """ + :calls: `GET /repos/:owner/:repo/git/refs/:ref `_ + :param ref: string + :rtype: :class:`github.GitRef.GitRef` + """ + prefix = "/git/refs/" + if not self._requester.FIX_REPO_GET_GIT_REF: + prefix = "/git/" + assert isinstance(ref, str), ref + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + prefix + ref + ) + return github.GitRef.GitRef(self._requester, headers, data, completed=True) + + def get_git_refs(self): + """ + :calls: `GET /repos/:owner/:repo/git/refs `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRef.GitRef` + """ + return github.PaginatedList.PaginatedList( + github.GitRef.GitRef, self._requester, self.url + "/git/refs", None + ) + + def get_git_tag(self, sha): + """ + :calls: `GET /repos/:owner/:repo/git/tags/:sha `_ + :param sha: string + :rtype: :class:`github.GitTag.GitTag` + """ + assert isinstance(sha, str), sha + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/git/tags/" + sha + ) + return github.GitTag.GitTag(self._requester, headers, data, completed=True) + + def get_git_tree(self, sha, recursive=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/git/trees/:sha `_ + :param sha: string + :param recursive: bool + :rtype: :class:`github.GitTree.GitTree` + """ + assert isinstance(sha, str), sha + assert recursive is github.GithubObject.NotSet or isinstance( + recursive, bool + ), recursive + url_parameters = dict() + if recursive is not github.GithubObject.NotSet and recursive: + # GitHub API requires the recursive parameter be set to 1. + url_parameters["recursive"] = 1 + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/git/trees/" + sha, parameters=url_parameters + ) + return github.GitTree.GitTree(self._requester, headers, data, completed=True) + + def get_hook(self, id): + """ + :calls: `GET /repos/:owner/:repo/hooks/:id `_ + :param id: integer + :rtype: :class:`github.Hook.Hook` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/hooks/" + str(id) + ) + return github.Hook.Hook(self._requester, headers, data, completed=True) + + def get_hooks(self): + """ + :calls: `GET /repos/:owner/:repo/hooks `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook` + """ + return github.PaginatedList.PaginatedList( + github.Hook.Hook, self._requester, self.url + "/hooks", None + ) + + def get_issue(self, number): + """ + :calls: `GET /repos/:owner/:repo/issues/:number `_ + :param number: integer + :rtype: :class:`github.Issue.Issue` + """ + assert isinstance(number, int), number + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/issues/" + str(number) + ) + return github.Issue.Issue(self._requester, headers, data, completed=True) + + def get_issues( + self, + milestone=github.GithubObject.NotSet, + state=github.GithubObject.NotSet, + assignee=github.GithubObject.NotSet, + mentioned=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + creator=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/issues `_ + :param milestone: :class:`github.Milestone.Milestone` or "none" or "*" + :param state: string. `open`, `closed`, or `all`. If this is not set the GitHub API default behavior will be used. At the moment this is to return only open issues. This might change anytime on GitHub API side and it could be clever to explicitly specify the state value. + :param assignee: string or :class:`github.NamedUser.NamedUser` or "none" or "*" + :param mentioned: :class:`github.NamedUser.NamedUser` + :param labels: list of string or :class:`github.Label.Label` + :param sort: string + :param direction: string + :param since: datetime.datetime + :param creator: string or :class:`github.NamedUser.NamedUser` + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` + """ + assert ( + milestone is github.GithubObject.NotSet + or milestone == "*" + or milestone == "none" + or isinstance(milestone, github.Milestone.Milestone) + ), milestone + assert state is github.GithubObject.NotSet or isinstance(state, str), state + assert ( + assignee is github.GithubObject.NotSet + or isinstance(assignee, github.NamedUser.NamedUser) + or isinstance(assignee, str) + ), assignee + assert mentioned is github.GithubObject.NotSet or isinstance( + mentioned, github.NamedUser.NamedUser + ), mentioned + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) or isinstance(element, str) + for element in labels + ), labels + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert ( + creator is github.GithubObject.NotSet + or isinstance(creator, github.NamedUser.NamedUser) + or isinstance(creator, str) + ), creator + url_parameters = dict() + if milestone is not github.GithubObject.NotSet: + if isinstance(milestone, str): + url_parameters["milestone"] = milestone + else: + url_parameters["milestone"] = milestone._identity + if state is not github.GithubObject.NotSet: + url_parameters["state"] = state + if assignee is not github.GithubObject.NotSet: + if isinstance(assignee, str): + url_parameters["assignee"] = assignee + else: + url_parameters["assignee"] = assignee._identity + if mentioned is not github.GithubObject.NotSet: + url_parameters["mentioned"] = mentioned._identity + if labels is not github.GithubObject.NotSet: + url_parameters["labels"] = ",".join( + [ + label.name if isinstance(label, github.Label.Label) else label + for label in labels + ] + ) + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + if creator is not github.GithubObject.NotSet: + if isinstance(creator, str): + url_parameters["creator"] = creator + else: + url_parameters["creator"] = creator._identity + return github.PaginatedList.PaginatedList( + github.Issue.Issue, self._requester, self.url + "/issues", url_parameters + ) + + def get_issues_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/issues/comments `_ + :param sort: string + :param direction: string + :param since: datetime.datetime + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment` + """ + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + url_parameters = dict() + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + return github.PaginatedList.PaginatedList( + github.IssueComment.IssueComment, + self._requester, + self.url + "/issues/comments", + url_parameters, + ) + + def get_issues_event(self, id): + """ + :calls: `GET /repos/:owner/:repo/issues/events/:id `_ + :param id: integer + :rtype: :class:`github.IssueEvent.IssueEvent` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", + self.url + "/issues/events/" + str(id), + headers={"Accept": Consts.mediaTypeLockReasonPreview}, + ) + return github.IssueEvent.IssueEvent( + self._requester, headers, data, completed=True + ) + + def get_issues_events(self): + """ + :calls: `GET /repos/:owner/:repo/issues/events `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueEvent.IssueEvent` + """ + return github.PaginatedList.PaginatedList( + github.IssueEvent.IssueEvent, + self._requester, + self.url + "/issues/events", + None, + headers={"Accept": Consts.mediaTypeLockReasonPreview}, + ) + + def get_key(self, id): + """ + :calls: `GET /repos/:owner/:repo/keys/:id `_ + :param id: integer + :rtype: :class:`github.RepositoryKey.RepositoryKey` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/keys/" + str(id) + ) + return github.RepositoryKey.RepositoryKey( + self._requester, headers, data, completed=True + ) + + def get_keys(self): + """ + :calls: `GET /repos/:owner/:repo/keys `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.RepositoryKey.RepositoryKey` + """ + return github.PaginatedList.PaginatedList( + github.RepositoryKey.RepositoryKey, + self._requester, + self.url + "/keys", + None, + ) + + def get_label(self, name): + """ + :calls: `GET /repos/:owner/:repo/labels/:name `_ + :param name: string + :rtype: :class:`github.Label.Label` + """ + assert isinstance(name, str), name + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/labels/" + urllib.parse.quote(name) + ) + return github.Label.Label(self._requester, headers, data, completed=True) + + def get_labels(self): + """ + :calls: `GET /repos/:owner/:repo/labels `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` + """ + return github.PaginatedList.PaginatedList( + github.Label.Label, self._requester, self.url + "/labels", None + ) + + def get_languages(self): + """ + :calls: `GET /repos/:owner/:repo/languages `_ + :rtype: dict of string to integer + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/languages" + ) + return data + + def get_license(self): + """ + :calls: `GET /repos/:owner/:repo/license `_ + :rtype: :class:`github.ContentFile.ContentFile` + """ + + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/license" + ) + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True + ) + + def get_milestone(self, number): + """ + :calls: `GET /repos/:owner/:repo/milestones/:number `_ + :param number: integer + :rtype: :class:`github.Milestone.Milestone` + """ + assert isinstance(number, int), number + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/milestones/" + str(number) + ) + return github.Milestone.Milestone( + self._requester, headers, data, completed=True + ) + + def get_milestones( + self, + state=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/milestones `_ + :param state: string + :param sort: string + :param direction: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Milestone.Milestone` + """ + assert state is github.GithubObject.NotSet or isinstance(state, str), state + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + url_parameters = dict() + if state is not github.GithubObject.NotSet: + url_parameters["state"] = state + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + return github.PaginatedList.PaginatedList( + github.Milestone.Milestone, + self._requester, + self.url + "/milestones", + url_parameters, + ) + + def get_network_events(self): + """ + :calls: `GET /networks/:owner/:repo/events `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` + """ + return github.PaginatedList.PaginatedList( + github.Event.Event, + self._requester, + "/networks/" + self.owner.login + "/" + self.name + "/events", + None, + ) + + def get_pull(self, number): + """ + :calls: `GET /repos/:owner/:repo/pulls/:number `_ + :param number: integer + :rtype: :class:`github.PullRequest.PullRequest` + """ + assert isinstance(number, int), number + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/pulls/" + str(number) + ) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True + ) + + def get_pulls( + self, + state=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + base=github.GithubObject.NotSet, + head=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/pulls `_ + :param state: string + :param sort: string + :param direction: string + :param base: string + :param head: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequest.PullRequest` + """ + assert state is github.GithubObject.NotSet or isinstance(state, str), state + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert base is github.GithubObject.NotSet or isinstance(base, str), base + assert head is github.GithubObject.NotSet or isinstance(head, str), head + url_parameters = dict() + if state is not github.GithubObject.NotSet: + url_parameters["state"] = state + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + if base is not github.GithubObject.NotSet: + url_parameters["base"] = base + if head is not github.GithubObject.NotSet: + url_parameters["head"] = head + return github.PaginatedList.PaginatedList( + github.PullRequest.PullRequest, + self._requester, + self.url + "/pulls", + url_parameters, + ) + + def get_pulls_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/pulls/comments `_ + :param sort: string + :param direction: string + :param since: datetime.datetime + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` + """ + return self.get_pulls_review_comments(sort, direction, since) + + def get_pulls_review_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/pulls/comments `_ + :param sort: string + :param direction: string + :param since: datetime.datetime + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` + """ + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + url_parameters = dict() + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + return github.PaginatedList.PaginatedList( + github.PullRequestComment.PullRequestComment, + self._requester, + self.url + "/pulls/comments", + url_parameters, + ) + + def get_readme(self, ref=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/readme `_ + :param ref: string + :rtype: :class:`github.ContentFile.ContentFile` + """ + assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref + url_parameters = dict() + if ref is not github.GithubObject.NotSet: + url_parameters["ref"] = ref + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/readme", parameters=url_parameters + ) + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True + ) + + def get_source_import(self): + """ + :calls: `GET /repos/:owner/:repo/import `_ + :rtype: :class:`github.SourceImport.SourceImport` + """ + import_header = {"Accept": Consts.mediaTypeImportPreview} + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/import", headers=import_header, + ) + if not data: + return None + else: + return github.SourceImport.SourceImport( + self._requester, headers, data, completed=True + ) + + def get_stargazers(self): + """ + :calls: `GET /repos/:owner/:repo/stargazers `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, self._requester, self.url + "/stargazers", None + ) + + def get_stargazers_with_dates(self): + """ + :calls: `GET /repos/:owner/:repo/stargazers `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Stargazer.Stargazer` + """ + return github.PaginatedList.PaginatedList( + github.Stargazer.Stargazer, + self._requester, + self.url + "/stargazers", + None, + headers={"Accept": Consts.mediaTypeStarringPreview}, + ) + + def get_stats_contributors(self): + """ + :calls: `GET /repos/:owner/:repo/stats/contributors `_ + :rtype: None or list of :class:`github.StatsContributor.StatsContributor` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/contributors" + ) + if not data: + return None + else: + return [ + github.StatsContributor.StatsContributor( + self._requester, headers, attributes, completed=True + ) + for attributes in data + ] + + def get_stats_commit_activity(self): + """ + :calls: `GET /repos/:owner/:repo/stats/commit_activity `_ + :rtype: None or list of :class:`github.StatsCommitActivity.StatsCommitActivity` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/commit_activity" + ) + if not data: + return None + else: + return [ + github.StatsCommitActivity.StatsCommitActivity( + self._requester, headers, attributes, completed=True + ) + for attributes in data + ] + + def get_stats_code_frequency(self): + """ + :calls: `GET /repos/:owner/:repo/stats/code_frequency `_ + :rtype: None or list of :class:`github.StatsCodeFrequency.StatsCodeFrequency` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/code_frequency" + ) + if not data: + return None + else: + return [ + github.StatsCodeFrequency.StatsCodeFrequency( + self._requester, headers, attributes, completed=True + ) + for attributes in data + ] + + def get_stats_participation(self): + """ + :calls: `GET /repos/:owner/:repo/stats/participation `_ + :rtype: None or :class:`github.StatsParticipation.StatsParticipation` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/participation" + ) + if not data: + return None + else: + return github.StatsParticipation.StatsParticipation( + self._requester, headers, data, completed=True + ) + + def get_stats_punch_card(self): + """ + :calls: `GET /repos/:owner/:repo/stats/punch_card `_ + :rtype: None or :class:`github.StatsPunchCard.StatsPunchCard` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/punch_card" + ) + if not data: + return None + else: + return github.StatsPunchCard.StatsPunchCard( + self._requester, headers, data, completed=True + ) + + def get_subscribers(self): + """ + :calls: `GET /repos/:owner/:repo/subscribers `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, self._requester, self.url + "/subscribers", None + ) + + def get_tags(self): + """ + :calls: `GET /repos/:owner/:repo/tags `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Tag.Tag` + """ + return github.PaginatedList.PaginatedList( + github.Tag.Tag, self._requester, self.url + "/tags", None + ) + + def get_releases(self): + """ + :calls: `GET /repos/:owner/:repo/releases `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRelease.GitRelease` + """ + return github.PaginatedList.PaginatedList( + github.GitRelease.GitRelease, self._requester, self.url + "/releases", None + ) + + def get_release(self, id): + """ + :calls: `GET /repos/:owner/:repo/releases/:id `_ + :param id: int (release id), str (tag name) + :rtype: None or :class:`github.GitRelease.GitRelease` + """ + if isinstance(id, int): + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/releases/" + str(id) + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True + ) + elif isinstance(id, str): + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/releases/tags/" + id + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True + ) + + def get_latest_release(self): + """ + :calls: `GET /repos/:owner/:repo/releases/latest `_ + :rtype: :class:`github.GitRelease.GitRelease` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/releases/latest" + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True + ) + + def get_teams(self): + """ + :calls: `GET /repos/:owner/:repo/teams `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` + """ + return github.PaginatedList.PaginatedList( + github.Team.Team, self._requester, self.url + "/teams", None + ) + + def get_topics(self): + """ + :calls: `GET /repos/:owner/:repo/topics `_ + :rtype: list of strings + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", + self.url + "/topics", + headers={"Accept": Consts.mediaTypeTopicsPreview}, + ) + return data["names"] + + def get_watchers(self): + """ + :calls: `GET /repos/:owner/:repo/watchers `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, self._requester, self.url + "/watchers", None + ) + + def has_in_assignees(self, assignee): + """ + :calls: `GET /repos/:owner/:repo/assignees/:assignee `_ + :param assignee: string or :class:`github.NamedUser.NamedUser` + :rtype: bool + """ + assert isinstance(assignee, github.NamedUser.NamedUser) or isinstance( + assignee, str + ), assignee + + if isinstance(assignee, github.NamedUser.NamedUser): + assignee = assignee._identity + + status, headers, data = self._requester.requestJson( + "GET", self.url + "/assignees/" + assignee + ) + return status == 204 + + def has_in_collaborators(self, collaborator): + """ + :calls: `GET /repos/:owner/:repo/collaborators/:user `_ + :param collaborator: string or :class:`github.NamedUser.NamedUser` + :rtype: bool + """ + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, str + ), collaborator + + if isinstance(collaborator, github.NamedUser.NamedUser): + collaborator = collaborator._identity + + status, headers, data = self._requester.requestJson( + "GET", self.url + "/collaborators/" + collaborator + ) + return status == 204 + + def _legacy_convert_issue(self, attributes): + convertedAttributes = { + "number": attributes["number"], + "url": "/repos" + urllib.parse.urlparse(attributes["html_url"]).path, + "user": { + "login": attributes["user"], + "url": "/users/" + attributes["user"], + }, + } + if "labels" in attributes: # pragma no branch + convertedAttributes["labels"] = [ + {"name": label} for label in attributes["labels"] + ] + for attr in ("title", "created_at", "comments", "body", "updated_at", "state"): + if attr in attributes: # pragma no branch + convertedAttributes[attr] = attributes[attr] + return convertedAttributes + + def legacy_search_issues(self, state, keyword): + """ + :calls: `GET /legacy/issues/search/:owner/:repository/:state/:keyword `_ + :param state: "open" or "closed" + :param keyword: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` + """ + assert state in ["open", "closed"], state + assert isinstance(keyword, str), keyword + headers, data = self._requester.requestJsonAndCheck( + "GET", + "/legacy/issues/search/" + + self.owner.login + + "/" + + self.name + + "/" + + state + + "/" + + urllib.parse.quote(keyword), + ) + return [ + github.Issue.Issue( + self._requester, + headers, + self._legacy_convert_issue(element), + completed=False, + ) + for element in data["issues"] + ] + + def get_notifications( + self, + all=github.GithubObject.NotSet, + participating=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + before=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/notifications `_ + :param all: bool + :param participating: bool + :param since: datetime.datetime + :param before: datetime.datetime + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification` + """ + + assert all is github.GithubObject.NotSet or isinstance(all, bool), all + assert participating is github.GithubObject.NotSet or isinstance( + participating, bool + ), participating + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert before is github.GithubObject.NotSet or isinstance( + before, datetime.datetime + ), before + + params = dict() + if all is not github.GithubObject.NotSet: + params["all"] = all + if participating is not github.GithubObject.NotSet: + params["participating"] = participating + if since is not github.GithubObject.NotSet: + params["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + if before is not github.GithubObject.NotSet: + params["before"] = before.strftime("%Y-%m-%dT%H:%M:%SZ") + + return github.PaginatedList.PaginatedList( + github.Notification.Notification, + self._requester, + self.url + "/notifications", + params, + ) + + def mark_notifications_as_read(self, last_read_at=datetime.datetime.utcnow()): + """ + :calls: `PUT /repos/:owner/:repo/notifications `_ + :param last_read_at: datetime + """ + assert isinstance(last_read_at, datetime.datetime) + put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} + + headers, data = self._requester.requestJsonAndCheck( + "PUT", self.url + "/notifications", input=put_parameters + ) + + def merge(self, base, head, commit_message=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/merges `_ + :param base: string + :param head: string + :param commit_message: string + :rtype: :class:`github.Commit.Commit` + """ + assert isinstance(base, str), base + assert isinstance(head, str), head + assert commit_message is github.GithubObject.NotSet or isinstance( + commit_message, str + ), commit_message + post_parameters = { + "base": base, + "head": head, + } + if commit_message is not github.GithubObject.NotSet: + post_parameters["commit_message"] = commit_message + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/merges", input=post_parameters + ) + if data is None: + return None + else: + return github.Commit.Commit(self._requester, headers, data, completed=True) + + def replace_topics(self, topics): + """ + :calls: `PUT /repos/:owner/:repo/topics `_ + :param topics: list of strings + :rtype: None + """ + post_parameters = {"names": topics} + headers, data = self._requester.requestJsonAndCheck( + "PUT", + self.url + "/topics", + headers={"Accept": Consts.mediaTypeTopicsPreview}, + input=post_parameters, + ) + + def get_vulnerability_alert(self): + """ + :calls: `GET /repos/:owner/:repo/vulnerability-alerts `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "GET", + self.url + "/vulnerability-alerts", + headers={"Accept": Consts.vulnerabilityAlertsPreview}, + ) + return status == 204 + + def enable_vulnerability_alert(self): + """ + :calls: `PUT /repos/:owner/:repo/vulnerability-alerts `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "PUT", + self.url + "/vulnerability-alerts", + headers={"Accept": Consts.vulnerabilityAlertsPreview}, + ) + return status == 204 + + def disable_vulnerability_alert(self): + """ + :calls: `DELETE /repos/:owner/:repo/vulnerability-alerts `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "DELETE", + self.url + "/vulnerability-alerts", + headers={"Accept": Consts.vulnerabilityAlertsPreview}, + ) + return status == 204 + + def enable_automated_security_fixes(self): + """ + :calls: `PUT /repos/:owner/:repo/automated-security-fixes `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "PUT", + self.url + "/automated-security-fixes", + headers={"Accept": Consts.automatedSecurityFixes}, + ) + return status == 204 + + def disable_automated_security_fixes(self): + """ + :calls: `DELETE /repos/:owner/:repo/automated-security-fixes `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "DELETE", + self.url + "/automated-security-fixes", + headers={"Accept": Consts.automatedSecurityFixes}, + ) + return status == 204 + + def remove_from_collaborators(self, collaborator): + """ + :calls: `DELETE /repos/:owner/:repo/collaborators/:user `_ + :param collaborator: string or :class:`github.NamedUser.NamedUser` + :rtype: None + """ + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, str + ), collaborator + + if isinstance(collaborator, github.NamedUser.NamedUser): + collaborator = collaborator._identity + + headers, data = self._requester.requestJsonAndCheck( + "DELETE", self.url + "/collaborators/" + collaborator + ) + + def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet): + """ + :calls: `POST /hub `_ + :param event: string + :param callback: string + :param secret: string + :rtype: None + """ + return self._hub("subscribe", event, callback, secret) + + def unsubscribe_from_hub(self, event, callback): + """ + :calls: `POST /hub `_ + :param event: string + :param callback: string + :param secret: string + :rtype: None + """ + return self._hub("unsubscribe", event, callback, github.GithubObject.NotSet) + + def _hub(self, mode, event, callback, secret): + assert isinstance(mode, str), mode + assert isinstance(event, str), event + assert isinstance(callback, str), callback + assert secret is github.GithubObject.NotSet or isinstance(secret, str), secret + + post_parameters = collections.OrderedDict() + post_parameters["hub.callback"] = callback + post_parameters["hub.topic"] = ( + "https://github.com/" + self.full_name + "/events/" + event + ) + post_parameters["hub.mode"] = mode + if secret is not github.GithubObject.NotSet: + post_parameters["hub.secret"] = secret + + headers, output = self._requester.requestMultipartAndCheck( + "POST", "/hub", input=post_parameters + ) + + @property + def _identity(self): + return self.owner.login + "/" + self.name + + def get_release_asset(self, id): + assert isinstance(id, (int)), id + + resp_headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/releases/assets/" + str(id) + ) + return github.GitReleaseAsset.GitReleaseAsset( + self._requester, resp_headers, data, completed=True + ) + + def _initAttributes(self): + self._allow_merge_commit = github.GithubObject.NotSet + self._allow_rebase_merge = github.GithubObject.NotSet + self._allow_squash_merge = github.GithubObject.NotSet + self._archived = github.GithubObject.NotSet + self._archive_url = github.GithubObject.NotSet + self._assignees_url = github.GithubObject.NotSet + self._blobs_url = github.GithubObject.NotSet + self._branches_url = github.GithubObject.NotSet + self._clone_url = github.GithubObject.NotSet + self._collaborators_url = github.GithubObject.NotSet + self._comments_url = github.GithubObject.NotSet + self._commits_url = github.GithubObject.NotSet + self._compare_url = github.GithubObject.NotSet + self._contents_url = github.GithubObject.NotSet + self._contributors_url = github.GithubObject.NotSet + self._created_at = github.GithubObject.NotSet + self._default_branch = github.GithubObject.NotSet + self._delete_branch_on_merge = github.GithubObject.NotSet + self._description = github.GithubObject.NotSet + self._downloads_url = github.GithubObject.NotSet + self._events_url = github.GithubObject.NotSet + self._fork = github.GithubObject.NotSet + self._forks = github.GithubObject.NotSet + self._forks_count = github.GithubObject.NotSet + self._forks_url = github.GithubObject.NotSet + self._full_name = github.GithubObject.NotSet + self._git_commits_url = github.GithubObject.NotSet + self._git_refs_url = github.GithubObject.NotSet + self._git_tags_url = github.GithubObject.NotSet + self._git_url = github.GithubObject.NotSet + self._has_downloads = github.GithubObject.NotSet + self._has_issues = github.GithubObject.NotSet + self._has_projects = github.GithubObject.NotSet + self._has_wiki = github.GithubObject.NotSet + self._homepage = github.GithubObject.NotSet + self._hooks_url = github.GithubObject.NotSet + self._html_url = github.GithubObject.NotSet + self._id = github.GithubObject.NotSet + self._is_template = github.GithubObject.NotSet + self._issue_comment_url = github.GithubObject.NotSet + self._issue_events_url = github.GithubObject.NotSet + self._issues_url = github.GithubObject.NotSet + self._keys_url = github.GithubObject.NotSet + self._labels_url = github.GithubObject.NotSet + self._language = github.GithubObject.NotSet + self._languages_url = github.GithubObject.NotSet + self._master_branch = github.GithubObject.NotSet + self._merges_url = github.GithubObject.NotSet + self._milestones_url = github.GithubObject.NotSet + self._mirror_url = github.GithubObject.NotSet + self._name = github.GithubObject.NotSet + self._network_count = github.GithubObject.NotSet + self._notifications_url = github.GithubObject.NotSet + self._open_issues = github.GithubObject.NotSet + self._open_issues_count = github.GithubObject.NotSet + self._organization = github.GithubObject.NotSet + self._owner = github.GithubObject.NotSet + self._parent = github.GithubObject.NotSet + self._permissions = github.GithubObject.NotSet + self._private = github.GithubObject.NotSet + self._pulls_url = github.GithubObject.NotSet + self._pushed_at = github.GithubObject.NotSet + self._size = github.GithubObject.NotSet + self._source = github.GithubObject.NotSet + self._ssh_url = github.GithubObject.NotSet + self._stargazers_count = github.GithubObject.NotSet + self._stargazers_url = github.GithubObject.NotSet + self._statuses_url = github.GithubObject.NotSet + self._subscribers_url = github.GithubObject.NotSet + self._subscribers_count = github.GithubObject.NotSet + self._subscription_url = github.GithubObject.NotSet + self._svn_url = github.GithubObject.NotSet + self._tags_url = github.GithubObject.NotSet + self._teams_url = github.GithubObject.NotSet + self._topics = github.GithubObject.NotSet + self._trees_url = github.GithubObject.NotSet + self._updated_at = github.GithubObject.NotSet + self._url = github.GithubObject.NotSet + self._watchers = github.GithubObject.NotSet + self._watchers_count = github.GithubObject.NotSet + + def _useAttributes(self, attributes): + if "allow_merge_commit" in attributes: # pragma no branch + self._allow_merge_commit = self._makeBoolAttribute( + attributes["allow_merge_commit"] + ) + if "allow_rebase_merge" in attributes: # pragma no branch + self._allow_rebase_merge = self._makeBoolAttribute( + attributes["allow_rebase_merge"] + ) + if "allow_squash_merge" in attributes: # pragma no branch + self._allow_squash_merge = self._makeBoolAttribute( + attributes["allow_squash_merge"] + ) + if "archived" in attributes: # pragma no branch + self._archived = self._makeBoolAttribute(attributes["archived"]) + if "archive_url" in attributes: # pragma no branch + self._archive_url = self._makeStringAttribute(attributes["archive_url"]) + if "assignees_url" in attributes: # pragma no branch + self._assignees_url = self._makeStringAttribute(attributes["assignees_url"]) + if "blobs_url" in attributes: # pragma no branch + self._blobs_url = self._makeStringAttribute(attributes["blobs_url"]) + if "branches_url" in attributes: # pragma no branch + self._branches_url = self._makeStringAttribute(attributes["branches_url"]) + if "clone_url" in attributes: # pragma no branch + self._clone_url = self._makeStringAttribute(attributes["clone_url"]) + if "collaborators_url" in attributes: # pragma no branch + self._collaborators_url = self._makeStringAttribute( + attributes["collaborators_url"] + ) + if "comments_url" in attributes: # pragma no branch + self._comments_url = self._makeStringAttribute(attributes["comments_url"]) + if "commits_url" in attributes: # pragma no branch + self._commits_url = self._makeStringAttribute(attributes["commits_url"]) + if "compare_url" in attributes: # pragma no branch + self._compare_url = self._makeStringAttribute(attributes["compare_url"]) + if "contents_url" in attributes: # pragma no branch + self._contents_url = self._makeStringAttribute(attributes["contents_url"]) + if "contributors_url" in attributes: # pragma no branch + self._contributors_url = self._makeStringAttribute( + attributes["contributors_url"] + ) + if "created_at" in attributes: # pragma no branch + self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) + if "default_branch" in attributes: # pragma no branch + self._default_branch = self._makeStringAttribute( + attributes["default_branch"] + ) + if "delete_branch_on_merge" in attributes: # pragma no branch + self._delete_branch_on_merge = self._makeBoolAttribute( + attributes["delete_branch_on_merge"] + ) + if "description" in attributes: # pragma no branch + self._description = self._makeStringAttribute(attributes["description"]) + if "downloads_url" in attributes: # pragma no branch + self._downloads_url = self._makeStringAttribute(attributes["downloads_url"]) + if "events_url" in attributes: # pragma no branch + self._events_url = self._makeStringAttribute(attributes["events_url"]) + if "fork" in attributes: # pragma no branch + self._fork = self._makeBoolAttribute(attributes["fork"]) + if "forks" in attributes: # pragma no branch + self._forks = self._makeIntAttribute(attributes["forks"]) + if "forks_count" in attributes: # pragma no branch + self._forks_count = self._makeIntAttribute(attributes["forks_count"]) + if "forks_url" in attributes: # pragma no branch + self._forks_url = self._makeStringAttribute(attributes["forks_url"]) + if "full_name" in attributes: # pragma no branch + self._full_name = self._makeStringAttribute(attributes["full_name"]) + if "git_commits_url" in attributes: # pragma no branch + self._git_commits_url = self._makeStringAttribute( + attributes["git_commits_url"] + ) + if "git_refs_url" in attributes: # pragma no branch + self._git_refs_url = self._makeStringAttribute(attributes["git_refs_url"]) + if "git_tags_url" in attributes: # pragma no branch + self._git_tags_url = self._makeStringAttribute(attributes["git_tags_url"]) + if "git_url" in attributes: # pragma no branch + self._git_url = self._makeStringAttribute(attributes["git_url"]) + if "has_downloads" in attributes: # pragma no branch + self._has_downloads = self._makeBoolAttribute(attributes["has_downloads"]) + if "has_issues" in attributes: # pragma no branch + self._has_issues = self._makeBoolAttribute(attributes["has_issues"]) + if "has_projects" in attributes: # pragma no branch + self._has_projects = self._makeBoolAttribute(attributes["has_projects"]) + if "has_wiki" in attributes: # pragma no branch + self._has_wiki = self._makeBoolAttribute(attributes["has_wiki"]) + if "homepage" in attributes: # pragma no branch + self._homepage = self._makeStringAttribute(attributes["homepage"]) + if "hooks_url" in attributes: # pragma no branch + self._hooks_url = self._makeStringAttribute(attributes["hooks_url"]) + if "html_url" in attributes: # pragma no branch + self._html_url = self._makeStringAttribute(attributes["html_url"]) + if "id" in attributes: # pragma no branch + self._id = self._makeIntAttribute(attributes["id"]) + if "is_template" in attributes: # pragma no branch + self._is_template = self._makeBoolAttribute(attributes["is_template"]) + if "issue_comment_url" in attributes: # pragma no branch + self._issue_comment_url = self._makeStringAttribute( + attributes["issue_comment_url"] + ) + if "issue_events_url" in attributes: # pragma no branch + self._issue_events_url = self._makeStringAttribute( + attributes["issue_events_url"] + ) + if "issues_url" in attributes: # pragma no branch + self._issues_url = self._makeStringAttribute(attributes["issues_url"]) + if "keys_url" in attributes: # pragma no branch + self._keys_url = self._makeStringAttribute(attributes["keys_url"]) + if "labels_url" in attributes: # pragma no branch + self._labels_url = self._makeStringAttribute(attributes["labels_url"]) + if "language" in attributes: # pragma no branch + self._language = self._makeStringAttribute(attributes["language"]) + if "languages_url" in attributes: # pragma no branch + self._languages_url = self._makeStringAttribute(attributes["languages_url"]) + if "master_branch" in attributes: # pragma no branch + self._master_branch = self._makeStringAttribute(attributes["master_branch"]) + if "merges_url" in attributes: # pragma no branch + self._merges_url = self._makeStringAttribute(attributes["merges_url"]) + if "milestones_url" in attributes: # pragma no branch + self._milestones_url = self._makeStringAttribute( + attributes["milestones_url"] + ) + if "mirror_url" in attributes: # pragma no branch + self._mirror_url = self._makeStringAttribute(attributes["mirror_url"]) + if "name" in attributes: # pragma no branch + self._name = self._makeStringAttribute(attributes["name"]) + if "network_count" in attributes: # pragma no branch + self._network_count = self._makeIntAttribute(attributes["network_count"]) + if "notifications_url" in attributes: # pragma no branch + self._notifications_url = self._makeStringAttribute( + attributes["notifications_url"] + ) + if "open_issues" in attributes: # pragma no branch + self._open_issues = self._makeIntAttribute(attributes["open_issues"]) + if "open_issues_count" in attributes: # pragma no branch + self._open_issues_count = self._makeIntAttribute( + attributes["open_issues_count"] + ) + if "organization" in attributes: # pragma no branch + self._organization = self._makeClassAttribute( + github.Organization.Organization, attributes["organization"] + ) + if "owner" in attributes: # pragma no branch + self._owner = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["owner"] + ) + if "parent" in attributes: # pragma no branch + self._parent = self._makeClassAttribute(Repository, attributes["parent"]) + if "permissions" in attributes: # pragma no branch + self._permissions = self._makeClassAttribute( + github.Permissions.Permissions, attributes["permissions"] + ) + if "private" in attributes: # pragma no branch + self._private = self._makeBoolAttribute(attributes["private"]) + if "pulls_url" in attributes: # pragma no branch + self._pulls_url = self._makeStringAttribute(attributes["pulls_url"]) + if "pushed_at" in attributes: # pragma no branch + self._pushed_at = self._makeDatetimeAttribute(attributes["pushed_at"]) + if "size" in attributes: # pragma no branch + self._size = self._makeIntAttribute(attributes["size"]) + if "source" in attributes: # pragma no branch + self._source = self._makeClassAttribute(Repository, attributes["source"]) + if "ssh_url" in attributes: # pragma no branch + self._ssh_url = self._makeStringAttribute(attributes["ssh_url"]) + if "stargazers_count" in attributes: # pragma no branch + self._stargazers_count = self._makeIntAttribute( + attributes["stargazers_count"] + ) + if "stargazers_url" in attributes: # pragma no branch + self._stargazers_url = self._makeStringAttribute( + attributes["stargazers_url"] + ) + if "statuses_url" in attributes: # pragma no branch + self._statuses_url = self._makeStringAttribute(attributes["statuses_url"]) + if "subscribers_url" in attributes: # pragma no branch + self._subscribers_url = self._makeStringAttribute( + attributes["subscribers_url"] + ) + if "subscribers_count" in attributes: # pragma no branch + self._subscribers_count = self._makeIntAttribute( + attributes["subscribers_count"] + ) + if "subscription_url" in attributes: # pragma no branch + self._subscription_url = self._makeStringAttribute( + attributes["subscription_url"] + ) + if "svn_url" in attributes: # pragma no branch + self._svn_url = self._makeStringAttribute(attributes["svn_url"]) + if "tags_url" in attributes: # pragma no branch + self._tags_url = self._makeStringAttribute(attributes["tags_url"]) + if "teams_url" in attributes: # pragma no branch + self._teams_url = self._makeStringAttribute(attributes["teams_url"]) + if "trees_url" in attributes: # pragma no branch + self._trees_url = self._makeStringAttribute(attributes["trees_url"]) + if "topics" in attributes: # pragma no branch + self._topics = self._makeListOfStringsAttribute(attributes["topics"]) + if "updated_at" in attributes: # pragma no branch + self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) + if "url" in attributes: # pragma no branch + self._url = self._makeStringAttribute(attributes["url"]) + if "watchers" in attributes: # pragma no branch + self._watchers = self._makeIntAttribute(attributes["watchers"]) + if "watchers_count" in attributes: # pragma no branch + self._watchers_count = self._makeIntAttribute(attributes["watchers_count"]) From a95e448a79a30e01cc704555cea31a6124304226 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Tue, 29 Sep 2020 20:27:44 -0300 Subject: [PATCH 10/25] Fix formatting --- github/AuthenticatedUser.py | 10 +++++----- github/Organization.py | 10 +++++----- tests/AuthenticatedUser.py | 16 +++++++++++++--- tests/Organization.py | 16 +++++++++++++--- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 570fa00cf5..08472eae8f 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -503,11 +503,11 @@ def create_fork(self, repo): ) def create_repo_from_template( - self, - name, - repo, - description=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, + self, + name, + repo, + description=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, ): """ :calls: `POST /repos/:template_owner/:template_repo/generate ` diff --git a/github/Organization.py b/github/Organization.py index 5d918c5626..f364200b05 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -406,11 +406,11 @@ def create_fork(self, repo): ) def create_repo_from_template( - self, - name, - repo, - description=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, + self, + name, + repo, + description=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, ): """self.name :calls: `POST /repos/:template_owner/:template_repo/generate `_ diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index 9a6d30558d..cbb9bfc68e 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -664,8 +664,13 @@ def testCreateFork(self): def testCreateRepoFromTemplate(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") - repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo) - self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/hello-world-docker-action-new") + repo = self.user.create_repo_from_template( + "hello-world-docker-action-new", template_repo + ) + self.assertEqual( + repo.url, + "https://api.github.com/repos/jacquev6/hello-world-docker-action-new", + ) self.assertEqual(repo.is_template, False) def testCreateRepoFromTemplateWithAllArguments(self): @@ -673,7 +678,12 @@ def testCreateRepoFromTemplateWithAllArguments(self): description = "My repo from template" private = True - repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) + repo = self.user.create_repo_from_template( + "hello-world-docker-action-new", + template_repo, + description=description, + private=private, + ) self.assertEqual(repo.description, description) self.assertTrue(repo.private) diff --git a/tests/Organization.py b/tests/Organization.py index 64be9654b3..8788cd7092 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -361,8 +361,13 @@ def testCreateFork(self): def testCreateRepoFromTemplate(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") - repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo) - self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new") + repo = self.org.create_repo_from_template( + "hello-world-docker-action-new", template_repo + ) + self.assertEqual( + repo.url, + "https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new", + ) self.assertEqual(repo.is_template, False) def testCreateRepoFromTemplateWithAllArguments(self): @@ -370,7 +375,12 @@ def testCreateRepoFromTemplateWithAllArguments(self): description = "My repo from template" private = True - repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) + repo = self.org.create_repo_from_template( + "hello-world-docker-action-new", + template_repo, + description=description, + private=private, + ) self.assertEqual(repo.description, description) self.assertTrue(repo.private) From 8fa9341d2869c44ae83439bb65bee7d578ffed0d Mon Sep 17 00:00:00 2001 From: KimSia Sim Date: Sat, 31 Jul 2021 11:27:28 +0800 Subject: [PATCH 11/25] Add create_repo_from_template to Organization and AuthenticatedUser --- github/AuthenticatedUser.py | 41 +++++++++++++++++++++++++++++++++++++ github/Consts.py | 5 ++++- github/Organization.py | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 9f9993d56a..ad129f63f7 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -501,6 +501,47 @@ def create_fork(self, repo): self._requester, headers, data, completed=True ) + def create_repo_from_template( + self, + name, + repo, + description=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:name/generate `_ + :param name: string + :param repo :class:`github.Repository.Repository` + :param description: string + :param private: bool + :rtype: :class:`github.Repository.Repository` + """ + assert isinstance(repo, github.Repository.Repository), repo + assert isinstance(repo, github.Repository.Repository), repo + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + post_parameters = { + "name": name, + "owner": self.login, + } + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if private is not github.GithubObject.NotSet: + post_parameters["private"] = private + headers, data = self._requester.requestJsonAndCheck( + "POST", + "/repos/" + repo.owner.login + "/" + repo.name + "/generate", + input=post_parameters, + headers={"Accept": Consts.mediaTypeTemplatesPreview}, + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True + ) + def create_gist(self, public, files, description=github.GithubObject.NotSet): """ :calls: `POST /gists `_ diff --git a/github/Consts.py b/github/Consts.py index ec2ae6bf98..3d83cc8f3b 100644 --- a/github/Consts.py +++ b/github/Consts.py @@ -99,7 +99,10 @@ # https://developer.github.com/changes/2018-05-24-user-migration-api/ mediaTypeMigrationPreview = "application/vnd.github.wyandotte-preview+json" -# https://docs.github.com/en/rest/reference/search#highlighting-code-search-results-1 +# https://developer.github.com/changes/2019-07-16-repository-templates-api/ +mediaTypeTemplatesPreview = "application/vnd.github.baptiste-preview+json" + +# https://developer.github.com/v3/search/#highlighting-code-search-results-1 highLightSearchPreview = "application/vnd.github.v3.text-match+json" # https://developer.github.com/changes/2018-02-22-protected-branches-required-signatures/ diff --git a/github/Organization.py b/github/Organization.py index 0248945430..9b9332d043 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -403,6 +403,47 @@ def create_fork(self, repo): self._requester, headers, data, completed=True ) + def create_repo_from_template( + self, + name, + repo, + description=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + ): + """self.name + :calls: `POST /repos/:owner/:name/generate `_ + :param name: string + :param repo :class:`github.Repository.Repository` + :param description: string + :param private: bool + :rtype: :class:`github.Repository.Repository` + """ + assert isinstance(name, str), name + assert isinstance(repo, github.Repository.Repository), repo + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + post_parameters = { + "name": name, + "owner": self.login, + } + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if private is not github.GithubObject.NotSet: + post_parameters["private"] = private + headers, data = self._requester.requestJsonAndCheck( + "POST", + "/repos/" + repo.owner.login + "/" + repo.name + "/generate", + input=post_parameters, + headers={"Accept": Consts.mediaTypeTemplatesPreview}, + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True + ) + def create_hook( self, name, From 18c1d07742e5dc0bc7b31e26c763d911a9f1e0da Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Tue, 11 Feb 2020 10:29:11 -0300 Subject: [PATCH 12/25] Fix create_repo_from_template docstring url --- github/Organization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/Organization.py b/github/Organization.py index 9b9332d043..4bc02b70fa 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -411,7 +411,7 @@ def create_repo_from_template( private=github.GithubObject.NotSet, ): """self.name - :calls: `POST /repos/:owner/:name/generate `_ + :calls: `POST /repos/:template_owner/:template_repo/generate `_ :param name: string :param repo :class:`github.Repository.Repository` :param description: string From 476ee42a1f183d53a39fd1d3a7e54e0c1c0e36a4 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Tue, 11 Feb 2020 10:31:18 -0300 Subject: [PATCH 13/25] Add is_template attribute to Repository --- github/Repository.py | 11 +++++++++++ scripts/add_attribute.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/github/Repository.py b/github/Repository.py index 835c994e74..b7fc1a30f1 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -473,6 +473,14 @@ def id(self): self._completeIfNotSet(self._id) return self._id.value + @property + def is_template(self): + """ + :type: bool + """ + self._completeIfNotSet(self._is_template) + return self._is_template.value + @property def issue_comment_url(self): """ @@ -3699,6 +3707,7 @@ def _initAttributes(self): self._hooks_url = github.GithubObject.NotSet self._html_url = github.GithubObject.NotSet self._id = github.GithubObject.NotSet + self._is_template = github.GithubObject.NotSet self._issue_comment_url = github.GithubObject.NotSet self._issue_events_url = github.GithubObject.NotSet self._issues_url = github.GithubObject.NotSet @@ -3840,6 +3849,8 @@ def _useAttributes(self, attributes): self._html_url = self._makeStringAttribute(attributes["html_url"]) if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) + if "is_template" in attributes: # pragma no branch + self._is_template = self._makeBoolAttribute(attributes["is_template"]) if "issue_comment_url" in attributes: # pragma no branch self._issue_comment_url = self._makeStringAttribute( attributes["issue_comment_url"] diff --git a/scripts/add_attribute.py b/scripts/add_attribute.py index 73bc1a58c5..7b8513e76f 100644 --- a/scripts/add_attribute.py +++ b/scripts/add_attribute.py @@ -183,4 +183,4 @@ with open(fileName, "w") as f: for line in newLines: - f.write(line + "\n") + f.write((line + "\n").encode()) From b0188533bb2dfe035a49f4f3307523d240ff87fa Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 16:11:06 -0300 Subject: [PATCH 14/25] Add tests for the new create_repo_from_template method --- github/AuthenticatedUser.py | 2 +- tests/AuthenticatedUser.py | 16 +++++++++ tests/Organization.py | 16 +++++++++ ...ticatedUser.testCreateRepoFromTemplate.txt | 33 +++++++++++++++++++ ...CreateRepoFromTemplateWithAllArguments.txt | 33 +++++++++++++++++++ ...rganization.testCreateRepoFromTemplate.txt | 22 +++++++++++++ ...CreateRepoFromTemplateWithAllArguments.txt | 22 +++++++++++++ tests/Repository.py | 1 + 8 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt create mode 100644 tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt create mode 100644 tests/ReplayData/Organization.testCreateRepoFromTemplate.txt create mode 100644 tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index ad129f63f7..520ab24447 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -509,7 +509,7 @@ def create_repo_from_template( private=github.GithubObject.NotSet, ): """ - :calls: `POST /repos/:owner/:name/generate `_ + :calls: `POST /repos/:template_owner/:template_repo/generate ` :param name: string :param repo :class:`github.Repository.Repository` :param description: string diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index ac32251cfa..7fc801d670 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -663,6 +663,22 @@ def testCreateFork(self): repo = self.user.create_fork(self.g.get_user("nvie").get_repo("gitflow")) self.assertEqual(repo.source.full_name, "nvie/gitflow") + def testCreateRepoFromTemplate(self): + template_repo = self.g.get_repo("actions/hello-world-docker-action") + + repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo) + self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/hello-world-docker-action-new") + self.assertEqual(repo.is_template, False) + + def testCreateRepoFromTemplateWithAllArguments(self): + template_repo = self.g.get_repo("actions/hello-world-docker-action") + + description = "My repo from template" + private = True + repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) + self.assertEqual(repo.description, description) + self.assertEqual(repo.private, private) + def testGetNotification(self): notification = self.user.get_notification("8406712") self.assertEqual(notification.id, "8406712") diff --git a/tests/Organization.py b/tests/Organization.py index de59a52383..ae29f25583 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -356,6 +356,22 @@ def testCreateFork(self): self.assertFalse(repo.has_wiki) self.assertFalse(repo.has_pages) + def testCreateRepoFromTemplate(self): + template_repo = self.g.get_repo("actions/hello-world-docker-action") + + repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo) + self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new") + self.assertEqual(repo.is_template, False) + + def testCreateRepoFromTemplateWithAllArguments(self): + template_repo = self.g.get_repo("actions/hello-world-docker-action") + + description = "My repo from template" + private = True + repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) + self.assertEqual(repo.description, description) + self.assertEqual(repo.private, private) + def testInviteUserWithNeither(self): with self.assertRaises(AssertionError) as raisedexp: self.org.invite_user() diff --git a/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt new file mode 100644 index 0000000000..3ab48b9c2e --- /dev/null +++ b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt @@ -0,0 +1,33 @@ +https +GET +api.github.com +None +/repos/actions/hello-world-docker-action +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 16:56:45 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4997'), ('X-RateLimit-Reset', '1581443569'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', 'W/"63c75e6c241c8aa34fa31eaac3091d88"'), ('Last-Modified', 'Fri, 07 Feb 2020 09:28:27 GMT'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '5200:6A2A:85CA2:FC534:5E42DCCD')] +{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","private":false,"owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"admin":false,"push":false,"pull":true},"temp_clone_token":"","organization":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"network_count":30,"subscribers_count":1} + +https +GET +api.github.com +None +/user +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"79f748546e5fc4492505a70de6542183"'), ('date', 'Tue, 08 May 2012 09:51:20 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"public_repos":10,"type":"User","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","followers":13,"bio":"","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","disk_usage":16692,"plan":{"private_repos":5,"space":614400,"name":"micro","collaborators":1},"html_url":"https://github.com/jacquev6","blog":"http://vincent-jacques.net","login":"jacquev6","email":"vincent@vincent-jacques.net","created_at":"2010-07-09T06:10:06Z","company":"Criteo","location":"Paris, France","total_private_repos":5,"public_gists":1,"following":24,"name":"Vincent Jacques","id":327146,"owned_private_repos":5,"private_gists":5,"collaborators":0,"hireable":false,"node_id":"MDQ6VXNlcjMyNzE0Ng=="} + +https +POST +api.github.com +None +/repos/actions/hello-world-docker-action/generate +{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"name": "hello-world-docker-action-new", "owner": "jacquev6"} +201 +[('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 16:56:49 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '11775'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4995'), ('X-RateLimit-Reset', '1581443568'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"eabd6fce61227c57848e030e45c468c3"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/jacquev6/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '8C7A:1AEB:84521:F940F:5E42DCCE')] +{"id":239815940,"node_id":"MDEwOlJlcG9zaXRvcnkyMzk4MTU5NDA=","name":"hello-world-docker-action-new","full_name":"jacquev6/hello-world-docker-action-new","owner":{"login":"jacquev6","id":9718970,"node_id":"MDQ6VXNlcjk3MTg5NzA=","avatar_url":"https://avatars2.githubusercontent.com/u/9718970?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jacquev6/hello-world-docker-action-new","description":null,"fork":false,"url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new","forks_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/forks","keys_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/teams","hooks_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/hooks","issue_events_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues/events{/number}","events_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/events","assignees_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/assignees{/user}","branches_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/branches{/branch}","tags_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/tags","blobs_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/refs{/sha}","trees_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/statuses/{sha}","languages_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/languages","stargazers_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/stargazers","contributors_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/contributors","subscribers_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/subscribers","subscription_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/subscription","commits_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/commits{/sha}","git_commits_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/commits{/sha}","comments_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/comments{/number}","issue_comment_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues/comments{/number}","contents_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/contents/{+path}","compare_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/merges","archive_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/downloads","issues_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues{/number}","pulls_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/pulls{/number}","milestones_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/milestones{/number}","notifications_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/labels{/name}","releases_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/releases{/id}","deployments_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/deployments","created_at":"2020-02-11T16:56:47Z","updated_at":"2020-02-11T16:56:47Z","pushed_at":"2020-02-11T16:56:48Z","git_url":"git://github.com/jacquev6/hello-world-docker-action-new.git","ssh_url":"git@github.com:jacquev6/hello-world-docker-action-new.git","clone_url":"https://github.com/jacquev6/hello-world-docker-action-new.git","svn_url":"https://github.com/jacquev6/hello-world-docker-action-new","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"pull":true,"push":true,"admin":true},"is_template":false,"template_repository":{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"pull":true,"push":false,"admin":false},"is_template":true},"subscribers_count":1,"network_count":1} + diff --git a/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt new file mode 100644 index 0000000000..13bbac4fb8 --- /dev/null +++ b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt @@ -0,0 +1,33 @@ +https +GET +api.github.com +None +/repos/actions/hello-world-docker-action +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 19:18:56 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4996'), ('X-RateLimit-Reset', '1581452316'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', 'W/"63c75e6c241c8aa34fa31eaac3091d88"'), ('Last-Modified', 'Fri, 07 Feb 2020 09:28:27 GMT'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '1BD6:14E8:BA6CC:1C4CAD:5E42FE20')] +{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","private":false,"owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"admin":false,"push":false,"pull":true},"temp_clone_token":"","organization":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"network_count":30,"subscribers_count":1} + +https +GET +api.github.com +None +/user +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"79f748546e5fc4492505a70de6542183"'), ('date', 'Tue, 08 May 2012 09:51:20 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"public_repos":10,"type":"User","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","followers":13,"bio":"","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","disk_usage":16692,"plan":{"private_repos":5,"space":614400,"name":"micro","collaborators":1},"html_url":"https://github.com/jacquev6","blog":"http://vincent-jacques.net","login":"jacquev6","email":"vincent@vincent-jacques.net","created_at":"2010-07-09T06:10:06Z","company":"Criteo","location":"Paris, France","total_private_repos":5,"public_gists":1,"following":24,"name":"Vincent Jacques","id":327146,"owned_private_repos":5,"private_gists":5,"collaborators":0,"hireable":false,"node_id":"MDQ6VXNlcjMyNzE0Ng=="} + +https +POST +api.github.com +None +/repos/actions/hello-world-docker-action/generate +{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"name": "hello-world-docker-action-new", "owner": "jacquev6", "description": "My repo from template", "private": true} +201 +[('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 19:18:59 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '11794'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4994'), ('X-RateLimit-Reset', '1581452316'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"7fe9f51a711de4ffab9b930e33e3d875"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/jacquev6/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '3FB4:2492:632B7:FC388:5E42FE21')] +{"id":239844699,"node_id":"MDEwOlJlcG9zaXRvcnkyMzk4NDQ2OTk=","name":"hello-world-docker-action-new","full_name":"jacquev6/hello-world-docker-action-new","owner":{"login":"jacquev6","id":9718970,"node_id":"MDQ6VXNlcjk3MTg5NzA=","avatar_url":"https://avatars2.githubusercontent.com/u/9718970?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"private":true,"html_url":"https://github.com/jacquev6/hello-world-docker-action-new","description":"My repo from template","fork":false,"url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new","forks_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/forks","keys_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/teams","hooks_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/hooks","issue_events_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues/events{/number}","events_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/events","assignees_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/assignees{/user}","branches_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/branches{/branch}","tags_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/tags","blobs_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/refs{/sha}","trees_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/statuses/{sha}","languages_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/languages","stargazers_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/stargazers","contributors_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/contributors","subscribers_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/subscribers","subscription_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/subscription","commits_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/commits{/sha}","git_commits_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/git/commits{/sha}","comments_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/comments{/number}","issue_comment_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues/comments{/number}","contents_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/contents/{+path}","compare_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/merges","archive_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/downloads","issues_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/issues{/number}","pulls_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/pulls{/number}","milestones_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/milestones{/number}","notifications_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/labels{/name}","releases_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/releases{/id}","deployments_url":"https://api.github.com/repos/jacquev6/hello-world-docker-action-new/deployments","created_at":"2020-02-11T19:18:57Z","updated_at":"2020-02-11T19:18:57Z","pushed_at":"2020-02-11T19:18:59Z","git_url":"git://github.com/jacquev6/hello-world-docker-action-new.git","ssh_url":"git@github.com:jacquev6/hello-world-docker-action-new.git","clone_url":"https://github.com/jacquev6/hello-world-docker-action-new.git","svn_url":"https://github.com/jacquev6/hello-world-docker-action-new","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"pull":true,"push":true,"admin":true},"is_template":false,"template_repository":{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"pull":true,"push":false,"admin":false},"is_template":true},"subscribers_count":1,"network_count":1} + diff --git a/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt b/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt new file mode 100644 index 0000000000..9d97746918 --- /dev/null +++ b/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt @@ -0,0 +1,22 @@ +https +GET +api.github.com +None +/repos/actions/hello-world-docker-action +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 13:54:27 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4998'), ('X-RateLimit-Reset', '1581519266'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', 'W/"63c75e6c241c8aa34fa31eaac3091d88"'), ('Last-Modified', 'Fri, 07 Feb 2020 09:28:27 GMT'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '4A6A:20CC:7983B:E89EF:5E440392')] +{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","private":false,"owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"admin":false,"push":false,"pull":true},"temp_clone_token":"","organization":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"network_count":30,"subscribers_count":1} + +https +POST +api.github.com +None +/repos/actions/hello-world-docker-action/generate +{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"name": "hello-world-docker-action-new", "owner": "BeaverSoftware"} +201 +[('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 13:54:29 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '12600'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4997'), ('X-RateLimit-Reset', '1581519266'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"36abdc4630fb044196d6efbfc0f644e0"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '8C3C:2BF7:ACD4:17C45:5E440393')] +{"id":240025159,"node_id":"MDEwOlJlcG9zaXRvcnkyNDAwMjUxNTk=","name":"hello-world-docker-action-new","full_name":"BeaverSoftware/hello-world-docker-action-new","owner":{"login":"BeaverSoftware","id":60894054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwODk0MDU0","avatar_url":"https://avatars2.githubusercontent.com/u/60894054?v=4","gravatar_id":"","url":"https://api.github.com/users/BeaverSoftware","html_url":"https://github.com/BeaverSoftware","followers_url":"https://api.github.com/users/BeaverSoftware/followers","following_url":"https://api.github.com/users/BeaverSoftware/following{/other_user}","gists_url":"https://api.github.com/users/BeaverSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/BeaverSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeaverSoftware/subscriptions","organizations_url":"https://api.github.com/users/BeaverSoftware/orgs","repos_url":"https://api.github.com/users/BeaverSoftware/repos","events_url":"https://api.github.com/users/BeaverSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/BeaverSoftware/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new","description":null,"fork":false,"url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new","forks_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/forks","keys_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/teams","hooks_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/hooks","issue_events_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues/events{/number}","events_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/events","assignees_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/assignees{/user}","branches_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/branches{/branch}","tags_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/tags","blobs_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/refs{/sha}","trees_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/statuses/{sha}","languages_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/languages","stargazers_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/stargazers","contributors_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/contributors","subscribers_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/subscribers","subscription_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/subscription","commits_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/commits{/sha}","git_commits_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/commits{/sha}","comments_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/comments{/number}","issue_comment_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues/comments{/number}","contents_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/contents/{+path}","compare_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/merges","archive_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/downloads","issues_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues{/number}","pulls_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/pulls{/number}","milestones_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/milestones{/number}","notifications_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/labels{/name}","releases_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/releases{/id}","deployments_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/deployments","created_at":"2020-02-12T13:54:28Z","updated_at":"2020-02-12T13:54:28Z","pushed_at":"2020-02-12T13:54:29Z","git_url":"git://github.com/BeaverSoftware/hello-world-docker-action-new.git","ssh_url":"git@github.com:BeaverSoftware/hello-world-docker-action-new.git","clone_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new.git","svn_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"pull":true,"push":true,"admin":true},"is_template":false,"template_repository":{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"pull":true,"push":false,"admin":false},"is_template":true},"organization":{"login":"BeaverSoftware","id":60894054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwODk0MDU0","avatar_url":"https://avatars2.githubusercontent.com/u/60894054?v=4","gravatar_id":"","url":"https://api.github.com/users/BeaverSoftware","html_url":"https://github.com/BeaverSoftware","followers_url":"https://api.github.com/users/BeaverSoftware/followers","following_url":"https://api.github.com/users/BeaverSoftware/following{/other_user}","gists_url":"https://api.github.com/users/BeaverSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/BeaverSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeaverSoftware/subscriptions","organizations_url":"https://api.github.com/users/BeaverSoftware/orgs","repos_url":"https://api.github.com/users/BeaverSoftware/repos","events_url":"https://api.github.com/users/BeaverSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/BeaverSoftware/received_events","type":"Organization","site_admin":false},"subscribers_count":0,"network_count":1} + diff --git a/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt b/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt new file mode 100644 index 0000000000..8e45505ef5 --- /dev/null +++ b/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt @@ -0,0 +1,22 @@ +https +GET +api.github.com +None +/repos/actions/hello-world-docker-action +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 18:18:10 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4992'), ('X-RateLimit-Reset', '1581534987'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', 'W/"63c75e6c241c8aa34fa31eaac3091d88"'), ('Last-Modified', 'Fri, 07 Feb 2020 09:28:27 GMT'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '41AB:41D3:1FFAAB:3C0DBC:5E444162')] +{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","private":false,"owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"admin":false,"push":false,"pull":true},"temp_clone_token":"","organization":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"network_count":30,"subscribers_count":1} + +https +POST +api.github.com +None +/repos/actions/hello-world-docker-action/generate +{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"name": "hello-world-docker-action-new", "owner": "BeaverSoftware", "description": "My repo from template", "private": true} +201 +[('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 18:18:12 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '12619'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4991'), ('X-RateLimit-Reset', '1581534987'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"7ab10890a25b4661a4310dc8dbf4491f"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', 'C35C:1792:11E12C:2D04D2:5E444162')] +{"id":240083127,"node_id":"MDEwOlJlcG9zaXRvcnkyNDAwODMxMjc=","name":"hello-world-docker-action-new","full_name":"BeaverSoftware/hello-world-docker-action-new","owner":{"login":"BeaverSoftware","id":60894054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwODk0MDU0","avatar_url":"https://avatars2.githubusercontent.com/u/60894054?v=4","gravatar_id":"","url":"https://api.github.com/users/BeaverSoftware","html_url":"https://github.com/BeaverSoftware","followers_url":"https://api.github.com/users/BeaverSoftware/followers","following_url":"https://api.github.com/users/BeaverSoftware/following{/other_user}","gists_url":"https://api.github.com/users/BeaverSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/BeaverSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeaverSoftware/subscriptions","organizations_url":"https://api.github.com/users/BeaverSoftware/orgs","repos_url":"https://api.github.com/users/BeaverSoftware/repos","events_url":"https://api.github.com/users/BeaverSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/BeaverSoftware/received_events","type":"Organization","site_admin":false},"private":true,"html_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new","description":"My repo from template","fork":false,"url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new","forks_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/forks","keys_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/teams","hooks_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/hooks","issue_events_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues/events{/number}","events_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/events","assignees_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/assignees{/user}","branches_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/branches{/branch}","tags_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/tags","blobs_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/refs{/sha}","trees_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/statuses/{sha}","languages_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/languages","stargazers_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/stargazers","contributors_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/contributors","subscribers_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/subscribers","subscription_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/subscription","commits_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/commits{/sha}","git_commits_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/git/commits{/sha}","comments_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/comments{/number}","issue_comment_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues/comments{/number}","contents_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/contents/{+path}","compare_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/merges","archive_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/downloads","issues_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/issues{/number}","pulls_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/pulls{/number}","milestones_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/milestones{/number}","notifications_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/labels{/name}","releases_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/releases{/id}","deployments_url":"https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new/deployments","created_at":"2020-02-12T18:18:11Z","updated_at":"2020-02-12T18:18:11Z","pushed_at":"2020-02-12T18:18:12Z","git_url":"git://github.com/BeaverSoftware/hello-world-docker-action-new.git","ssh_url":"git@github.com:BeaverSoftware/hello-world-docker-action-new.git","clone_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new.git","svn_url":"https://github.com/BeaverSoftware/hello-world-docker-action-new","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","permissions":{"pull":true,"push":true,"admin":true},"is_template":false,"template_repository":{"id":200448202,"node_id":"MDEwOlJlcG9zaXRvcnkyMDA0NDgyMDI=","name":"hello-world-docker-action","full_name":"actions/hello-world-docker-action","owner":{"login":"actions","id":44036562,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0MDM2NTYy","avatar_url":"https://avatars1.githubusercontent.com/u/44036562?v=4","gravatar_id":"","url":"https://api.github.com/users/actions","html_url":"https://github.com/actions","followers_url":"https://api.github.com/users/actions/followers","following_url":"https://api.github.com/users/actions/following{/other_user}","gists_url":"https://api.github.com/users/actions/gists{/gist_id}","starred_url":"https://api.github.com/users/actions/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/actions/subscriptions","organizations_url":"https://api.github.com/users/actions/orgs","repos_url":"https://api.github.com/users/actions/repos","events_url":"https://api.github.com/users/actions/events{/privacy}","received_events_url":"https://api.github.com/users/actions/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/actions/hello-world-docker-action","description":"A template to demonstrate how to build a Docker action.","fork":false,"url":"https://api.github.com/repos/actions/hello-world-docker-action","forks_url":"https://api.github.com/repos/actions/hello-world-docker-action/forks","keys_url":"https://api.github.com/repos/actions/hello-world-docker-action/keys{/key_id}","collaborators_url":"https://api.github.com/repos/actions/hello-world-docker-action/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/actions/hello-world-docker-action/teams","hooks_url":"https://api.github.com/repos/actions/hello-world-docker-action/hooks","issue_events_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/events{/number}","events_url":"https://api.github.com/repos/actions/hello-world-docker-action/events","assignees_url":"https://api.github.com/repos/actions/hello-world-docker-action/assignees{/user}","branches_url":"https://api.github.com/repos/actions/hello-world-docker-action/branches{/branch}","tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/tags","blobs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/refs{/sha}","trees_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/trees{/sha}","statuses_url":"https://api.github.com/repos/actions/hello-world-docker-action/statuses/{sha}","languages_url":"https://api.github.com/repos/actions/hello-world-docker-action/languages","stargazers_url":"https://api.github.com/repos/actions/hello-world-docker-action/stargazers","contributors_url":"https://api.github.com/repos/actions/hello-world-docker-action/contributors","subscribers_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscribers","subscription_url":"https://api.github.com/repos/actions/hello-world-docker-action/subscription","commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/commits{/sha}","git_commits_url":"https://api.github.com/repos/actions/hello-world-docker-action/git/commits{/sha}","comments_url":"https://api.github.com/repos/actions/hello-world-docker-action/comments{/number}","issue_comment_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues/comments{/number}","contents_url":"https://api.github.com/repos/actions/hello-world-docker-action/contents/{+path}","compare_url":"https://api.github.com/repos/actions/hello-world-docker-action/compare/{base}...{head}","merges_url":"https://api.github.com/repos/actions/hello-world-docker-action/merges","archive_url":"https://api.github.com/repos/actions/hello-world-docker-action/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/actions/hello-world-docker-action/downloads","issues_url":"https://api.github.com/repos/actions/hello-world-docker-action/issues{/number}","pulls_url":"https://api.github.com/repos/actions/hello-world-docker-action/pulls{/number}","milestones_url":"https://api.github.com/repos/actions/hello-world-docker-action/milestones{/number}","notifications_url":"https://api.github.com/repos/actions/hello-world-docker-action/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/actions/hello-world-docker-action/labels{/name}","releases_url":"https://api.github.com/repos/actions/hello-world-docker-action/releases{/id}","deployments_url":"https://api.github.com/repos/actions/hello-world-docker-action/deployments","created_at":"2019-08-04T04:10:12Z","updated_at":"2020-02-07T09:28:27Z","pushed_at":"2020-01-17T19:48:23Z","git_url":"git://github.com/actions/hello-world-docker-action.git","ssh_url":"git@github.com:actions/hello-world-docker-action.git","clone_url":"https://github.com/actions/hello-world-docker-action.git","svn_url":"https://github.com/actions/hello-world-docker-action","homepage":"https://help.github.com/en/articles/creating-a-docker-container-action","size":11,"stargazers_count":26,"watchers_count":26,"language":"Dockerfile","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":30,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":30,"open_issues":1,"watchers":26,"default_branch":"master","permissions":{"pull":true,"push":false,"admin":false},"is_template":true},"organization":{"login":"BeaverSoftware","id":60894054,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYwODk0MDU0","avatar_url":"https://avatars2.githubusercontent.com/u/60894054?v=4","gravatar_id":"","url":"https://api.github.com/users/BeaverSoftware","html_url":"https://github.com/BeaverSoftware","followers_url":"https://api.github.com/users/BeaverSoftware/followers","following_url":"https://api.github.com/users/BeaverSoftware/following{/other_user}","gists_url":"https://api.github.com/users/BeaverSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/BeaverSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BeaverSoftware/subscriptions","organizations_url":"https://api.github.com/users/BeaverSoftware/orgs","repos_url":"https://api.github.com/users/BeaverSoftware/repos","events_url":"https://api.github.com/users/BeaverSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/BeaverSoftware/received_events","type":"Organization","site_admin":false},"subscribers_count":0,"network_count":1} + diff --git a/tests/Repository.py b/tests/Repository.py index e30aa884c8..935d7bdfc1 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -89,6 +89,7 @@ def testAttributes(self): self.assertEqual(self.repo.homepage, "http://vincent-jacques.net/PyGithub") self.assertEqual(self.repo.html_url, "https://github.com/jacquev6/PyGithub") self.assertEqual(self.repo.id, 3544490) + self.assertEqual(self.repo.is_template, None) self.assertEqual(self.repo.language, "Python") self.assertEqual(self.repo.master_branch, None) self.assertEqual(self.repo.name, "PyGithub") From aca2570a38d8547a091da6472d3b5e28fa5b22fc Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 17:16:29 -0300 Subject: [PATCH 15/25] Fix name assertion --- github/AuthenticatedUser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 520ab24447..6afaebacc5 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -516,7 +516,7 @@ def create_repo_from_template( :param private: bool :rtype: :class:`github.Repository.Repository` """ - assert isinstance(repo, github.Repository.Repository), repo + assert isinstance(name, str), name assert isinstance(repo, github.Repository.Repository), repo assert description is github.GithubObject.NotSet or isinstance( description, str From 3b53479f8b335a0b00416f565bb5f7bf4c970498 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 22:08:46 -0300 Subject: [PATCH 16/25] fix flake8 violation --- github/AuthenticatedUser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 6afaebacc5..3d50493eac 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -537,7 +537,7 @@ def create_repo_from_template( "/repos/" + repo.owner.login + "/" + repo.name + "/generate", input=post_parameters, headers={"Accept": Consts.mediaTypeTemplatesPreview}, - ) + ) return github.Repository.Repository( self._requester, headers, data, completed=True ) From ba76eff13c99a5882b1db5ed2b26b215b11e3cb3 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 22:32:01 -0300 Subject: [PATCH 17/25] refactor assertions --- tests/AuthenticatedUser.py | 2 +- tests/Organization.py | 2 +- tests/Repository.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index 7fc801d670..276d1b3a9f 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -677,7 +677,7 @@ def testCreateRepoFromTemplateWithAllArguments(self): private = True repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) self.assertEqual(repo.description, description) - self.assertEqual(repo.private, private) + self.assertTrue(repo.private) def testGetNotification(self): notification = self.user.get_notification("8406712") diff --git a/tests/Organization.py b/tests/Organization.py index ae29f25583..42151eeb03 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -370,7 +370,7 @@ def testCreateRepoFromTemplateWithAllArguments(self): private = True repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) self.assertEqual(repo.description, description) - self.assertEqual(repo.private, private) + self.assertTrue(repo.private) def testInviteUserWithNeither(self): with self.assertRaises(AssertionError) as raisedexp: diff --git a/tests/Repository.py b/tests/Repository.py index 935d7bdfc1..cdc78b761b 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -89,7 +89,7 @@ def testAttributes(self): self.assertEqual(self.repo.homepage, "http://vincent-jacques.net/PyGithub") self.assertEqual(self.repo.html_url, "https://github.com/jacquev6/PyGithub") self.assertEqual(self.repo.id, 3544490) - self.assertEqual(self.repo.is_template, None) + self.assertIs(self.repo.is_template, None) self.assertEqual(self.repo.language, "Python") self.assertEqual(self.repo.master_branch, None) self.assertEqual(self.repo.name, "PyGithub") From f0372a9d8b62a7ae7e875829ebdd3878ef39c988 Mon Sep 17 00:00:00 2001 From: KimSia Sim Date: Sat, 31 Jul 2021 11:28:16 +0800 Subject: [PATCH 18/25] Revert scripts/add_attribute.py change --- github/Repository.py | 3961 -------------------------------------- scripts/add_attribute.py | 2 +- 2 files changed, 1 insertion(+), 3962 deletions(-) diff --git a/github/Repository.py b/github/Repository.py index b7fc1a30f1..e69de29bb2 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -1,3961 +0,0 @@ -############################ Copyrights and license ############################ -# # -# Copyright 2012 Christopher Gilbert # -# Copyright 2012 Steve English # -# Copyright 2012 Vincent Jacques # -# Copyright 2012 Zearin # -# Copyright 2013 AKFish # -# Copyright 2013 Adrian Petrescu # -# Copyright 2013 Cameron White # -# Copyright 2013 David Farr # -# Copyright 2013 Mark Roddy # -# Copyright 2013 Vincent Jacques # -# Copyright 2013 martinqt # -# Copyright 2014 Vincent Jacques # -# Copyright 2015 Aaron Levine # -# Copyright 2015 Christopher Wilcox # -# Copyright 2015 Dan Vanderkam # -# Copyright 2015 Ed Holland # -# Copyright 2015 Enix Yu # -# Copyright 2015 Jay # -# Copyright 2015 Jimmy Zelinskie # -# Copyright 2015 Jonathan Debonis # -# Copyright 2015 Kevin Lewandowski # -# Copyright 2015 Kyle Hornberg # -# Copyright 2015 edhollandAL # -# Copyright 2016 @tmshn # -# Copyright 2016 Dustin Spicuzza # -# Copyright 2016 Enix Yu # -# Copyright 2016 Jannis Gebauer # -# Copyright 2016 Per Øyvind Karlsen # -# Copyright 2016 Peter Buckley # -# Copyright 2016 Sylvus # -# Copyright 2016 fukatani # -# Copyright 2016 ghfan # -# Copyright 2017 Andreas Lutro # -# Copyright 2017 Ben Firshman # -# Copyright 2017 Chris McBride # -# Copyright 2017 Hugo # -# Copyright 2017 Jannis Gebauer # -# Copyright 2017 Jason White # -# Copyright 2017 Jimmy Zelinskie # -# Copyright 2017 Nhomar Hernández [Vauxoo] # -# Copyright 2017 Simon # -# Copyright 2018 Andrew Smith # -# Copyright 2018 Brian Torres-Gil # -# Copyright 2018 Hayden Fuss # -# Copyright 2018 Ilya Konstantinov # -# Copyright 2018 Jacopo Notarstefano # -# Copyright 2018 John Hui # -# Copyright 2018 Mateusz Loskot # -# Copyright 2018 Michael Behrisch # -# Copyright 2018 Nicholas Buse # -# Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> # -# Copyright 2018 Shinichi TAMURA # -# Copyright 2018 Steve Kowalik # -# Copyright 2018 Wan Liuyang # -# Copyright 2018 Will Yardley # -# Copyright 2018 per1234 # -# Copyright 2018 sechastain # -# Copyright 2018 sfdye # -# Copyright 2018 Vinay Hegde # -# Copyright 2018 Justin Kufro # -# Copyright 2018 Ivan Minno # -# Copyright 2018 Zilei Gu # -# Copyright 2018 Yves Zumbach # -# Copyright 2018 Leying Chen # -# Copyright 2020 Pascal Hofmann # -# # -# This file is part of PyGithub. # -# http://pygithub.readthedocs.io/ # -# # -# PyGithub is free software: you can redistribute it and/or modify it under # -# the terms of the GNU Lesser General Public License as published by the Free # -# Software Foundation, either version 3 of the License, or (at your option) # -# any later version. # -# # -# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # -# details. # -# # -# You should have received a copy of the GNU Lesser General Public License # -# along with PyGithub. If not, see . # -# # -################################################################################ - -import collections -import datetime -import urllib.parse -from base64 import b64encode - -from deprecated import deprecated - -import github.Branch -import github.CheckRun -import github.CheckSuite -import github.Clones -import github.Commit -import github.CommitComment -import github.Comparison -import github.ContentFile -import github.Deployment -import github.Download -import github.Event -import github.GitBlob -import github.GitCommit -import github.GithubObject -import github.GitRef -import github.GitRelease -import github.GitReleaseAsset -import github.GitTag -import github.GitTree -import github.Hook -import github.Invitation -import github.Issue -import github.IssueEvent -import github.Label -import github.Milestone -import github.NamedUser -import github.Organization -import github.PaginatedList -import github.Path -import github.Permissions -import github.Project -import github.PublicKey -import github.PullRequest -import github.Referrer -import github.Repository -import github.RepositoryKey -import github.RepositoryPreferences -import github.SelfHostedActionsRunner -import github.SourceImport -import github.Stargazer -import github.StatsCodeFrequency -import github.StatsCommitActivity -import github.StatsContributor -import github.StatsParticipation -import github.StatsPunchCard -import github.Tag -import github.Team -import github.View -import github.Workflow -import github.WorkflowRun - -from . import Consts - - -class Repository(github.GithubObject.CompletableGithubObject): - """ - This class represents Repositories. The reference can be found here http://docs.github.com/en/rest/reference/repos - """ - - def __repr__(self): - return self.get__repr__({"full_name": self._full_name.value}) - - @property - def allow_merge_commit(self): - """ - :type: bool - """ - self._completeIfNotSet(self._allow_merge_commit) - return self._allow_merge_commit.value - - @property - def allow_rebase_merge(self): - """ - :type: bool - """ - self._completeIfNotSet(self._allow_rebase_merge) - return self._allow_rebase_merge.value - - @property - def allow_squash_merge(self): - """ - :type: bool - """ - self._completeIfNotSet(self._allow_squash_merge) - return self._allow_squash_merge.value - - @property - def archived(self): - """ - :type: bool - """ - self._completeIfNotSet(self._archived) - return self._archived.value - - @property - def archive_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._archive_url) - return self._archive_url.value - - @property - def assignees_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._assignees_url) - return self._assignees_url.value - - @property - def blobs_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._blobs_url) - return self._blobs_url.value - - @property - def branches_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._branches_url) - return self._branches_url.value - - @property - def clone_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._clone_url) - return self._clone_url.value - - @property - def collaborators_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._collaborators_url) - return self._collaborators_url.value - - @property - def comments_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._comments_url) - return self._comments_url.value - - @property - def commits_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._commits_url) - return self._commits_url.value - - @property - def compare_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._compare_url) - return self._compare_url.value - - @property - def contents_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._contents_url) - return self._contents_url.value - - @property - def contributors_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._contributors_url) - return self._contributors_url.value - - @property - def created_at(self): - """ - :type: datetime.datetime - """ - self._completeIfNotSet(self._created_at) - return self._created_at.value - - @property - def default_branch(self): - """ - :type: string - """ - self._completeIfNotSet(self._default_branch) - return self._default_branch.value - - @property - def delete_branch_on_merge(self): - """ - :type: bool - """ - self._completeIfNotSet(self._delete_branch_on_merge) - return self._delete_branch_on_merge.value - - @property - def deployments_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._deployments_url) - return self._deployments_url.value - - @property - def description(self): - """ - :type: string - """ - self._completeIfNotSet(self._description) - return self._description.value - - @property - def downloads_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._downloads_url) - return self._downloads_url.value - - @property - def events_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._events_url) - return self._events_url.value - - @property - def fork(self): - """ - :type: bool - """ - self._completeIfNotSet(self._fork) - return self._fork.value - - @property - def forks(self): - """ - :type: integer - """ - self._completeIfNotSet(self._forks) - return self._forks.value - - @property - def forks_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._forks_count) - return self._forks_count.value - - @property - def forks_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._forks_url) - return self._forks_url.value - - @property - def full_name(self): - """ - :type: string - """ - self._completeIfNotSet(self._full_name) - return self._full_name.value - - @property - def git_commits_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._git_commits_url) - return self._git_commits_url.value - - @property - def git_refs_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._git_refs_url) - return self._git_refs_url.value - - @property - def git_tags_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._git_tags_url) - return self._git_tags_url.value - - @property - def git_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._git_url) - return self._git_url.value - - @property - def has_downloads(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_downloads) - return self._has_downloads.value - - @property - def has_issues(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_issues) - return self._has_issues.value - - @property - def has_pages(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_pages) - return self._has_pages.value - - @property - def has_projects(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_projects) - return self._has_projects.value - - @property - def has_wiki(self): - """ - :type: bool - """ - self._completeIfNotSet(self._has_wiki) - return self._has_wiki.value - - @property - def homepage(self): - """ - :type: string - """ - self._completeIfNotSet(self._homepage) - return self._homepage.value - - @property - def hooks_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._hooks_url) - return self._hooks_url.value - - @property - def html_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._html_url) - return self._html_url.value - - @property - def id(self): - """ - :type: integer - """ - self._completeIfNotSet(self._id) - return self._id.value - - @property - def is_template(self): - """ - :type: bool - """ - self._completeIfNotSet(self._is_template) - return self._is_template.value - - @property - def issue_comment_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._issue_comment_url) - return self._issue_comment_url.value - - @property - def issue_events_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._issue_events_url) - return self._issue_events_url.value - - @property - def issues_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._issues_url) - return self._issues_url.value - - @property - def keys_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._keys_url) - return self._keys_url.value - - @property - def labels_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._labels_url) - return self._labels_url.value - - @property - def language(self): - """ - :type: string - """ - self._completeIfNotSet(self._language) - return self._language.value - - @property - def languages_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._languages_url) - return self._languages_url.value - - @property - def master_branch(self): - """ - :type: string - """ - self._completeIfNotSet(self._master_branch) - return self._master_branch.value - - @property - def merges_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._merges_url) - return self._merges_url.value - - @property - def milestones_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._milestones_url) - return self._milestones_url.value - - @property - def mirror_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._mirror_url) - return self._mirror_url.value - - @property - def name(self): - """ - :type: string - """ - self._completeIfNotSet(self._name) - return self._name.value - - @property - def network_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._network_count) - return self._network_count.value - - @property - def notifications_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._notifications_url) - return self._notifications_url.value - - @property - def open_issues(self): - """ - :type: integer - """ - self._completeIfNotSet(self._open_issues) - return self._open_issues.value - - @property - def open_issues_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._open_issues_count) - return self._open_issues_count.value - - @property - def organization(self): - """ - :type: :class:`github.Organization.Organization` - """ - self._completeIfNotSet(self._organization) - return self._organization.value - - @property - def owner(self): - """ - :type: :class:`github.NamedUser.NamedUser` - """ - self._completeIfNotSet(self._owner) - return self._owner.value - - @property - def parent(self): - """ - :type: :class:`github.Repository.Repository` - """ - self._completeIfNotSet(self._parent) - return self._parent.value - - @property - def permissions(self): - """ - :type: :class:`github.Permissions.Permissions` - """ - self._completeIfNotSet(self._permissions) - return self._permissions.value - - @property - def private(self): - """ - :type: bool - """ - self._completeIfNotSet(self._private) - return self._private.value - - @property - def pulls_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._pulls_url) - return self._pulls_url.value - - @property - def pushed_at(self): - """ - :type: datetime.datetime - """ - self._completeIfNotSet(self._pushed_at) - return self._pushed_at.value - - @property - def releases_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._releases_url) - return self._releases_url.value - - @property - def size(self): - """ - :type: integer - """ - self._completeIfNotSet(self._size) - return self._size.value - - @property - def source(self): - """ - :type: :class:`github.Repository.Repository` - """ - self._completeIfNotSet(self._source) - return self._source.value - - @property - def ssh_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._ssh_url) - return self._ssh_url.value - - @property - def stargazers_count(self): - """ - :type: integer - """ - self._completeIfNotSet( - self._stargazers_count - ) # pragma no cover (Should be covered) - return self._stargazers_count.value # pragma no cover (Should be covered) - - @property - def stargazers_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._stargazers_url) - return self._stargazers_url.value - - @property - def statuses_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._statuses_url) - return self._statuses_url.value - - @property - def subscribers_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._subscribers_url) - return self._subscribers_url.value - - @property - def subscribers_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._subscribers_count) - return self._subscribers_count.value - - @property - def subscription_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._subscription_url) - return self._subscription_url.value - - @property - def svn_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._svn_url) - return self._svn_url.value - - @property - def tags_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._tags_url) - return self._tags_url.value - - @property - def teams_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._teams_url) - return self._teams_url.value - - @property - def trees_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._trees_url) - return self._trees_url.value - - @property - def updated_at(self): - """ - :type: datetime.datetime - """ - self._completeIfNotSet(self._updated_at) - return self._updated_at.value - - @property - def url(self): - """ - :type: string - """ - self._completeIfNotSet(self._url) - return self._url.value - - @property - def watchers(self): - """ - :type: integer - """ - self._completeIfNotSet(self._watchers) - return self._watchers.value - - @property - def watchers_count(self): - """ - :type: integer - """ - self._completeIfNotSet(self._watchers_count) - return self._watchers_count.value - - def add_to_collaborators(self, collaborator, permission=github.GithubObject.NotSet): - """ - :calls: `PUT /repos/{owner}/{repo}/collaborators/{user} `_ - :param collaborator: string or :class:`github.NamedUser.NamedUser` - :param permission: string 'pull', 'push' or 'admin' - :rtype: None - """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( - collaborator, str - ), collaborator - assert permission is github.GithubObject.NotSet or isinstance( - permission, str - ), permission - - if isinstance(collaborator, github.NamedUser.NamedUser): - collaborator = collaborator._identity - - if permission is not github.GithubObject.NotSet: - put_parameters = {"permission": permission} - else: - put_parameters = None - - headers, data = self._requester.requestJsonAndCheck( - "PUT", f"{self.url}/collaborators/{collaborator}", input=put_parameters - ) - # return an invitation object if there's data returned by the API. If data is empty - # there's a pending invitation for the given user. - return ( - github.Invitation.Invitation(self._requester, headers, data, completed=True) - if data is not None - else None - ) - - def get_collaborator_permission(self, collaborator): - """ - :calls: `GET /repos/{owner}/{repo}/collaborators/{username}/permission `_ - :param collaborator: string or :class:`github.NamedUser.NamedUser` - :rtype: string - """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( - collaborator, str - ), collaborator - if isinstance(collaborator, github.NamedUser.NamedUser): - collaborator = collaborator._identity - headers, data = self._requester.requestJsonAndCheck( - "GET", - f"{self.url}/collaborators/{collaborator}/permission", - ) - return data["permission"] - - def get_pending_invitations(self): - """ - :calls: `GET /repos/{owner}/{repo}/invitations `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Invitation.Invitation` - """ - return github.PaginatedList.PaginatedList( - github.Invitation.Invitation, - self._requester, - f"{self.url}/invitations", - None, - ) - - def remove_invitation(self, invite_id): - """ - :calls: `DELETE /repos/{owner}/{repo}/invitations/{invitation_id} `_ - :rtype: None - """ - assert isinstance(invite_id, int), invite_id - - headers, data = self._requester.requestJsonAndCheck( - "DELETE", f"{self.url}/invitations/{invite_id}" - ) - - def compare(self, base, head): - """ - :calls: `GET /repos/{owner}/{repo}/compare/{base...:head} `_ - :param base: string - :param head: string - :rtype: :class:`github.Comparison.Comparison` - """ - assert isinstance(base, str), base - assert isinstance(head, str), head - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/compare/{base}...{head}" - ) - return github.Comparison.Comparison( - self._requester, headers, data, completed=True - ) - - def create_git_blob(self, content, encoding): - """ - :calls: `POST /repos/{owner}/{repo}/git/blobs `_ - :param content: string - :param encoding: string - :rtype: :class:`github.GitBlob.GitBlob` - """ - assert isinstance(content, str), content - assert isinstance(encoding, str), encoding - post_parameters = { - "content": content, - "encoding": encoding, - } - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/git/blobs", input=post_parameters - ) - return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) - - def create_git_commit( - self, - message, - tree, - parents, - author=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/{owner}/{repo}/git/commits `_ - :param message: string - :param tree: :class:`github.GitTree.GitTree` - :param parents: list of :class:`github.GitCommit.GitCommit` - :param author: :class:`github.InputGitAuthor.InputGitAuthor` - :param committer: :class:`github.InputGitAuthor.InputGitAuthor` - :rtype: :class:`github.GitCommit.GitCommit` - """ - assert isinstance(message, str), message - assert isinstance(tree, github.GitTree.GitTree), tree - assert all( - isinstance(element, github.GitCommit.GitCommit) for element in parents - ), parents - assert author is github.GithubObject.NotSet or isinstance( - author, github.InputGitAuthor - ), author - assert committer is github.GithubObject.NotSet or isinstance( - committer, github.InputGitAuthor - ), committer - post_parameters = { - "message": message, - "tree": tree._identity, - "parents": [element._identity for element in parents], - } - if author is not github.GithubObject.NotSet: - post_parameters["author"] = author._identity - if committer is not github.GithubObject.NotSet: - post_parameters["committer"] = committer._identity - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/git/commits", input=post_parameters - ) - return github.GitCommit.GitCommit( - self._requester, headers, data, completed=True - ) - - def create_git_ref(self, ref, sha): - """ - :calls: `POST /repos/{owner}/{repo}/git/refs `_ - :param ref: string - :param sha: string - :rtype: :class:`github.GitRef.GitRef` - """ - assert isinstance(ref, str), ref - assert isinstance(sha, str), sha - post_parameters = { - "ref": ref, - "sha": sha, - } - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/git/refs", input=post_parameters - ) - return github.GitRef.GitRef(self._requester, headers, data, completed=True) - - def create_git_tag_and_release( - self, - tag, - tag_message, - release_name, - release_message, - object, - type, - tagger=github.GithubObject.NotSet, - draft=False, - prerelease=False, - ): - """ - Convenience function that calls :meth:`Repository.create_git_tag` and - :meth:`Repository.create_git_release`. - - :param tag: string - :param tag_message: string - :param release_name: string - :param release_message: string - :param object: string - :param type: string - :param tagger: :class:github.InputGitAuthor.InputGitAuthor - :param draft: bool - :param prerelease: bool - :rtype: :class:`github.GitRelease.GitRelease` - """ - self.create_git_tag(tag, tag_message, object, type, tagger) - return self.create_git_release( - tag, - release_name, - release_message, - draft, - prerelease, - target_commitish=object, - ) - - def create_git_release( - self, - tag, - name, - message, - draft=False, - prerelease=False, - target_commitish=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/{owner}/{repo}/releases `_ - :param tag: string - :param name: string - :param message: string - :param draft: bool - :param prerelease: bool - :param target_commitish: string or :class:`github.Branch.Branch` or :class:`github.Commit.Commit` or :class:`github.GitCommit.GitCommit` - :rtype: :class:`github.GitRelease.GitRelease` - """ - assert isinstance(tag, str), tag - assert isinstance(name, str), name - assert isinstance(message, str), message - assert isinstance(draft, bool), draft - assert isinstance(prerelease, bool), prerelease - assert target_commitish is github.GithubObject.NotSet or isinstance( - target_commitish, - ( - str, - github.Branch.Branch, - github.Commit.Commit, - github.GitCommit.GitCommit, - ), - ), target_commitish - post_parameters = { - "tag_name": tag, - "name": name, - "body": message, - "draft": draft, - "prerelease": prerelease, - } - if isinstance(target_commitish, str): - post_parameters["target_commitish"] = target_commitish - elif isinstance(target_commitish, github.Branch.Branch): - post_parameters["target_commitish"] = target_commitish.name - elif isinstance( - target_commitish, (github.Commit.Commit, github.GitCommit.GitCommit) - ): - post_parameters["target_commitish"] = target_commitish.sha - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/releases", input=post_parameters - ) - return github.GitRelease.GitRelease( - self._requester, headers, data, completed=True - ) - - def create_git_tag( - self, tag, message, object, type, tagger=github.GithubObject.NotSet - ): - """ - :calls: `POST /repos/{owner}/{repo}/git/tags `_ - :param tag: string - :param message: string - :param object: string - :param type: string - :param tagger: :class:`github.InputGitAuthor.InputGitAuthor` - :rtype: :class:`github.GitTag.GitTag` - """ - assert isinstance(tag, str), tag - assert isinstance(message, str), message - assert isinstance(object, str), object - assert isinstance(type, str), type - assert tagger is github.GithubObject.NotSet or isinstance( - tagger, github.InputGitAuthor - ), tagger - post_parameters = { - "tag": tag, - "message": message, - "object": object, - "type": type, - } - if tagger is not github.GithubObject.NotSet: - post_parameters["tagger"] = tagger._identity - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/git/tags", input=post_parameters - ) - return github.GitTag.GitTag(self._requester, headers, data, completed=True) - - def create_git_tree(self, tree, base_tree=github.GithubObject.NotSet): - """ - :calls: `POST /repos/{owner}/{repo}/git/trees `_ - :param tree: list of :class:`github.InputGitTreeElement.InputGitTreeElement` - :param base_tree: :class:`github.GitTree.GitTree` - :rtype: :class:`github.GitTree.GitTree` - """ - assert all( - isinstance(element, github.InputGitTreeElement) for element in tree - ), tree - assert base_tree is github.GithubObject.NotSet or isinstance( - base_tree, github.GitTree.GitTree - ), base_tree - post_parameters = { - "tree": [element._identity for element in tree], - } - if base_tree is not github.GithubObject.NotSet: - post_parameters["base_tree"] = base_tree._identity - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/git/trees", input=post_parameters - ) - return github.GitTree.GitTree(self._requester, headers, data, completed=True) - - def create_hook( - self, - name, - config, - events=github.GithubObject.NotSet, - active=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/{owner}/{repo}/hooks `_ - :param name: string - :param config: dict - :param events: list of string - :param active: bool - :rtype: :class:`github.Hook.Hook` - """ - assert isinstance(name, str), name - assert isinstance(config, dict), config - assert events is github.GithubObject.NotSet or all( - isinstance(element, str) for element in events - ), events - assert active is github.GithubObject.NotSet or isinstance(active, bool), active - post_parameters = { - "name": name, - "config": config, - } - if events is not github.GithubObject.NotSet: - post_parameters["events"] = events - if active is not github.GithubObject.NotSet: - post_parameters["active"] = active - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/hooks", input=post_parameters - ) - return github.Hook.Hook(self._requester, headers, data, completed=True) - - def create_issue( - self, - title, - body=github.GithubObject.NotSet, - assignee=github.GithubObject.NotSet, - milestone=github.GithubObject.NotSet, - labels=github.GithubObject.NotSet, - assignees=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/{owner}/{repo}/issues `_ - :param title: string - :param body: string - :param assignee: string or :class:`github.NamedUser.NamedUser` - :param assignees: list of string or :class:`github.NamedUser.NamedUser` - :param milestone: :class:`github.Milestone.Milestone` - :param labels: list of :class:`github.Label.Label` - :rtype: :class:`github.Issue.Issue` - """ - assert isinstance(title, str), title - assert body is github.GithubObject.NotSet or isinstance(body, str), body - assert ( - assignee is github.GithubObject.NotSet - or isinstance(assignee, github.NamedUser.NamedUser) - or isinstance(assignee, str) - ), assignee - assert assignees is github.GithubObject.NotSet or all( - isinstance(element, github.NamedUser.NamedUser) or isinstance(element, str) - for element in assignees - ), assignees - assert milestone is github.GithubObject.NotSet or isinstance( - milestone, github.Milestone.Milestone - ), milestone - assert labels is github.GithubObject.NotSet or all( - isinstance(element, github.Label.Label) or isinstance(element, str) - for element in labels - ), labels - - post_parameters = { - "title": title, - } - if body is not github.GithubObject.NotSet: - post_parameters["body"] = body - if assignee is not github.GithubObject.NotSet: - if isinstance(assignee, str): - post_parameters["assignee"] = assignee - else: - post_parameters["assignee"] = assignee._identity - if assignees is not github.GithubObject.NotSet: - post_parameters["assignees"] = [ - element._identity - if isinstance(element, github.NamedUser.NamedUser) - else element - for element in assignees - ] - if milestone is not github.GithubObject.NotSet: - post_parameters["milestone"] = milestone._identity - if labels is not github.GithubObject.NotSet: - post_parameters["labels"] = [ - element.name if isinstance(element, github.Label.Label) else element - for element in labels - ] - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/issues", input=post_parameters - ) - return github.Issue.Issue(self._requester, headers, data, completed=True) - - def create_key(self, title, key, read_only=False): - """ - :calls: `POST /repos/{owner}/{repo}/keys `_ - :param title: string - :param key: string - :param read_only: bool - :rtype: :class:`github.RepositoryKey.RepositoryKey` - """ - assert isinstance(title, str), title - assert isinstance(key, str), key - assert isinstance(read_only, bool), read_only - post_parameters = { - "title": title, - "key": key, - "read_only": read_only, - } - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/keys", input=post_parameters - ) - return github.RepositoryKey.RepositoryKey( - self._requester, headers, data, completed=True - ) - - def create_label(self, name, color, description=github.GithubObject.NotSet): - """ - :calls: `POST /repos/{owner}/{repo}/labels `_ - :param name: string - :param color: string - :param description: string - :rtype: :class:`github.Label.Label` - """ - assert isinstance(name, str), name - assert isinstance(color, str), color - assert description is github.GithubObject.NotSet or isinstance( - description, str - ), description - post_parameters = { - "name": name, - "color": color, - } - if description is not github.GithubObject.NotSet: - post_parameters["description"] = description - headers, data = self._requester.requestJsonAndCheck( - "POST", - f"{self.url}/labels", - input=post_parameters, - headers={"Accept": Consts.mediaTypeLabelDescriptionSearchPreview}, - ) - return github.Label.Label(self._requester, headers, data, completed=True) - - def create_milestone( - self, - title, - state=github.GithubObject.NotSet, - description=github.GithubObject.NotSet, - due_on=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/{owner}/{repo}/milestones `_ - :param title: string - :param state: string - :param description: string - :param due_on: datetime - :rtype: :class:`github.Milestone.Milestone` - """ - assert isinstance(title, str), title - assert state is github.GithubObject.NotSet or isinstance(state, str), state - assert description is github.GithubObject.NotSet or isinstance( - description, str - ), description - assert due_on is github.GithubObject.NotSet or isinstance( - due_on, (datetime.datetime, datetime.date) - ), due_on - post_parameters = { - "title": title, - } - if state is not github.GithubObject.NotSet: - post_parameters["state"] = state - if description is not github.GithubObject.NotSet: - post_parameters["description"] = description - if due_on is not github.GithubObject.NotSet: - if isinstance(due_on, datetime.date): - post_parameters["due_on"] = due_on.strftime("%Y-%m-%dT%H:%M:%SZ") - else: - post_parameters["due_on"] = due_on.isoformat() - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/milestones", input=post_parameters - ) - return github.Milestone.Milestone( - self._requester, headers, data, completed=True - ) - - def create_project(self, name, body=github.GithubObject.NotSet): - """ - :calls: `POST /repos/{owner}/{repo}/projects `_ - :param name: string - :param body: string - :rtype: :class:`github.Project.Project` - """ - assert isinstance(name, str), name - assert body is github.GithubObject.NotSet or isinstance(body, str), body - post_parameters = { - "name": name, - } - import_header = {"Accept": Consts.mediaTypeProjectsPreview} - if body is not github.GithubObject.NotSet: - post_parameters["body"] = body - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/projects", headers=import_header, input=post_parameters - ) - return github.Project.Project(self._requester, headers, data, completed=True) - - def create_pull(self, *args, **kwds): - """ - :calls: `POST /repos/{owner}/{repo}/pulls `_ - :param title: string - :param body: string - :param issue: :class:`github.Issue.Issue` - :param base: string - :param head: string - :param draft: bool - :param maintainer_can_modify: bool - :rtype: :class:`github.PullRequest.PullRequest` - """ - if len(args) + len(kwds) >= 4: - return self.__create_pull_1(*args, **kwds) - else: - return self.__create_pull_2(*args, **kwds) - - def __create_pull_1( - self, - title, - body, - base, - head, - maintainer_can_modify=github.GithubObject.NotSet, - draft=False, - ): - assert isinstance(title, str), title - assert isinstance(body, str), body - assert isinstance(base, str), base - assert isinstance(head, str), head - assert maintainer_can_modify is github.GithubObject.NotSet or isinstance( - maintainer_can_modify, bool - ), maintainer_can_modify - assert isinstance(draft, bool), draft - if maintainer_can_modify is not github.GithubObject.NotSet: - return self.__create_pull( - title=title, - body=body, - base=base, - head=head, - maintainer_can_modify=maintainer_can_modify, - draft=draft, - ) - else: - return self.__create_pull( - title=title, body=body, base=base, head=head, draft=draft - ) - - def __create_pull_2(self, issue, base, head): - assert isinstance(issue, github.Issue.Issue), issue - assert isinstance(base, str), base - assert isinstance(head, str), head - return self.__create_pull(issue=issue._identity, base=base, head=head) - - def __create_pull(self, **kwds): - post_parameters = kwds - - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/pulls", input=post_parameters - ) - return github.PullRequest.PullRequest( - self._requester, headers, data, completed=True - ) - - def create_repository_dispatch( - self, event_type, client_payload=github.GithubObject.NotSet - ): - """ - :calls: POST /repos/{owner}/{repo}/dispatches - :param event_type: string - :param client_payload: dict - :rtype: bool - """ - assert isinstance(event_type, str), event_type - assert client_payload is github.GithubObject.NotSet or isinstance( - client_payload, dict - ), client_payload - post_parameters = {"event_type": event_type} - if client_payload is not github.GithubObject.NotSet: - post_parameters["client_payload"] = client_payload - status, headers, data = self._requester.requestJson( - "POST", f"{self.url}/dispatches", input=post_parameters - ) - return status == 204 - - def create_secret(self, secret_name, unencrypted_value): - """ - :calls: `PUT /repos/{owner}/{repo}/actions/secrets/{secret_name} `_ - :param secret_name: string - :param unencrypted_value: string - :rtype: bool - """ - assert isinstance(secret_name, str), secret_name - assert isinstance(unencrypted_value, str), unencrypted_value - public_key = self.get_public_key() - payload = public_key.encrypt(unencrypted_value) - put_parameters = { - "key_id": public_key.key_id, - "encrypted_value": payload, - } - status, headers, data = self._requester.requestJson( - "PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters - ) - return status == 201 - - def delete_secret(self, secret_name): - """ - :calls: `DELETE /repos/{owner}/{repo}/actions/secrets/{secret_name} `_ - :param secret_name: string - :rtype: bool - """ - assert isinstance(secret_name, str), secret_name - status, headers, data = self._requester.requestJson( - "DELETE", f"{self.url}/actions/secrets/{secret_name}" - ) - return status == 204 - - def create_source_import( - self, - vcs, - vcs_url, - vcs_username=github.GithubObject.NotSet, - vcs_password=github.GithubObject.NotSet, - ): - """ - :calls: `PUT /repos/{owner}/{repo}/import `_ - :param vcs: string - :param vcs_url: string - :param vcs_username: string - :param vcs_password: string - :rtype: :class:`github.SourceImport.SourceImport` - """ - assert isinstance(vcs, str), vcs - assert isinstance(vcs_url, str), vcs_url - assert vcs_username is github.GithubObject.NotSet or isinstance( - vcs_username, str - ), vcs_username - assert vcs_password is github.GithubObject.NotSet or isinstance( - vcs_password, str - ), vcs_password - put_parameters = {"vcs": vcs, "vcs_url": vcs_url} - - if vcs_username is not github.GithubObject.NotSet: - put_parameters["vcs_username"] = vcs_username - - if vcs_password is not github.GithubObject.NotSet: - put_parameters["vcs_password"] = vcs_password - - import_header = {"Accept": Consts.mediaTypeImportPreview} - - headers, data = self._requester.requestJsonAndCheck( - "PUT", f"{self.url}/import", headers=import_header, input=put_parameters - ) - - return github.SourceImport.SourceImport( - self._requester, headers, data, completed=False - ) - - def delete(self): - """ - :calls: `DELETE /repos/{owner}/{repo} `_ - :rtype: None - """ - headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) - - def edit( - self, - name=None, - description=github.GithubObject.NotSet, - homepage=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, - has_issues=github.GithubObject.NotSet, - has_projects=github.GithubObject.NotSet, - has_wiki=github.GithubObject.NotSet, - has_downloads=github.GithubObject.NotSet, - default_branch=github.GithubObject.NotSet, - allow_squash_merge=github.GithubObject.NotSet, - allow_merge_commit=github.GithubObject.NotSet, - allow_rebase_merge=github.GithubObject.NotSet, - delete_branch_on_merge=github.GithubObject.NotSet, - archived=github.GithubObject.NotSet, - ): - """ - :calls: `PATCH /repos/{owner}/{repo} `_ - :param name: string - :param description: string - :param homepage: string - :param private: bool - :param has_issues: bool - :param has_projects: bool - :param has_wiki: bool - :param has_downloads: bool - :param default_branch: string - :param allow_squash_merge: bool - :param allow_merge_commit: bool - :param allow_rebase_merge: bool - :param delete_branch_on_merge: bool - :param archived: bool. Unarchiving repositories is currently not supported through API (https://docs.github.com/en/rest/reference/repos#edit) - :rtype: None - """ - if name is None: - name = self.name - assert isinstance(name, str), name - assert description is github.GithubObject.NotSet or isinstance( - description, str - ), description - assert homepage is github.GithubObject.NotSet or isinstance( - homepage, str - ), homepage - assert private is github.GithubObject.NotSet or isinstance( - private, bool - ), private - assert has_issues is github.GithubObject.NotSet or isinstance( - has_issues, bool - ), has_issues - assert has_projects is github.GithubObject.NotSet or isinstance( - has_projects, bool - ), has_projects - assert has_wiki is github.GithubObject.NotSet or isinstance( - has_wiki, bool - ), has_wiki - assert has_downloads is github.GithubObject.NotSet or isinstance( - has_downloads, bool - ), has_downloads - assert default_branch is github.GithubObject.NotSet or isinstance( - default_branch, str - ), default_branch - assert allow_squash_merge is github.GithubObject.NotSet or isinstance( - allow_squash_merge, bool - ), allow_squash_merge - assert allow_merge_commit is github.GithubObject.NotSet or isinstance( - allow_merge_commit, bool - ), allow_merge_commit - assert allow_rebase_merge is github.GithubObject.NotSet or isinstance( - allow_rebase_merge, bool - ), allow_rebase_merge - assert delete_branch_on_merge is github.GithubObject.NotSet or isinstance( - delete_branch_on_merge, bool - ), delete_branch_on_merge - assert archived is github.GithubObject.NotSet or ( - isinstance(archived, bool) and archived is True - ), archived - post_parameters = { - "name": name, - } - if description is not github.GithubObject.NotSet: - post_parameters["description"] = description - if homepage is not github.GithubObject.NotSet: - post_parameters["homepage"] = homepage - if private is not github.GithubObject.NotSet: - post_parameters["private"] = private - if has_issues is not github.GithubObject.NotSet: - post_parameters["has_issues"] = has_issues - if has_projects is not github.GithubObject.NotSet: - post_parameters["has_projects"] = has_projects - if has_wiki is not github.GithubObject.NotSet: - post_parameters["has_wiki"] = has_wiki - if has_downloads is not github.GithubObject.NotSet: - post_parameters["has_downloads"] = has_downloads - if default_branch is not github.GithubObject.NotSet: - post_parameters["default_branch"] = default_branch - if allow_squash_merge is not github.GithubObject.NotSet: - post_parameters["allow_squash_merge"] = allow_squash_merge - if allow_merge_commit is not github.GithubObject.NotSet: - post_parameters["allow_merge_commit"] = allow_merge_commit - if allow_rebase_merge is not github.GithubObject.NotSet: - post_parameters["allow_rebase_merge"] = allow_rebase_merge - if delete_branch_on_merge is not github.GithubObject.NotSet: - post_parameters["delete_branch_on_merge"] = delete_branch_on_merge - if archived is not github.GithubObject.NotSet: - post_parameters["archived"] = archived - headers, data = self._requester.requestJsonAndCheck( - "PATCH", self.url, input=post_parameters - ) - self._useAttributes(data) - - def get_archive_link(self, archive_format, ref=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/{archive_format}/{ref} `_ - :param archive_format: string - :param ref: string - :rtype: string - """ - assert isinstance(archive_format, str), archive_format - assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref - url = f"{self.url}/{archive_format}" - if ref is not github.GithubObject.NotSet: - url += f"/{ref}" - headers, data = self._requester.requestJsonAndCheck("GET", url) - return headers["location"] - - def get_assignees(self): - """ - :calls: `GET /repos/{owner}/{repo}/assignees `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, f"{self.url}/assignees", None - ) - - def get_branch(self, branch): - """ - :calls: `GET /repos/{owner}/{repo}/branches/{branch} `_ - :param branch: string - :rtype: :class:`github.Branch.Branch` - """ - assert isinstance(branch, str), branch - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/branches/{branch}" - ) - return github.Branch.Branch(self._requester, headers, data, completed=True) - - def get_branches(self): - """ - :calls: `GET /repos/{owner}/{repo}/branches `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Branch.Branch` - """ - return github.PaginatedList.PaginatedList( - github.Branch.Branch, self._requester, f"{self.url}/branches", None - ) - - def get_collaborators(self, affiliation=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/collaborators `_ - :param affiliation: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - - url_parameters = dict() - allowed_affiliations = ["outside", "direct", "all"] - if affiliation is not github.GithubObject.NotSet: - assert isinstance(affiliation, str), affiliation - assert ( - affiliation in allowed_affiliations - ), f"Affiliation can be one of {', '.join(allowed_affiliations)}" - url_parameters["affiliation"] = affiliation - - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - f"{self.url}/collaborators", - url_parameters, - ) - - def get_comment(self, id): - """ - :calls: `GET /repos/{owner}/{repo}/comments/{id} `_ - :param id: integer - :rtype: :class:`github.CommitComment.CommitComment` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/comments/{id}" - ) - return github.CommitComment.CommitComment( - self._requester, headers, data, completed=True - ) - - def get_comments(self): - """ - :calls: `GET /repos/{owner}/{repo}/comments `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CommitComment.CommitComment` - """ - return github.PaginatedList.PaginatedList( - github.CommitComment.CommitComment, - self._requester, - f"{self.url}/comments", - None, - ) - - def get_commit(self, sha): - """ - :calls: `GET /repos/{owner}/{repo}/commits/{sha} `_ - :param sha: string - :rtype: :class:`github.Commit.Commit` - """ - assert isinstance(sha, str), sha - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/commits/{sha}" - ) - return github.Commit.Commit(self._requester, headers, data, completed=True) - - def get_commits( - self, - sha=github.GithubObject.NotSet, - path=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - until=github.GithubObject.NotSet, - author=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/commits `_ - :param sha: string - :param path: string - :param since: datetime.datetime - :param until: datetime.datetime - :param author: string or :class:`github.NamedUser.NamedUser` or :class:`github.AuthenticatedUser.AuthenticatedUser` - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit` - """ - assert sha is github.GithubObject.NotSet or isinstance(sha, str), sha - assert path is github.GithubObject.NotSet or isinstance(path, str), path - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - assert until is github.GithubObject.NotSet or isinstance( - until, datetime.datetime - ), until - assert author is github.GithubObject.NotSet or isinstance( - author, - ( - str, - github.NamedUser.NamedUser, - github.AuthenticatedUser.AuthenticatedUser, - ), - ), author - url_parameters = dict() - if sha is not github.GithubObject.NotSet: - url_parameters["sha"] = sha - if path is not github.GithubObject.NotSet: - url_parameters["path"] = path - if since is not github.GithubObject.NotSet: - url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - if until is not github.GithubObject.NotSet: - url_parameters["until"] = until.strftime("%Y-%m-%dT%H:%M:%SZ") - if author is not github.GithubObject.NotSet: - if isinstance( - author, - ( - github.NamedUser.NamedUser, - github.AuthenticatedUser.AuthenticatedUser, - ), - ): - url_parameters["author"] = author.login - else: - url_parameters["author"] = author - return github.PaginatedList.PaginatedList( - github.Commit.Commit, self._requester, f"{self.url}/commits", url_parameters - ) - - def get_contents(self, path, ref=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/contents/{path} `_ - :param path: string - :param ref: string - :rtype: :class:`github.ContentFile.ContentFile` or a list of them - """ - assert isinstance(path, str), path - assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref - # Path of '/' should be the empty string. - if path == "/": - path = "" - url_parameters = dict() - if ref is not github.GithubObject.NotSet: - url_parameters["ref"] = ref - headers, data = self._requester.requestJsonAndCheck( - "GET", - f"{self.url}/contents/{urllib.parse.quote(path)}", - parameters=url_parameters, - ) - - # Handle 302 redirect response - if headers.get("status") == "302 Found" and headers.get("location"): - headers, data = self._requester.requestJsonAndCheck( - "GET", headers["location"], parameters=url_parameters - ) - - if isinstance(data, list): - return [ - # Lazy completion only makes sense for files. See discussion - # here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130 - github.ContentFile.ContentFile( - self._requester, headers, item, completed=(item["type"] != "file") - ) - for item in data - ] - return github.ContentFile.ContentFile( - self._requester, headers, data, completed=True - ) - - def get_deployments( - self, - sha=github.GithubObject.NotSet, - ref=github.GithubObject.NotSet, - task=github.GithubObject.NotSet, - environment=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/deployments `_ - :param: sha: string - :param: ref: string - :param: task: string - :param: environment: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Deployment.Deployment` - """ - assert sha is github.GithubObject.NotSet or isinstance(sha, str), sha - assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref - assert task is github.GithubObject.NotSet or isinstance(task, str), task - assert environment is github.GithubObject.NotSet or isinstance( - environment, str - ), environment - parameters = {} - if sha is not github.GithubObject.NotSet: - parameters["sha"] = sha - if ref is not github.GithubObject.NotSet: - parameters["ref"] = ref - if task is not github.GithubObject.NotSet: - parameters["task"] = task - if environment is not github.GithubObject.NotSet: - parameters["environment"] = environment - return github.PaginatedList.PaginatedList( - github.Deployment.Deployment, - self._requester, - f"{self.url}/deployments", - parameters, - headers={"Accept": Consts.deploymentEnhancementsPreview}, - ) - - def get_deployment(self, id_): - """ - :calls: `GET /repos/{owner}/{repo}/deployments/{deployment_id} `_ - :param: id_: int - :rtype: :class:`github.Deployment.Deployment` - """ - assert isinstance(id_, int), id_ - headers, data = self._requester.requestJsonAndCheck( - "GET", - f"{self.url}/deployments/{id_}", - headers={"Accept": Consts.deploymentEnhancementsPreview}, - ) - return github.Deployment.Deployment( - self._requester, headers, data, completed=True - ) - - def create_deployment( - self, - ref, - task=github.GithubObject.NotSet, - auto_merge=github.GithubObject.NotSet, - required_contexts=github.GithubObject.NotSet, - payload=github.GithubObject.NotSet, - environment=github.GithubObject.NotSet, - description=github.GithubObject.NotSet, - transient_environment=github.GithubObject.NotSet, - production_environment=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/{owner}/{repo}/deployments `_ - :param: ref: string - :param: task: string - :param: auto_merge: bool - :param: required_contexts: list of status contexts - :param: payload: dict - :param: environment: string - :param: description: string - :param: transient_environment: bool - :param: production_environment: bool - :rtype: :class:`github.Deployment.Deployment` - """ - assert isinstance(ref, str), ref - assert task is github.GithubObject.NotSet or isinstance(task, str), task - assert auto_merge is github.GithubObject.NotSet or isinstance( - auto_merge, bool - ), auto_merge - assert required_contexts is github.GithubObject.NotSet or isinstance( - required_contexts, list - ), required_contexts # need to do better checking here - assert payload is github.GithubObject.NotSet or isinstance( - payload, dict - ), payload - assert environment is github.GithubObject.NotSet or isinstance( - environment, str - ), environment - assert description is github.GithubObject.NotSet or isinstance( - description, str - ), description - assert transient_environment is github.GithubObject.NotSet or isinstance( - transient_environment, bool - ), transient_environment - assert production_environment is github.GithubObject.NotSet or isinstance( - production_environment, bool - ), production_environment - - post_parameters = {"ref": ref} - if task is not github.GithubObject.NotSet: - post_parameters["task"] = task - if auto_merge is not github.GithubObject.NotSet: - post_parameters["auto_merge"] = auto_merge - if required_contexts is not github.GithubObject.NotSet: - post_parameters["required_contexts"] = required_contexts - if payload is not github.GithubObject.NotSet: - post_parameters["payload"] = payload - if environment is not github.GithubObject.NotSet: - post_parameters["environment"] = environment - if description is not github.GithubObject.NotSet: - post_parameters["description"] = description - if transient_environment is not github.GithubObject.NotSet: - post_parameters["transient_environment"] = transient_environment - if production_environment is not github.GithubObject.NotSet: - post_parameters["production_environment"] = production_environment - - headers, data = self._requester.requestJsonAndCheck( - "POST", - f"{self.url}/deployments", - input=post_parameters, - headers={"Accept": Consts.deploymentEnhancementsPreview}, - ) - - return github.Deployment.Deployment( - self._requester, headers, data, completed=True - ) - - def get_top_referrers(self): - """ - :calls: `GET /repos/{owner}/{repo}/traffic/popular/referrers `_ - :rtype: :class:`list` of :class:`github.Referrer.Referrer` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/traffic/popular/referrers" - ) - if isinstance(data, list): - return [ - github.Referrer.Referrer(self._requester, headers, item, completed=True) - for item in data - ] - - def get_top_paths(self): - """ - :calls: `GET /repos/{owner}/{repo}/traffic/popular/paths `_ - :rtype: :class:`list` of :class:`github.Path.Path` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/traffic/popular/paths" - ) - if isinstance(data, list): - return [ - github.Path.Path(self._requester, headers, item, completed=True) - for item in data - ] - - def get_views_traffic(self, per=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/traffic/views `_ - :param per: string, must be one of day or week, day by default - :rtype: None or list of :class:`github.View.View` - """ - assert per is github.GithubObject.NotSet or ( - isinstance(per, str) and (per == "day" or per == "week") - ), "per must be day or week, day by default" - url_parameters = dict() - if per is not github.GithubObject.NotSet: - url_parameters["per"] = per - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/traffic/views", parameters=url_parameters - ) - if ( - (isinstance(data, dict)) - and ("views" in data) - and (isinstance(data["views"], list)) - ): - data["views"] = [ - github.View.View(self._requester, headers, item, completed=True) - for item in data["views"] - ] - return data - - def get_clones_traffic(self, per=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/traffic/clones `_ - :param per: string, must be one of day or week, day by default - :rtype: None or list of :class:`github.Clones.Clones` - """ - assert per is github.GithubObject.NotSet or ( - isinstance(per, str) and (per == "day" or per == "week") - ), "per must be day or week, day by default" - url_parameters = dict() - if per is not github.GithubObject.NotSet: - url_parameters["per"] = per - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/traffic/clones", parameters=url_parameters - ) - if ( - (isinstance(data, dict)) - and ("clones" in data) - and (isinstance(data["clones"], list)) - ): - data["clones"] = [ - github.Clones.Clones(self._requester, headers, item, completed=True) - for item in data["clones"] - ] - return data - - def get_projects(self, state=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/projects `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Project.Project` - :param state: string - """ - - url_parameters = dict() - if state is not github.GithubObject.NotSet: - url_parameters["state"] = state - - return github.PaginatedList.PaginatedList( - github.Project.Project, - self._requester, - f"{self.url}/projects", - url_parameters, - {"Accept": Consts.mediaTypeProjectsPreview}, - ) - - def create_file( - self, - path, - message, - content, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet, - ): - """Create a file in this repository. - - :calls: `PUT /repos/{owner}/{repo}/contents/{path} `_ - :param path: string, (required), path of the file in the repository - :param message: string, (required), commit message - :param content: string, (required), the actual data in the file - :param branch: string, (optional), branch to create the commit on. Defaults to the default branch of the repository - :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. - :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. - :rtype: { - 'content': :class:`ContentFile `:, - 'commit': :class:`Commit `} - """ - assert isinstance(path, str) - assert isinstance(message, str) - assert isinstance(content, (str, bytes)) - assert branch is github.GithubObject.NotSet or isinstance(branch, str) - assert author is github.GithubObject.NotSet or isinstance( - author, github.InputGitAuthor - ) - assert committer is github.GithubObject.NotSet or isinstance( - committer, github.InputGitAuthor - ) - - if not isinstance(content, bytes): - content = content.encode("utf-8") - content = b64encode(content).decode("utf-8") - put_parameters = {"message": message, "content": content} - - if branch is not github.GithubObject.NotSet: - put_parameters["branch"] = branch - if author is not github.GithubObject.NotSet: - put_parameters["author"] = author._identity - if committer is not github.GithubObject.NotSet: - put_parameters["committer"] = committer._identity - - headers, data = self._requester.requestJsonAndCheck( - "PUT", - f"{self.url}/contents/{urllib.parse.quote(path)}", - input=put_parameters, - ) - - return { - "content": github.ContentFile.ContentFile( - self._requester, headers, data["content"], completed=False - ), - "commit": github.Commit.Commit( - self._requester, headers, data["commit"], completed=True - ), - } - - def update_file( - self, - path, - message, - content, - sha, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet, - ): - """This method updates a file in a repository - - :calls: `PUT /repos/{owner}/{repo}/contents/{path} `_ - :param path: string, Required. The content path. - :param message: string, Required. The commit message. - :param content: string, Required. The updated file content, either base64 encoded, or ready to be encoded. - :param sha: string, Required. The blob SHA of the file being replaced. - :param branch: string. The branch name. Default: the repository’s default branch (usually master) - :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. - :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. - :rtype: { - 'content': :class:`ContentFile `:, - 'commit': :class:`Commit `} - """ - assert isinstance(path, str) - assert isinstance(message, str) - assert isinstance(content, (str, bytes)) - assert isinstance(sha, str) - assert branch is github.GithubObject.NotSet or isinstance(branch, str) - assert author is github.GithubObject.NotSet or isinstance( - author, github.InputGitAuthor - ) - assert committer is github.GithubObject.NotSet or isinstance( - committer, github.InputGitAuthor - ) - - if not isinstance(content, bytes): - content = content.encode("utf-8") - content = b64encode(content).decode("utf-8") - - put_parameters = {"message": message, "content": content, "sha": sha} - - if branch is not github.GithubObject.NotSet: - put_parameters["branch"] = branch - if author is not github.GithubObject.NotSet: - put_parameters["author"] = author._identity - if committer is not github.GithubObject.NotSet: - put_parameters["committer"] = committer._identity - - headers, data = self._requester.requestJsonAndCheck( - "PUT", - f"{self.url}/contents/{urllib.parse.quote(path)}", - input=put_parameters, - ) - - return { - "commit": github.Commit.Commit( - self._requester, headers, data["commit"], completed=True - ), - "content": github.ContentFile.ContentFile( - self._requester, headers, data["content"], completed=False - ), - } - - def delete_file( - self, - path, - message, - sha, - branch=github.GithubObject.NotSet, - committer=github.GithubObject.NotSet, - author=github.GithubObject.NotSet, - ): - """This method deletes a file in a repository - - :calls: `DELETE /repos/{owner}/{repo}/contents/{path} `_ - :param path: string, Required. The content path. - :param message: string, Required. The commit message. - :param sha: string, Required. The blob SHA of the file being replaced. - :param branch: string. The branch name. Default: the repository’s default branch (usually master) - :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. - :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. - :rtype: { - 'content': :class:`null `:, - 'commit': :class:`Commit `} - """ - assert isinstance(path, str), "path must be str/unicode object" - assert isinstance(message, str), "message must be str/unicode object" - assert isinstance(sha, str), "sha must be a str/unicode object" - assert branch is github.GithubObject.NotSet or isinstance( - branch, str - ), "branch must be a str/unicode object" - assert author is github.GithubObject.NotSet or isinstance( - author, github.InputGitAuthor - ), "author must be a github.InputGitAuthor object" - assert committer is github.GithubObject.NotSet or isinstance( - committer, github.InputGitAuthor - ), "committer must be a github.InputGitAuthor object" - - url_parameters = {"message": message, "sha": sha} - if branch is not github.GithubObject.NotSet: - url_parameters["branch"] = branch - if author is not github.GithubObject.NotSet: - url_parameters["author"] = author._identity - if committer is not github.GithubObject.NotSet: - url_parameters["committer"] = committer._identity - - headers, data = self._requester.requestJsonAndCheck( - "DELETE", - f"{self.url}/contents/{urllib.parse.quote(path)}", - input=url_parameters, - ) - - return { - "commit": github.Commit.Commit( - self._requester, headers, data["commit"], completed=True - ), - "content": github.GithubObject.NotSet, - } - - @deprecated( - reason=""" - Repository.get_dir_contents() is deprecated, use - Repository.get_contents() instead. - """ - ) - def get_dir_contents(self, path, ref=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/contents/{path} `_ - :param path: string - :param ref: string - :rtype: list of :class:`github.ContentFile.ContentFile` - """ - return self.get_contents(path, ref=ref) - - def get_contributors(self, anon=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/contributors `_ - :param anon: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - url_parameters = dict() - if anon is not github.GithubObject.NotSet: - url_parameters["anon"] = anon - - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, - self._requester, - f"{self.url}/contributors", - url_parameters, - ) - - def get_download(self, id): - """ - :calls: `GET /repos/{owner}/{repo}/downloads/{id} `_ - :param id: integer - :rtype: :class:`github.Download.Download` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/downloads/{id}" - ) - return github.Download.Download(self._requester, headers, data, completed=True) - - def get_downloads(self): - """ - :calls: `GET /repos/{owner}/{repo}/downloads `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Download.Download` - """ - return github.PaginatedList.PaginatedList( - github.Download.Download, self._requester, f"{self.url}/downloads", None - ) - - def get_events(self): - """ - :calls: `GET /repos/{owner}/{repo}/events `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` - """ - return github.PaginatedList.PaginatedList( - github.Event.Event, self._requester, f"{self.url}/events", None - ) - - def get_forks(self): - """ - :calls: `GET /repos/{owner}/{repo}/forks `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` - """ - return github.PaginatedList.PaginatedList( - Repository, self._requester, f"{self.url}/forks", None - ) - - def create_fork(self, organization=github.GithubObject.NotSet): - """ - :calls: `POST /repos/{owner}/{repo}/forks `_ - :param organization: string or "none" or "*" - :rtype: :class:`github.Repository.Repository` - """ - assert organization is github.GithubObject.NotSet or isinstance( - organization, str - ), organization - post_parameters = {} - if organization is not github.GithubObject.NotSet: - post_parameters["organization"] = organization - headers, data = self._requester.requestJsonAndCheck( - "POST", - f"{self.url}/forks", - input=post_parameters, - ) - return Repository(self._requester, headers, data, completed=True) - - def get_git_blob(self, sha): - """ - :calls: `GET /repos/{owner}/{repo}/git/blobs/{sha} `_ - :param sha: string - :rtype: :class:`github.GitBlob.GitBlob` - """ - assert isinstance(sha, str), sha - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/git/blobs/{sha}" - ) - return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) - - def get_git_commit(self, sha): - """ - :calls: `GET /repos/{owner}/{repo}/git/commits/{sha} `_ - :param sha: string - :rtype: :class:`github.GitCommit.GitCommit` - """ - assert isinstance(sha, str), sha - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/git/commits/{sha}" - ) - return github.GitCommit.GitCommit( - self._requester, headers, data, completed=True - ) - - def get_git_ref(self, ref): - """ - :calls: `GET /repos/{owner}/{repo}/git/refs/{ref} `_ - :param ref: string - :rtype: :class:`github.GitRef.GitRef` - """ - prefix = "/git/refs/" - if not self._requester.FIX_REPO_GET_GIT_REF: - prefix = "/git/" - assert isinstance(ref, str), ref - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}{prefix}{ref}" - ) - return github.GitRef.GitRef(self._requester, headers, data, completed=True) - - def get_git_refs(self): - """ - :calls: `GET /repos/{owner}/{repo}/git/refs `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRef.GitRef` - """ - return github.PaginatedList.PaginatedList( - github.GitRef.GitRef, self._requester, f"{self.url}/git/refs", None - ) - - def get_git_matching_refs(self, ref): - """ - :calls: `GET /repos/{owner}/{repo}/git/matching-refs/{ref} ` - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRef.GitRef` - """ - assert isinstance(ref, str), ref - return github.PaginatedList.PaginatedList( - github.GitRef.GitRef, - self._requester, - f"{self.url}/git/matching-refs/{ref}", - None, - ) - - def get_git_tag(self, sha): - """ - :calls: `GET /repos/{owner}/{repo}/git/tags/{sha} `_ - :param sha: string - :rtype: :class:`github.GitTag.GitTag` - """ - assert isinstance(sha, str), sha - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/git/tags/{sha}" - ) - return github.GitTag.GitTag(self._requester, headers, data, completed=True) - - def get_git_tree(self, sha, recursive=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/git/trees/{sha} `_ - :param sha: string - :param recursive: bool - :rtype: :class:`github.GitTree.GitTree` - """ - assert isinstance(sha, str), sha - assert recursive is github.GithubObject.NotSet or isinstance( - recursive, bool - ), recursive - url_parameters = dict() - if recursive is not github.GithubObject.NotSet and recursive: - # GitHub API requires the recursive parameter be set to 1. - url_parameters["recursive"] = 1 - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/git/trees/{sha}", parameters=url_parameters - ) - return github.GitTree.GitTree(self._requester, headers, data, completed=True) - - def get_hook(self, id): - """ - :calls: `GET /repos/{owner}/{repo}/hooks/{id} `_ - :param id: integer - :rtype: :class:`github.Hook.Hook` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/hooks/{id}" - ) - return github.Hook.Hook(self._requester, headers, data, completed=True) - - def get_hooks(self): - """ - :calls: `GET /repos/{owner}/{repo}/hooks `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook` - """ - return github.PaginatedList.PaginatedList( - github.Hook.Hook, self._requester, f"{self.url}/hooks", None - ) - - def get_issue(self, number): - """ - :calls: `GET /repos/{owner}/{repo}/issues/{number} `_ - :param number: integer - :rtype: :class:`github.Issue.Issue` - """ - assert isinstance(number, int), number - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/issues/{number}" - ) - return github.Issue.Issue(self._requester, headers, data, completed=True) - - def get_issues( - self, - milestone=github.GithubObject.NotSet, - state=github.GithubObject.NotSet, - assignee=github.GithubObject.NotSet, - mentioned=github.GithubObject.NotSet, - labels=github.GithubObject.NotSet, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - creator=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/issues `_ - :param milestone: :class:`github.Milestone.Milestone` or "none" or "*" - :param state: string. `open`, `closed`, or `all`. If this is not set the GitHub API default behavior will be used. At the moment this is to return only open issues. This might change anytime on GitHub API side and it could be clever to explicitly specify the state value. - :param assignee: string or :class:`github.NamedUser.NamedUser` or "none" or "*" - :param mentioned: :class:`github.NamedUser.NamedUser` - :param labels: list of string or :class:`github.Label.Label` - :param sort: string - :param direction: string - :param since: datetime.datetime - :param creator: string or :class:`github.NamedUser.NamedUser` - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` - """ - assert ( - milestone is github.GithubObject.NotSet - or milestone == "*" - or milestone == "none" - or isinstance(milestone, github.Milestone.Milestone) - ), milestone - assert state is github.GithubObject.NotSet or isinstance(state, str), state - assert ( - assignee is github.GithubObject.NotSet - or isinstance(assignee, github.NamedUser.NamedUser) - or isinstance(assignee, str) - ), assignee - assert mentioned is github.GithubObject.NotSet or isinstance( - mentioned, github.NamedUser.NamedUser - ), mentioned - assert labels is github.GithubObject.NotSet or all( - isinstance(element, github.Label.Label) or isinstance(element, str) - for element in labels - ), labels - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - assert ( - creator is github.GithubObject.NotSet - or isinstance(creator, github.NamedUser.NamedUser) - or isinstance(creator, str) - ), creator - url_parameters = dict() - if milestone is not github.GithubObject.NotSet: - if isinstance(milestone, str): - url_parameters["milestone"] = milestone - else: - url_parameters["milestone"] = milestone._identity - if state is not github.GithubObject.NotSet: - url_parameters["state"] = state - if assignee is not github.GithubObject.NotSet: - if isinstance(assignee, str): - url_parameters["assignee"] = assignee - else: - url_parameters["assignee"] = assignee._identity - if mentioned is not github.GithubObject.NotSet: - url_parameters["mentioned"] = mentioned._identity - if labels is not github.GithubObject.NotSet: - url_parameters["labels"] = ",".join( - [ - label.name if isinstance(label, github.Label.Label) else label - for label in labels - ] - ) - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - if since is not github.GithubObject.NotSet: - url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - if creator is not github.GithubObject.NotSet: - if isinstance(creator, str): - url_parameters["creator"] = creator - else: - url_parameters["creator"] = creator._identity - return github.PaginatedList.PaginatedList( - github.Issue.Issue, self._requester, f"{self.url}/issues", url_parameters - ) - - def get_issues_comments( - self, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/issues/comments `_ - :param sort: string - :param direction: string - :param since: datetime.datetime - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment` - """ - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - url_parameters = dict() - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - if since is not github.GithubObject.NotSet: - url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - return github.PaginatedList.PaginatedList( - github.IssueComment.IssueComment, - self._requester, - f"{self.url}/issues/comments", - url_parameters, - ) - - def get_issues_event(self, id): - """ - :calls: `GET /repos/{owner}/{repo}/issues/events/{id} `_ - :param id: integer - :rtype: :class:`github.IssueEvent.IssueEvent` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", - f"{self.url}/issues/events/{id}", - headers={"Accept": Consts.mediaTypeLockReasonPreview}, - ) - return github.IssueEvent.IssueEvent( - self._requester, headers, data, completed=True - ) - - def get_issues_events(self): - """ - :calls: `GET /repos/{owner}/{repo}/issues/events `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueEvent.IssueEvent` - """ - return github.PaginatedList.PaginatedList( - github.IssueEvent.IssueEvent, - self._requester, - f"{self.url}/issues/events", - None, - headers={"Accept": Consts.mediaTypeLockReasonPreview}, - ) - - def get_key(self, id): - """ - :calls: `GET /repos/{owner}/{repo}/keys/{id} `_ - :param id: integer - :rtype: :class:`github.RepositoryKey.RepositoryKey` - """ - assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/keys/{id}" - ) - return github.RepositoryKey.RepositoryKey( - self._requester, headers, data, completed=True - ) - - def get_keys(self): - """ - :calls: `GET /repos/{owner}/{repo}/keys `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.RepositoryKey.RepositoryKey` - """ - return github.PaginatedList.PaginatedList( - github.RepositoryKey.RepositoryKey, - self._requester, - f"{self.url}/keys", - None, - ) - - def get_label(self, name): - """ - :calls: `GET /repos/{owner}/{repo}/labels/{name} `_ - :param name: string - :rtype: :class:`github.Label.Label` - """ - assert isinstance(name, str), name - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/labels/{urllib.parse.quote(name)}" - ) - return github.Label.Label(self._requester, headers, data, completed=True) - - def get_labels(self): - """ - :calls: `GET /repos/{owner}/{repo}/labels `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` - """ - return github.PaginatedList.PaginatedList( - github.Label.Label, self._requester, f"{self.url}/labels", None - ) - - def get_languages(self): - """ - :calls: `GET /repos/{owner}/{repo}/languages `_ - :rtype: dict of string to integer - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/languages" - ) - return data - - def get_license(self): - """ - :calls: `GET /repos/{owner}/{repo}/license `_ - :rtype: :class:`github.ContentFile.ContentFile` - """ - - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/license" - ) - return github.ContentFile.ContentFile( - self._requester, headers, data, completed=True - ) - - def get_milestone(self, number): - """ - :calls: `GET /repos/{owner}/{repo}/milestones/{number} `_ - :param number: integer - :rtype: :class:`github.Milestone.Milestone` - """ - assert isinstance(number, int), number - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/milestones/{number}" - ) - return github.Milestone.Milestone( - self._requester, headers, data, completed=True - ) - - def get_milestones( - self, - state=github.GithubObject.NotSet, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/milestones `_ - :param state: string - :param sort: string - :param direction: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Milestone.Milestone` - """ - assert state is github.GithubObject.NotSet or isinstance(state, str), state - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - url_parameters = dict() - if state is not github.GithubObject.NotSet: - url_parameters["state"] = state - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - return github.PaginatedList.PaginatedList( - github.Milestone.Milestone, - self._requester, - f"{self.url}/milestones", - url_parameters, - ) - - def get_network_events(self): - """ - :calls: `GET /networks/{owner}/{repo}/events `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` - """ - return github.PaginatedList.PaginatedList( - github.Event.Event, - self._requester, - f"/networks/{self.owner.login}/{self.name}/events", - None, - ) - - def get_public_key(self): - """ - :calls: `GET /repos/{owner}/{repo}/actions/secrets/public-key `_ - :rtype: :class:`github.PublicKey.PublicKey` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/actions/secrets/public-key" - ) - return github.PublicKey.PublicKey( - self._requester, headers, data, completed=True - ) - - def get_pull(self, number): - """ - :calls: `GET /repos/{owner}/{repo}/pulls/{number} `_ - :param number: integer - :rtype: :class:`github.PullRequest.PullRequest` - """ - assert isinstance(number, int), number - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/pulls/{number}" - ) - return github.PullRequest.PullRequest( - self._requester, headers, data, completed=True - ) - - def get_pulls( - self, - state=github.GithubObject.NotSet, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - base=github.GithubObject.NotSet, - head=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/pulls `_ - :param state: string - :param sort: string - :param direction: string - :param base: string - :param head: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequest.PullRequest` - """ - assert state is github.GithubObject.NotSet or isinstance(state, str), state - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert base is github.GithubObject.NotSet or isinstance(base, str), base - assert head is github.GithubObject.NotSet or isinstance(head, str), head - url_parameters = dict() - if state is not github.GithubObject.NotSet: - url_parameters["state"] = state - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - if base is not github.GithubObject.NotSet: - url_parameters["base"] = base - if head is not github.GithubObject.NotSet: - url_parameters["head"] = head - return github.PaginatedList.PaginatedList( - github.PullRequest.PullRequest, - self._requester, - f"{self.url}/pulls", - url_parameters, - ) - - def get_pulls_comments( - self, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/pulls/comments `_ - :param sort: string - :param direction: string - :param since: datetime.datetime - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` - """ - return self.get_pulls_review_comments(sort, direction, since) - - def get_pulls_review_comments( - self, - sort=github.GithubObject.NotSet, - direction=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/pulls/comments `_ - :param sort: string - :param direction: string - :param since: datetime.datetime - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` - """ - assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - url_parameters = dict() - if sort is not github.GithubObject.NotSet: - url_parameters["sort"] = sort - if direction is not github.GithubObject.NotSet: - url_parameters["direction"] = direction - if since is not github.GithubObject.NotSet: - url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - return github.PaginatedList.PaginatedList( - github.PullRequestComment.PullRequestComment, - self._requester, - f"{self.url}/pulls/comments", - url_parameters, - ) - - def get_readme(self, ref=github.GithubObject.NotSet): - """ - :calls: `GET /repos/{owner}/{repo}/readme `_ - :param ref: string - :rtype: :class:`github.ContentFile.ContentFile` - """ - assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref - url_parameters = dict() - if ref is not github.GithubObject.NotSet: - url_parameters["ref"] = ref - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/readme", parameters=url_parameters - ) - return github.ContentFile.ContentFile( - self._requester, headers, data, completed=True - ) - - def get_self_hosted_runner(self, runner_id): - """ - :calls: `GET /repos/{owner}/{repo}/actions/runners/{id} `_ - :param runner_id: int - :rtype: :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` - """ - assert isinstance(runner_id, int), runner_id - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/actions/runners/{runner_id}" - ) - return github.SelfHostedActionsRunner.SelfHostedActionsRunner( - self._requester, headers, data, completed=True - ) - - def get_self_hosted_runners(self): - """ - :calls: `GET /repos/{owner}/{repo}/actions/runners `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` - """ - return github.PaginatedList.PaginatedList( - github.SelfHostedActionsRunner.SelfHostedActionsRunner, - self._requester, - f"{self.url}/actions/runners", - None, - list_item="runners", - ) - - def get_source_import(self): - """ - :calls: `GET /repos/{owner}/{repo}/import `_ - :rtype: :class:`github.SourceImport.SourceImport` - """ - import_header = {"Accept": Consts.mediaTypeImportPreview} - headers, data = self._requester.requestJsonAndCheck( - "GET", - f"{self.url}/import", - headers=import_header, - ) - if not data: - return None - else: - return github.SourceImport.SourceImport( - self._requester, headers, data, completed=True - ) - - def get_stargazers(self): - """ - :calls: `GET /repos/{owner}/{repo}/stargazers `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, f"{self.url}/stargazers", None - ) - - def get_stargazers_with_dates(self): - """ - :calls: `GET /repos/{owner}/{repo}/stargazers `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Stargazer.Stargazer` - """ - return github.PaginatedList.PaginatedList( - github.Stargazer.Stargazer, - self._requester, - f"{self.url}/stargazers", - None, - headers={"Accept": Consts.mediaTypeStarringPreview}, - ) - - def get_stats_contributors(self): - """ - :calls: `GET /repos/{owner}/{repo}/stats/contributors `_ - :rtype: None or list of :class:`github.StatsContributor.StatsContributor` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/stats/contributors" - ) - if not data: - return None - else: - return [ - github.StatsContributor.StatsContributor( - self._requester, headers, attributes, completed=True - ) - for attributes in data - ] - - def get_stats_commit_activity(self): - """ - :calls: `GET /repos/{owner}/{repo}/stats/commit_activity `_ - :rtype: None or list of :class:`github.StatsCommitActivity.StatsCommitActivity` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/stats/commit_activity" - ) - if not data: - return None - else: - return [ - github.StatsCommitActivity.StatsCommitActivity( - self._requester, headers, attributes, completed=True - ) - for attributes in data - ] - - def get_stats_code_frequency(self): - """ - :calls: `GET /repos/{owner}/{repo}/stats/code_frequency `_ - :rtype: None or list of :class:`github.StatsCodeFrequency.StatsCodeFrequency` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/stats/code_frequency" - ) - if not data: - return None - else: - return [ - github.StatsCodeFrequency.StatsCodeFrequency( - self._requester, headers, attributes, completed=True - ) - for attributes in data - ] - - def get_stats_participation(self): - """ - :calls: `GET /repos/{owner}/{repo}/stats/participation `_ - :rtype: None or :class:`github.StatsParticipation.StatsParticipation` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/stats/participation" - ) - if not data: - return None - else: - return github.StatsParticipation.StatsParticipation( - self._requester, headers, data, completed=True - ) - - def get_stats_punch_card(self): - """ - :calls: `GET /repos/{owner}/{repo}/stats/punch_card `_ - :rtype: None or :class:`github.StatsPunchCard.StatsPunchCard` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/stats/punch_card" - ) - if not data: - return None - else: - return github.StatsPunchCard.StatsPunchCard( - self._requester, headers, data, completed=True - ) - - def get_subscribers(self): - """ - :calls: `GET /repos/{owner}/{repo}/subscribers `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, f"{self.url}/subscribers", None - ) - - def get_tags(self): - """ - :calls: `GET /repos/{owner}/{repo}/tags `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Tag.Tag` - """ - return github.PaginatedList.PaginatedList( - github.Tag.Tag, self._requester, f"{self.url}/tags", None - ) - - def get_releases(self): - """ - :calls: `GET /repos/{owner}/{repo}/releases `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRelease.GitRelease` - """ - return github.PaginatedList.PaginatedList( - github.GitRelease.GitRelease, self._requester, f"{self.url}/releases", None - ) - - def get_release(self, id): - """ - :calls: `GET /repos/{owner}/{repo}/releases/{id} `_ - :param id: int (release id), str (tag name) - :rtype: None or :class:`github.GitRelease.GitRelease` - """ - if isinstance(id, int): - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/releases/{id}" - ) - return github.GitRelease.GitRelease( - self._requester, headers, data, completed=True - ) - elif isinstance(id, str): - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/releases/tags/{id}" - ) - return github.GitRelease.GitRelease( - self._requester, headers, data, completed=True - ) - - def get_latest_release(self): - """ - :calls: `GET /repos/{owner}/{repo}/releases/latest `_ - :rtype: :class:`github.GitRelease.GitRelease` - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/releases/latest" - ) - return github.GitRelease.GitRelease( - self._requester, headers, data, completed=True - ) - - def get_teams(self): - """ - :calls: `GET /repos/{owner}/{repo}/teams `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` - """ - return github.PaginatedList.PaginatedList( - github.Team.Team, self._requester, f"{self.url}/teams", None - ) - - def get_topics(self): - """ - :calls: `GET /repos/{owner}/{repo}/topics `_ - :rtype: list of strings - """ - headers, data = self._requester.requestJsonAndCheck( - "GET", - f"{self.url}/topics", - headers={"Accept": Consts.mediaTypeTopicsPreview}, - ) - return data["names"] - - def get_watchers(self): - """ - :calls: `GET /repos/{owner}/{repo}/watchers `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` - """ - return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, f"{self.url}/watchers", None - ) - - def get_workflows(self): - """ - :calls: `GET /repos/{owner}/{repo}/actions/workflows `_ - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Workflow.Workflow` - """ - return github.PaginatedList.PaginatedList( - github.Workflow.Workflow, - self._requester, - f"{self.url}/actions/workflows", - None, - list_item="workflows", - ) - - def get_workflow(self, id_or_name): - """ - :calls: `GET /repos/{owner}/{repo}/actions/workflows/{workflow_id} `_ - :param id_or_name: int or string - - :rtype: :class:`github.Workflow.Workflow` - """ - assert isinstance(id_or_name, int) or isinstance(id_or_name, str), id_or_name - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/actions/workflows/{id_or_name}" - ) - return github.Workflow.Workflow(self._requester, headers, data, completed=True) - - def get_workflow_runs( - self, - actor=github.GithubObject.NotSet, - branch=github.GithubObject.NotSet, - event=github.GithubObject.NotSet, - status=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/actions/runs `_ - :param actor: :class:`github.NamedUser.NamedUser` or string - :param branch: :class:`github.Branch.Branch` or string - :param event: string - :param status: string `queued`, `in_progress`, `completed`, `success`, `failure`, `neutral`, `cancelled`, `skipped`, `timed_out`, or `action_required` - - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.WorkflowRun.WorkflowRun` - """ - assert ( - actor is github.GithubObject.NotSet - or isinstance(actor, github.NamedUser.NamedUser) - or isinstance(actor, str) - ), actor - assert ( - branch is github.GithubObject.NotSet - or isinstance(branch, github.Branch.Branch) - or isinstance(branch, str) - ), branch - assert event is github.GithubObject.NotSet or isinstance(event, str), event - assert status is github.GithubObject.NotSet or isinstance(status, str), status - - url_parameters = dict() - if actor is not github.GithubObject.NotSet: - if isinstance(actor, github.NamedUser.NamedUser): - url_parameters["actor"] = actor._identity - else: - url_parameters["actor"] = actor - if branch is not github.GithubObject.NotSet: - if isinstance(branch, github.Branch.Branch): - url_parameters["branch"] = branch.name - else: - url_parameters["branch"] = branch - if event is not github.GithubObject.NotSet: - url_parameters["event"] = event - if status is not github.GithubObject.NotSet: - url_parameters["status"] = status - - return github.PaginatedList.PaginatedList( - github.WorkflowRun.WorkflowRun, - self._requester, - f"{self.url}/actions/runs", - url_parameters, - list_item="workflow_runs", - ) - - def get_workflow_run(self, id_): - """ - :calls: `GET /repos/{owner}/{repo}/actions/runs/{run_id} `_ - :param id_: int - - :rtype: :class:`github.WorkflowRun.WorkflowRun` - """ - assert isinstance(id_, int) - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/actions/runs/{id_}" - ) - return github.WorkflowRun.WorkflowRun( - self._requester, headers, data, completed=True - ) - - def has_in_assignees(self, assignee): - """ - :calls: `GET /repos/{owner}/{repo}/assignees/{assignee} `_ - :param assignee: string or :class:`github.NamedUser.NamedUser` - :rtype: bool - """ - assert isinstance(assignee, github.NamedUser.NamedUser) or isinstance( - assignee, str - ), assignee - - if isinstance(assignee, github.NamedUser.NamedUser): - assignee = assignee._identity - - status, headers, data = self._requester.requestJson( - "GET", f"{self.url}/assignees/{assignee}" - ) - return status == 204 - - def has_in_collaborators(self, collaborator): - """ - :calls: `GET /repos/{owner}/{repo}/collaborators/{user} `_ - :param collaborator: string or :class:`github.NamedUser.NamedUser` - :rtype: bool - """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( - collaborator, str - ), collaborator - - if isinstance(collaborator, github.NamedUser.NamedUser): - collaborator = collaborator._identity - - status, headers, data = self._requester.requestJson( - "GET", f"{self.url}/collaborators/{collaborator}" - ) - return status == 204 - - def _legacy_convert_issue(self, attributes): - convertedAttributes = { - "number": attributes["number"], - "url": f"/repos{urllib.parse.urlparse(attributes['html_url']).path}", - "user": { - "login": attributes["user"], - "url": f"/users/{attributes['user']}", - }, - } - if "labels" in attributes: # pragma no branch - convertedAttributes["labels"] = [ - {"name": label} for label in attributes["labels"] - ] - for attr in ("title", "created_at", "comments", "body", "updated_at", "state"): - if attr in attributes: # pragma no branch - convertedAttributes[attr] = attributes[attr] - return convertedAttributes - - def legacy_search_issues(self, state, keyword): - """ - :calls: `GET /legacy/issues/search/{owner}/{repository}/{state}/{keyword} `_ - :param state: "open" or "closed" - :param keyword: string - :rtype: List of :class:`github.Issue.Issue` - """ - assert state in ["open", "closed"], state - assert isinstance(keyword, str), keyword - headers, data = self._requester.requestJsonAndCheck( - "GET", - f"/legacy/issues/search/{self.owner.login}/{self.name}/{state}/{urllib.parse.quote(keyword)}", - ) - return [ - github.Issue.Issue( - self._requester, - headers, - self._legacy_convert_issue(element), - completed=False, - ) - for element in data["issues"] - ] - - def get_notifications( - self, - all=github.GithubObject.NotSet, - participating=github.GithubObject.NotSet, - since=github.GithubObject.NotSet, - before=github.GithubObject.NotSet, - ): - """ - :calls: `GET /repos/{owner}/{repo}/notifications `_ - :param all: bool - :param participating: bool - :param since: datetime.datetime - :param before: datetime.datetime - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification` - """ - - assert all is github.GithubObject.NotSet or isinstance(all, bool), all - assert participating is github.GithubObject.NotSet or isinstance( - participating, bool - ), participating - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - assert before is github.GithubObject.NotSet or isinstance( - before, datetime.datetime - ), before - - params = dict() - if all is not github.GithubObject.NotSet: - params["all"] = all - if participating is not github.GithubObject.NotSet: - params["participating"] = participating - if since is not github.GithubObject.NotSet: - params["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") - if before is not github.GithubObject.NotSet: - params["before"] = before.strftime("%Y-%m-%dT%H:%M:%SZ") - - return github.PaginatedList.PaginatedList( - github.Notification.Notification, - self._requester, - f"{self.url}/notifications", - params, - ) - - def mark_notifications_as_read(self, last_read_at=datetime.datetime.utcnow()): - """ - :calls: `PUT /repos/{owner}/{repo}/notifications `_ - :param last_read_at: datetime - """ - assert isinstance(last_read_at, datetime.datetime) - put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} - - headers, data = self._requester.requestJsonAndCheck( - "PUT", f"{self.url}/notifications", input=put_parameters - ) - - def merge(self, base, head, commit_message=github.GithubObject.NotSet): - """ - :calls: `POST /repos/{owner}/{repo}/merges `_ - :param base: string - :param head: string - :param commit_message: string - :rtype: :class:`github.Commit.Commit` - """ - assert isinstance(base, str), base - assert isinstance(head, str), head - assert commit_message is github.GithubObject.NotSet or isinstance( - commit_message, str - ), commit_message - post_parameters = { - "base": base, - "head": head, - } - if commit_message is not github.GithubObject.NotSet: - post_parameters["commit_message"] = commit_message - headers, data = self._requester.requestJsonAndCheck( - "POST", f"{self.url}/merges", input=post_parameters - ) - if data is None: - return None - else: - return github.Commit.Commit(self._requester, headers, data, completed=True) - - def replace_topics(self, topics): - """ - :calls: `PUT /repos/{owner}/{repo}/topics `_ - :param topics: list of strings - :rtype: None - """ - post_parameters = {"names": topics} - headers, data = self._requester.requestJsonAndCheck( - "PUT", - f"{self.url}/topics", - headers={"Accept": Consts.mediaTypeTopicsPreview}, - input=post_parameters, - ) - - def get_vulnerability_alert(self): - """ - :calls: `GET /repos/{owner}/{repo}/vulnerability-alerts `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "GET", - f"{self.url}/vulnerability-alerts", - headers={"Accept": Consts.vulnerabilityAlertsPreview}, - ) - return status == 204 - - def enable_vulnerability_alert(self): - """ - :calls: `PUT /repos/{owner}/{repo}/vulnerability-alerts `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "PUT", - f"{self.url}/vulnerability-alerts", - headers={"Accept": Consts.vulnerabilityAlertsPreview}, - ) - return status == 204 - - def disable_vulnerability_alert(self): - """ - :calls: `DELETE /repos/{owner}/{repo}/vulnerability-alerts `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "DELETE", - f"{self.url}/vulnerability-alerts", - headers={"Accept": Consts.vulnerabilityAlertsPreview}, - ) - return status == 204 - - def enable_automated_security_fixes(self): - """ - :calls: `PUT /repos/{owner}/{repo}/automated-security-fixes `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "PUT", - f"{self.url}/automated-security-fixes", - headers={"Accept": Consts.automatedSecurityFixes}, - ) - return status == 204 - - def disable_automated_security_fixes(self): - """ - :calls: `DELETE /repos/{owner}/{repo}/automated-security-fixes `_ - :rtype: bool - """ - status, _, _ = self._requester.requestJson( - "DELETE", - f"{self.url}/automated-security-fixes", - headers={"Accept": Consts.automatedSecurityFixes}, - ) - return status == 204 - - def remove_from_collaborators(self, collaborator): - """ - :calls: `DELETE /repos/{owner}/{repo}/collaborators/{user} `_ - :param collaborator: string or :class:`github.NamedUser.NamedUser` - :rtype: None - """ - assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( - collaborator, str - ), collaborator - - if isinstance(collaborator, github.NamedUser.NamedUser): - collaborator = collaborator._identity - - headers, data = self._requester.requestJsonAndCheck( - "DELETE", f"{self.url}/collaborators/{collaborator}" - ) - - def remove_self_hosted_runner(self, runner): - """ - :calls: `DELETE /repos/{owner}/{repo}/actions/runners/{runner_id} `_ - :param runner: int or :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` - :rtype: bool - """ - assert isinstance( - runner, github.SelfHostedActionsRunner.SelfHostedActionsRunner - ) or isinstance(runner, int), runner - - if isinstance(runner, github.SelfHostedActionsRunner.SelfHostedActionsRunner): - runner = runner.id - - status, _, _ = self._requester.requestJson( - "DELETE", f"{self.url}/actions/runners/{runner}" - ) - return status == 204 - - def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet): - """ - :calls: `POST /hub `_ - :param event: string - :param callback: string - :param secret: string - :rtype: None - """ - return self._hub("subscribe", event, callback, secret) - - def unsubscribe_from_hub(self, event, callback): - """ - :calls: `POST /hub `_ - :param event: string - :param callback: string - :param secret: string - :rtype: None - """ - return self._hub("unsubscribe", event, callback, github.GithubObject.NotSet) - - def create_check_suite(self, head_sha): - """ - :calls: `POST /repos/{owner}/{repo}/check-suites `_ - :param head_sha: string - :rtype: :class:`github.CheckSuite.CheckSuite` - """ - assert isinstance(head_sha, str), head_sha - headers, data = self._requester.requestJsonAndCheck( - "POST", - f"{self.url}/check-suites", - input={"head_sha": head_sha}, - ) - return github.CheckSuite.CheckSuite( - self._requester, headers, data, completed=True - ) - - def get_check_suite(self, check_suite_id): - """ - :calls: `GET /repos/{owner}/{repo}/check-suites/{check_suite_id} `_ - :param check_suite_id: int - :rtype: :class:`github.CheckSuite.CheckSuite` - """ - assert isinstance(check_suite_id, int), check_suite_id - requestHeaders = {"Accept": "application/vnd.github.v3+json"} - headers, data = self._requester.requestJsonAndCheck( - "GET", - f"{self.url}/check-suites/{check_suite_id}", - headers=requestHeaders, - ) - return github.CheckSuite.CheckSuite( - self._requester, headers, data, completed=True - ) - - def update_check_suites_preferences(self, auto_trigger_checks): - """ - :calls: `PATCH /repos/{owner}/{repo}/check-suites/preferences `_ - :param auto_trigger_checks: list of dict - :rtype: :class:`github.RepositoryPreferences.RepositoryPreferences` - """ - assert all( - isinstance(element, dict) for element in auto_trigger_checks - ), auto_trigger_checks - headers, data = self._requester.requestJsonAndCheck( - "PATCH", - f"{self.url}/check-suites/preferences", - input={"auto_trigger_checks": auto_trigger_checks}, - ) - return github.RepositoryPreferences.RepositoryPreferences( - self._requester, headers, data, completed=True - ) - - def _hub(self, mode, event, callback, secret): - assert isinstance(mode, str), mode - assert isinstance(event, str), event - assert isinstance(callback, str), callback - assert secret is github.GithubObject.NotSet or isinstance(secret, str), secret - - post_parameters = collections.OrderedDict() - post_parameters["hub.callback"] = callback - post_parameters[ - "hub.topic" - ] = f"https://github.com/{self.full_name}/events/{event}" - post_parameters["hub.mode"] = mode - if secret is not github.GithubObject.NotSet: - post_parameters["hub.secret"] = secret - - headers, output = self._requester.requestMultipartAndCheck( - "POST", "/hub", input=post_parameters - ) - - @property - def _identity(self): - return f"{self.owner.login}/{self.name}" - - def get_release_asset(self, id): - assert isinstance(id, (int)), id - - resp_headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/releases/assets/{id}" - ) - return github.GitReleaseAsset.GitReleaseAsset( - self._requester, resp_headers, data, completed=True - ) - - def create_check_run( - self, - name, - head_sha, - details_url=github.GithubObject.NotSet, - external_id=github.GithubObject.NotSet, - status=github.GithubObject.NotSet, - started_at=github.GithubObject.NotSet, - conclusion=github.GithubObject.NotSet, - completed_at=github.GithubObject.NotSet, - output=github.GithubObject.NotSet, - actions=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/{owner}/{repo}/check-runs `_ - :param name: string - :param head_sha: string - :param details_url: string - :param external_id: string - :param status: string - :param started_at: datetime.datetime - :param conclusion: string - :param completed_at: datetime.datetime - :param output: dict - :param actions: list of dict - :rtype: :class:`github.CheckRun.CheckRun` - """ - assert isinstance(name, str), name - assert isinstance(head_sha, str), head_sha - assert details_url is github.GithubObject.NotSet or isinstance( - details_url, str - ), details_url - assert external_id is github.GithubObject.NotSet or isinstance( - external_id, str - ), external_id - assert status is github.GithubObject.NotSet or isinstance(status, str), status - assert started_at is github.GithubObject.NotSet or isinstance( - started_at, datetime.datetime - ), started_at - assert conclusion is github.GithubObject.NotSet or isinstance( - conclusion, str - ), conclusion - assert completed_at is github.GithubObject.NotSet or isinstance( - completed_at, datetime.datetime - ), completed_at - assert output is github.GithubObject.NotSet or isinstance(output, dict), output - assert actions is github.GithubObject.NotSet or all( - isinstance(element, dict) for element in actions - ), actions - - post_parameters = { - "name": name, - "head_sha": head_sha, - } - if details_url is not github.GithubObject.NotSet: - post_parameters["details_url"] = details_url - if external_id is not github.GithubObject.NotSet: - post_parameters["external_id"] = external_id - if status is not github.GithubObject.NotSet: - post_parameters["status"] = status - if started_at is not github.GithubObject.NotSet: - post_parameters["started_at"] = started_at.strftime("%Y-%m-%dT%H:%M:%SZ") - if completed_at is not github.GithubObject.NotSet: - post_parameters["completed_at"] = completed_at.strftime( - "%Y-%m-%dT%H:%M:%SZ" - ) - if conclusion is not github.GithubObject.NotSet: - post_parameters["conclusion"] = conclusion - if output is not github.GithubObject.NotSet: - post_parameters["output"] = output - if actions is not github.GithubObject.NotSet: - post_parameters["actions"] = actions - - headers, data = self._requester.requestJsonAndCheck( - "POST", - f"{self.url}/check-runs", - input=post_parameters, - ) - return github.CheckRun.CheckRun(self._requester, headers, data, completed=True) - - def get_check_run(self, check_run_id): - """ - :calls: `GET /repos/{owner}/{repo}/check-runs/{check_run_id} `_ - :param check_run_id: int - :rtype: :class:`github.CheckRun.CheckRun` - """ - assert isinstance(check_run_id, int), check_run_id - headers, data = self._requester.requestJsonAndCheck( - "GET", f"{self.url}/check-runs/{check_run_id}" - ) - return github.CheckRun.CheckRun(self._requester, headers, data, completed=True) - - def _initAttributes(self): - self._allow_merge_commit = github.GithubObject.NotSet - self._allow_rebase_merge = github.GithubObject.NotSet - self._allow_squash_merge = github.GithubObject.NotSet - self._archived = github.GithubObject.NotSet - self._archive_url = github.GithubObject.NotSet - self._assignees_url = github.GithubObject.NotSet - self._blobs_url = github.GithubObject.NotSet - self._branches_url = github.GithubObject.NotSet - self._clone_url = github.GithubObject.NotSet - self._collaborators_url = github.GithubObject.NotSet - self._comments_url = github.GithubObject.NotSet - self._commits_url = github.GithubObject.NotSet - self._compare_url = github.GithubObject.NotSet - self._contents_url = github.GithubObject.NotSet - self._contributors_url = github.GithubObject.NotSet - self._created_at = github.GithubObject.NotSet - self._default_branch = github.GithubObject.NotSet - self._delete_branch_on_merge = github.GithubObject.NotSet - self._deployments_url = github.GithubObject.NotSet - self._description = github.GithubObject.NotSet - self._downloads_url = github.GithubObject.NotSet - self._events_url = github.GithubObject.NotSet - self._fork = github.GithubObject.NotSet - self._forks = github.GithubObject.NotSet - self._forks_count = github.GithubObject.NotSet - self._forks_url = github.GithubObject.NotSet - self._full_name = github.GithubObject.NotSet - self._git_commits_url = github.GithubObject.NotSet - self._git_refs_url = github.GithubObject.NotSet - self._git_tags_url = github.GithubObject.NotSet - self._git_url = github.GithubObject.NotSet - self._has_downloads = github.GithubObject.NotSet - self._has_issues = github.GithubObject.NotSet - self._has_pages = github.GithubObject.NotSet - self._has_projects = github.GithubObject.NotSet - self._has_wiki = github.GithubObject.NotSet - self._homepage = github.GithubObject.NotSet - self._hooks_url = github.GithubObject.NotSet - self._html_url = github.GithubObject.NotSet - self._id = github.GithubObject.NotSet - self._is_template = github.GithubObject.NotSet - self._issue_comment_url = github.GithubObject.NotSet - self._issue_events_url = github.GithubObject.NotSet - self._issues_url = github.GithubObject.NotSet - self._keys_url = github.GithubObject.NotSet - self._labels_url = github.GithubObject.NotSet - self._language = github.GithubObject.NotSet - self._languages_url = github.GithubObject.NotSet - self._master_branch = github.GithubObject.NotSet - self._merges_url = github.GithubObject.NotSet - self._milestones_url = github.GithubObject.NotSet - self._mirror_url = github.GithubObject.NotSet - self._name = github.GithubObject.NotSet - self._network_count = github.GithubObject.NotSet - self._notifications_url = github.GithubObject.NotSet - self._open_issues = github.GithubObject.NotSet - self._open_issues_count = github.GithubObject.NotSet - self._organization = github.GithubObject.NotSet - self._owner = github.GithubObject.NotSet - self._parent = github.GithubObject.NotSet - self._permissions = github.GithubObject.NotSet - self._private = github.GithubObject.NotSet - self._pulls_url = github.GithubObject.NotSet - self._pushed_at = github.GithubObject.NotSet - self._releases_url = github.GithubObject.NotSet - self._size = github.GithubObject.NotSet - self._source = github.GithubObject.NotSet - self._ssh_url = github.GithubObject.NotSet - self._stargazers_count = github.GithubObject.NotSet - self._stargazers_url = github.GithubObject.NotSet - self._statuses_url = github.GithubObject.NotSet - self._subscribers_url = github.GithubObject.NotSet - self._subscribers_count = github.GithubObject.NotSet - self._subscription_url = github.GithubObject.NotSet - self._svn_url = github.GithubObject.NotSet - self._tags_url = github.GithubObject.NotSet - self._teams_url = github.GithubObject.NotSet - self._trees_url = github.GithubObject.NotSet - self._updated_at = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - self._watchers = github.GithubObject.NotSet - self._watchers_count = github.GithubObject.NotSet - - def _useAttributes(self, attributes): - if "allow_merge_commit" in attributes: # pragma no branch - self._allow_merge_commit = self._makeBoolAttribute( - attributes["allow_merge_commit"] - ) - if "allow_rebase_merge" in attributes: # pragma no branch - self._allow_rebase_merge = self._makeBoolAttribute( - attributes["allow_rebase_merge"] - ) - if "allow_squash_merge" in attributes: # pragma no branch - self._allow_squash_merge = self._makeBoolAttribute( - attributes["allow_squash_merge"] - ) - if "archived" in attributes: # pragma no branch - self._archived = self._makeBoolAttribute(attributes["archived"]) - if "archive_url" in attributes: # pragma no branch - self._archive_url = self._makeStringAttribute(attributes["archive_url"]) - if "assignees_url" in attributes: # pragma no branch - self._assignees_url = self._makeStringAttribute(attributes["assignees_url"]) - if "blobs_url" in attributes: # pragma no branch - self._blobs_url = self._makeStringAttribute(attributes["blobs_url"]) - if "branches_url" in attributes: # pragma no branch - self._branches_url = self._makeStringAttribute(attributes["branches_url"]) - if "clone_url" in attributes: # pragma no branch - self._clone_url = self._makeStringAttribute(attributes["clone_url"]) - if "collaborators_url" in attributes: # pragma no branch - self._collaborators_url = self._makeStringAttribute( - attributes["collaborators_url"] - ) - if "comments_url" in attributes: # pragma no branch - self._comments_url = self._makeStringAttribute(attributes["comments_url"]) - if "commits_url" in attributes: # pragma no branch - self._commits_url = self._makeStringAttribute(attributes["commits_url"]) - if "compare_url" in attributes: # pragma no branch - self._compare_url = self._makeStringAttribute(attributes["compare_url"]) - if "contents_url" in attributes: # pragma no branch - self._contents_url = self._makeStringAttribute(attributes["contents_url"]) - if "contributors_url" in attributes: # pragma no branch - self._contributors_url = self._makeStringAttribute( - attributes["contributors_url"] - ) - if "created_at" in attributes: # pragma no branch - self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) - if "default_branch" in attributes: # pragma no branch - self._default_branch = self._makeStringAttribute( - attributes["default_branch"] - ) - if "delete_branch_on_merge" in attributes: # pragma no branch - self._delete_branch_on_merge = self._makeBoolAttribute( - attributes["delete_branch_on_merge"] - ) - if "deployments_url" in attributes: # pragma no branch - self._deployments_url = self._makeStringAttribute( - attributes["deployments_url"] - ) - if "description" in attributes: # pragma no branch - self._description = self._makeStringAttribute(attributes["description"]) - if "downloads_url" in attributes: # pragma no branch - self._downloads_url = self._makeStringAttribute(attributes["downloads_url"]) - if "events_url" in attributes: # pragma no branch - self._events_url = self._makeStringAttribute(attributes["events_url"]) - if "fork" in attributes: # pragma no branch - self._fork = self._makeBoolAttribute(attributes["fork"]) - if "forks" in attributes: # pragma no branch - self._forks = self._makeIntAttribute(attributes["forks"]) - if "forks_count" in attributes: # pragma no branch - self._forks_count = self._makeIntAttribute(attributes["forks_count"]) - if "forks_url" in attributes: # pragma no branch - self._forks_url = self._makeStringAttribute(attributes["forks_url"]) - if "full_name" in attributes: # pragma no branch - self._full_name = self._makeStringAttribute(attributes["full_name"]) - if "git_commits_url" in attributes: # pragma no branch - self._git_commits_url = self._makeStringAttribute( - attributes["git_commits_url"] - ) - if "git_refs_url" in attributes: # pragma no branch - self._git_refs_url = self._makeStringAttribute(attributes["git_refs_url"]) - if "git_tags_url" in attributes: # pragma no branch - self._git_tags_url = self._makeStringAttribute(attributes["git_tags_url"]) - if "git_url" in attributes: # pragma no branch - self._git_url = self._makeStringAttribute(attributes["git_url"]) - if "has_downloads" in attributes: # pragma no branch - self._has_downloads = self._makeBoolAttribute(attributes["has_downloads"]) - if "has_issues" in attributes: # pragma no branch - self._has_issues = self._makeBoolAttribute(attributes["has_issues"]) - if "has_pages" in attributes: # pragma no branch - self._has_pages = self._makeBoolAttribute(attributes["has_pages"]) - if "has_projects" in attributes: # pragma no branch - self._has_projects = self._makeBoolAttribute(attributes["has_projects"]) - if "has_wiki" in attributes: # pragma no branch - self._has_wiki = self._makeBoolAttribute(attributes["has_wiki"]) - if "homepage" in attributes: # pragma no branch - self._homepage = self._makeStringAttribute(attributes["homepage"]) - if "hooks_url" in attributes: # pragma no branch - self._hooks_url = self._makeStringAttribute(attributes["hooks_url"]) - if "html_url" in attributes: # pragma no branch - self._html_url = self._makeStringAttribute(attributes["html_url"]) - if "id" in attributes: # pragma no branch - self._id = self._makeIntAttribute(attributes["id"]) - if "is_template" in attributes: # pragma no branch - self._is_template = self._makeBoolAttribute(attributes["is_template"]) - if "issue_comment_url" in attributes: # pragma no branch - self._issue_comment_url = self._makeStringAttribute( - attributes["issue_comment_url"] - ) - if "issue_events_url" in attributes: # pragma no branch - self._issue_events_url = self._makeStringAttribute( - attributes["issue_events_url"] - ) - if "issues_url" in attributes: # pragma no branch - self._issues_url = self._makeStringAttribute(attributes["issues_url"]) - if "keys_url" in attributes: # pragma no branch - self._keys_url = self._makeStringAttribute(attributes["keys_url"]) - if "labels_url" in attributes: # pragma no branch - self._labels_url = self._makeStringAttribute(attributes["labels_url"]) - if "language" in attributes: # pragma no branch - self._language = self._makeStringAttribute(attributes["language"]) - if "languages_url" in attributes: # pragma no branch - self._languages_url = self._makeStringAttribute(attributes["languages_url"]) - if "master_branch" in attributes: # pragma no branch - self._master_branch = self._makeStringAttribute(attributes["master_branch"]) - if "merges_url" in attributes: # pragma no branch - self._merges_url = self._makeStringAttribute(attributes["merges_url"]) - if "milestones_url" in attributes: # pragma no branch - self._milestones_url = self._makeStringAttribute( - attributes["milestones_url"] - ) - if "mirror_url" in attributes: # pragma no branch - self._mirror_url = self._makeStringAttribute(attributes["mirror_url"]) - if "name" in attributes: # pragma no branch - self._name = self._makeStringAttribute(attributes["name"]) - if "network_count" in attributes: # pragma no branch - self._network_count = self._makeIntAttribute(attributes["network_count"]) - if "notifications_url" in attributes: # pragma no branch - self._notifications_url = self._makeStringAttribute( - attributes["notifications_url"] - ) - if "open_issues" in attributes: # pragma no branch - self._open_issues = self._makeIntAttribute(attributes["open_issues"]) - if "open_issues_count" in attributes: # pragma no branch - self._open_issues_count = self._makeIntAttribute( - attributes["open_issues_count"] - ) - if "organization" in attributes: # pragma no branch - self._organization = self._makeClassAttribute( - github.Organization.Organization, attributes["organization"] - ) - if "owner" in attributes: # pragma no branch - self._owner = self._makeClassAttribute( - github.NamedUser.NamedUser, attributes["owner"] - ) - if "parent" in attributes: # pragma no branch - self._parent = self._makeClassAttribute(Repository, attributes["parent"]) - if "permissions" in attributes: # pragma no branch - self._permissions = self._makeClassAttribute( - github.Permissions.Permissions, attributes["permissions"] - ) - if "private" in attributes: # pragma no branch - self._private = self._makeBoolAttribute(attributes["private"]) - if "pulls_url" in attributes: # pragma no branch - self._pulls_url = self._makeStringAttribute(attributes["pulls_url"]) - if "pushed_at" in attributes: # pragma no branch - self._pushed_at = self._makeDatetimeAttribute(attributes["pushed_at"]) - if "releases_url" in attributes: # pragma no branch - self._releases_url = self._makeStringAttribute(attributes["releases_url"]) - if "size" in attributes: # pragma no branch - self._size = self._makeIntAttribute(attributes["size"]) - if "source" in attributes: # pragma no branch - self._source = self._makeClassAttribute(Repository, attributes["source"]) - if "ssh_url" in attributes: # pragma no branch - self._ssh_url = self._makeStringAttribute(attributes["ssh_url"]) - if "stargazers_count" in attributes: # pragma no branch - self._stargazers_count = self._makeIntAttribute( - attributes["stargazers_count"] - ) - if "stargazers_url" in attributes: # pragma no branch - self._stargazers_url = self._makeStringAttribute( - attributes["stargazers_url"] - ) - if "statuses_url" in attributes: # pragma no branch - self._statuses_url = self._makeStringAttribute(attributes["statuses_url"]) - if "subscribers_url" in attributes: # pragma no branch - self._subscribers_url = self._makeStringAttribute( - attributes["subscribers_url"] - ) - if "subscribers_count" in attributes: # pragma no branch - self._subscribers_count = self._makeIntAttribute( - attributes["subscribers_count"] - ) - if "subscription_url" in attributes: # pragma no branch - self._subscription_url = self._makeStringAttribute( - attributes["subscription_url"] - ) - if "svn_url" in attributes: # pragma no branch - self._svn_url = self._makeStringAttribute(attributes["svn_url"]) - if "tags_url" in attributes: # pragma no branch - self._tags_url = self._makeStringAttribute(attributes["tags_url"]) - if "teams_url" in attributes: # pragma no branch - self._teams_url = self._makeStringAttribute(attributes["teams_url"]) - if "trees_url" in attributes: # pragma no branch - self._trees_url = self._makeStringAttribute(attributes["trees_url"]) - if "updated_at" in attributes: # pragma no branch - self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) - if "url" in attributes: # pragma no branch - self._url = self._makeStringAttribute(attributes["url"]) - if "watchers" in attributes: # pragma no branch - self._watchers = self._makeIntAttribute(attributes["watchers"]) - if "watchers_count" in attributes: # pragma no branch - self._watchers_count = self._makeIntAttribute(attributes["watchers_count"]) diff --git a/scripts/add_attribute.py b/scripts/add_attribute.py index 7b8513e76f..73bc1a58c5 100644 --- a/scripts/add_attribute.py +++ b/scripts/add_attribute.py @@ -183,4 +183,4 @@ with open(fileName, "w") as f: for line in newLines: - f.write((line + "\n").encode()) + f.write(line + "\n") From efb9dc2aa30f479f8dbc30f0f145cd145c0850c2 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Wed, 12 Feb 2020 22:41:33 -0300 Subject: [PATCH 19/25] Restore file delete by mistake --- github/Repository.py | 3413 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3413 insertions(+) diff --git a/github/Repository.py b/github/Repository.py index e69de29bb2..b3a27dc4cb 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -0,0 +1,3413 @@ +# -*- coding: utf-8 -*- + +############################ Copyrights and license ############################ +# # +# Copyright 2012 Christopher Gilbert # +# Copyright 2012 Steve English # +# Copyright 2012 Vincent Jacques # +# Copyright 2012 Zearin # +# Copyright 2013 AKFish # +# Copyright 2013 Adrian Petrescu # +# Copyright 2013 Cameron White # +# Copyright 2013 David Farr # +# Copyright 2013 Mark Roddy # +# Copyright 2013 Vincent Jacques # +# Copyright 2013 martinqt # +# Copyright 2014 Vincent Jacques # +# Copyright 2015 Aaron Levine # +# Copyright 2015 Christopher Wilcox # +# Copyright 2015 Dan Vanderkam # +# Copyright 2015 Ed Holland # +# Copyright 2015 Enix Yu # +# Copyright 2015 Jay # +# Copyright 2015 Jimmy Zelinskie # +# Copyright 2015 Jonathan Debonis # +# Copyright 2015 Kevin Lewandowski # +# Copyright 2015 Kyle Hornberg # +# Copyright 2015 edhollandAL # +# Copyright 2016 @tmshn # +# Copyright 2016 Dustin Spicuzza # +# Copyright 2016 Enix Yu # +# Copyright 2016 Jannis Gebauer # +# Copyright 2016 Per Øyvind Karlsen # +# Copyright 2016 Peter Buckley # +# Copyright 2016 Sylvus # +# Copyright 2016 fukatani # +# Copyright 2016 ghfan # +# Copyright 2017 Andreas Lutro # +# Copyright 2017 Ben Firshman # +# Copyright 2017 Chris McBride # +# Copyright 2017 Hugo # +# Copyright 2017 Jannis Gebauer # +# Copyright 2017 Jason White # +# Copyright 2017 Jimmy Zelinskie # +# Copyright 2017 Nhomar Hernández [Vauxoo] # +# Copyright 2017 Simon # +# Copyright 2018 Andrew Smith # +# Copyright 2018 Brian Torres-Gil # +# Copyright 2018 Hayden Fuss # +# Copyright 2018 Ilya Konstantinov # +# Copyright 2018 Jacopo Notarstefano # +# Copyright 2018 John Hui # +# Copyright 2018 Mateusz Loskot # +# Copyright 2018 Michael Behrisch # +# Copyright 2018 Nicholas Buse # +# Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com> # +# Copyright 2018 Shinichi TAMURA # +# Copyright 2018 Steve Kowalik # +# Copyright 2018 Wan Liuyang # +# Copyright 2018 Will Yardley # +# Copyright 2018 per1234 # +# Copyright 2018 sechastain # +# Copyright 2018 sfdye # +# Copyright 2018 Vinay Hegde # +# Copyright 2018 Justin Kufro # +# Copyright 2018 Ivan Minno # +# Copyright 2018 Zilei Gu # +# Copyright 2018 Yves Zumbach # +# Copyright 2018 Leying Chen # +# # +# This file is part of PyGithub. # +# http://pygithub.readthedocs.io/ # +# # +# PyGithub is free software: you can redistribute it and/or modify it under # +# the terms of the GNU Lesser General Public License as published by the Free # +# Software Foundation, either version 3 of the License, or (at your option) # +# any later version. # +# # +# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # +# details. # +# # +# You should have received a copy of the GNU Lesser General Public License # +# along with PyGithub. If not, see . # +# # +################################################################################ + +import collections +import datetime +import urllib.parse +from base64 import b64encode + +from deprecated import deprecated + +import github.Branch +import github.Clones +import github.Commit +import github.CommitComment +import github.Comparison +import github.ContentFile +import github.Download +import github.Event +import github.GitBlob +import github.GitCommit +import github.GithubObject +import github.GitRef +import github.GitRelease +import github.GitReleaseAsset +import github.GitTag +import github.GitTree +import github.Hook +import github.Invitation +import github.Issue +import github.IssueEvent +import github.Label +import github.Milestone +import github.NamedUser +import github.Organization +import github.PaginatedList +import github.Path +import github.Permissions +import github.Project +import github.PullRequest +import github.Referrer +import github.Repository +import github.RepositoryKey +import github.SourceImport +import github.Stargazer +import github.StatsCodeFrequency +import github.StatsCommitActivity +import github.StatsContributor +import github.StatsParticipation +import github.StatsPunchCard +import github.Tag +import github.Team +import github.View + +from . import Consts + + +class Repository(github.GithubObject.CompletableGithubObject): + """ + This class represents Repositories. The reference can be found here http://developer.github.com/v3/repos/ + """ + + def __repr__(self): + return self.get__repr__({"full_name": self._full_name.value}) + + @property + def allow_merge_commit(self): + """ + :type: bool + """ + self._completeIfNotSet(self._allow_merge_commit) + return self._allow_merge_commit.value + + @property + def allow_rebase_merge(self): + """ + :type: bool + """ + self._completeIfNotSet(self._allow_rebase_merge) + return self._allow_rebase_merge.value + + @property + def allow_squash_merge(self): + """ + :type: bool + """ + self._completeIfNotSet(self._allow_squash_merge) + return self._allow_squash_merge.value + + @property + def archived(self): + """ + :type: bool + """ + self._completeIfNotSet(self._archived) + return self._archived.value + + @property + def archive_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._archive_url) + return self._archive_url.value + + @property + def assignees_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._assignees_url) + return self._assignees_url.value + + @property + def blobs_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._blobs_url) + return self._blobs_url.value + + @property + def branches_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._branches_url) + return self._branches_url.value + + @property + def clone_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._clone_url) + return self._clone_url.value + + @property + def collaborators_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._collaborators_url) + return self._collaborators_url.value + + @property + def comments_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._comments_url) + return self._comments_url.value + + @property + def commits_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._commits_url) + return self._commits_url.value + + @property + def compare_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._compare_url) + return self._compare_url.value + + @property + def contents_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._contents_url) + return self._contents_url.value + + @property + def contributors_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._contributors_url) + return self._contributors_url.value + + @property + def created_at(self): + """ + :type: datetime.datetime + """ + self._completeIfNotSet(self._created_at) + return self._created_at.value + + @property + def default_branch(self): + """ + :type: string + """ + self._completeIfNotSet(self._default_branch) + return self._default_branch.value + + @property + def delete_branch_on_merge(self): + """ + :type: bool + """ + self._completeIfNotSet(self._delete_branch_on_merge) + return self._delete_branch_on_merge.value + + @property + def description(self): + """ + :type: string + """ + self._completeIfNotSet(self._description) + return self._description.value + + @property + def downloads_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._downloads_url) + return self._downloads_url.value + + @property + def events_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._events_url) + return self._events_url.value + + @property + def fork(self): + """ + :type: bool + """ + self._completeIfNotSet(self._fork) + return self._fork.value + + @property + def forks(self): + """ + :type: integer + """ + self._completeIfNotSet(self._forks) + return self._forks.value + + @property + def forks_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._forks_count) + return self._forks_count.value + + @property + def forks_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._forks_url) + return self._forks_url.value + + @property + def full_name(self): + """ + :type: string + """ + self._completeIfNotSet(self._full_name) + return self._full_name.value + + @property + def git_commits_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._git_commits_url) + return self._git_commits_url.value + + @property + def git_refs_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._git_refs_url) + return self._git_refs_url.value + + @property + def git_tags_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._git_tags_url) + return self._git_tags_url.value + + @property + def git_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._git_url) + return self._git_url.value + + @property + def has_downloads(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_downloads) + return self._has_downloads.value + + @property + def has_issues(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_issues) + return self._has_issues.value + + @property + def has_projects(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_projects) + return self._has_projects.value + + @property + def has_wiki(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_wiki) + return self._has_wiki.value + + @property + def homepage(self): + """ + :type: string + """ + self._completeIfNotSet(self._homepage) + return self._homepage.value + + @property + def hooks_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._hooks_url) + return self._hooks_url.value + + @property + def html_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._html_url) + return self._html_url.value + + @property + def id(self): + """ + :type: integer + """ + self._completeIfNotSet(self._id) + return self._id.value + + @property + def is_template(self): + """ + :type: bool + """ + self._completeIfNotSet(self._is_template) + return self._is_template.value + + @property + def issue_comment_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._issue_comment_url) + return self._issue_comment_url.value + + @property + def issue_events_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._issue_events_url) + return self._issue_events_url.value + + @property + def issues_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._issues_url) + return self._issues_url.value + + @property + def keys_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._keys_url) + return self._keys_url.value + + @property + def labels_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._labels_url) + return self._labels_url.value + + @property + def language(self): + """ + :type: string + """ + self._completeIfNotSet(self._language) + return self._language.value + + @property + def languages_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._languages_url) + return self._languages_url.value + + @property + def master_branch(self): + """ + :type: string + """ + self._completeIfNotSet(self._master_branch) + return self._master_branch.value + + @property + def merges_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._merges_url) + return self._merges_url.value + + @property + def milestones_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._milestones_url) + return self._milestones_url.value + + @property + def mirror_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._mirror_url) + return self._mirror_url.value + + @property + def name(self): + """ + :type: string + """ + self._completeIfNotSet(self._name) + return self._name.value + + @property + def network_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._network_count) + return self._network_count.value + + @property + def notifications_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._notifications_url) + return self._notifications_url.value + + @property + def open_issues(self): + """ + :type: integer + """ + self._completeIfNotSet(self._open_issues) + return self._open_issues.value + + @property + def open_issues_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._open_issues_count) + return self._open_issues_count.value + + @property + def organization(self): + """ + :type: :class:`github.Organization.Organization` + """ + self._completeIfNotSet(self._organization) + return self._organization.value + + @property + def owner(self): + """ + :type: :class:`github.NamedUser.NamedUser` + """ + self._completeIfNotSet(self._owner) + return self._owner.value + + @property + def parent(self): + """ + :type: :class:`github.Repository.Repository` + """ + self._completeIfNotSet(self._parent) + return self._parent.value + + @property + def permissions(self): + """ + :type: :class:`github.Permissions.Permissions` + """ + self._completeIfNotSet(self._permissions) + return self._permissions.value + + @property + def private(self): + """ + :type: bool + """ + self._completeIfNotSet(self._private) + return self._private.value + + @property + def pulls_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._pulls_url) + return self._pulls_url.value + + @property + def pushed_at(self): + """ + :type: datetime.datetime + """ + self._completeIfNotSet(self._pushed_at) + return self._pushed_at.value + + @property + def size(self): + """ + :type: integer + """ + self._completeIfNotSet(self._size) + return self._size.value + + @property + def source(self): + """ + :type: :class:`github.Repository.Repository` + """ + self._completeIfNotSet(self._source) + return self._source.value + + @property + def ssh_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._ssh_url) + return self._ssh_url.value + + @property + def stargazers_count(self): + """ + :type: integer + """ + self._completeIfNotSet( + self._stargazers_count + ) # pragma no cover (Should be covered) + return self._stargazers_count.value # pragma no cover (Should be covered) + + @property + def stargazers_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._stargazers_url) + return self._stargazers_url.value + + @property + def statuses_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._statuses_url) + return self._statuses_url.value + + @property + def subscribers_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._subscribers_url) + return self._subscribers_url.value + + @property + def subscribers_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._subscribers_count) + return self._subscribers_count.value + + @property + def subscription_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._subscription_url) + return self._subscription_url.value + + @property + def svn_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._svn_url) + return self._svn_url.value + + @property + def tags_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._tags_url) + return self._tags_url.value + + @property + def teams_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._teams_url) + return self._teams_url.value + + @property + def topics(self): + """ + :type: list of strings + """ + self._completeIfNotSet(self._topics) + return self._topics.value + + @property + def trees_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._trees_url) + return self._trees_url.value + + @property + def updated_at(self): + """ + :type: datetime.datetime + """ + self._completeIfNotSet(self._updated_at) + return self._updated_at.value + + @property + def url(self): + """ + :type: string + """ + self._completeIfNotSet(self._url) + return self._url.value + + @property + def watchers(self): + """ + :type: integer + """ + self._completeIfNotSet(self._watchers) + return self._watchers.value + + @property + def watchers_count(self): + """ + :type: integer + """ + self._completeIfNotSet(self._watchers_count) + return self._watchers_count.value + + def add_to_collaborators(self, collaborator, permission=github.GithubObject.NotSet): + """ + :calls: `PUT /repos/:owner/:repo/collaborators/:user `_ + :param collaborator: string or :class:`github.NamedUser.NamedUser` + :param permission: string 'pull', 'push' or 'admin' + :rtype: None + """ + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, str + ), collaborator + assert permission is github.GithubObject.NotSet or isinstance( + permission, str + ), permission + + if isinstance(collaborator, github.NamedUser.NamedUser): + collaborator = collaborator._identity + + if permission is not github.GithubObject.NotSet: + put_parameters = {"permission": permission} + else: + put_parameters = None + + headers, data = self._requester.requestJsonAndCheck( + "PUT", self.url + "/collaborators/" + collaborator, input=put_parameters + ) + # return an invitation object if there's data returned by the API. If data is empty + # there's a pending invitation for the given user. + return ( + github.Invitation.Invitation(self._requester, headers, data, completed=True) + if data is not None + else None + ) + + def get_collaborator_permission(self, collaborator): + """ + :calls: `GET /repos/:owner/:repo/collaborators/:username/permission `_ + :param collaborator: string or :class:`github.NamedUser.NamedUser` + :rtype: string + """ + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, str + ), collaborator + if isinstance(collaborator, github.NamedUser.NamedUser): + collaborator = collaborator._identity + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/collaborators/" + collaborator + "/permission", + ) + return data["permission"] + + def get_pending_invitations(self): + """ + :calls: `GET /repos/:owner/:repo/invitations `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Invitation.Invitation` + """ + return github.PaginatedList.PaginatedList( + github.Invitation.Invitation, + self._requester, + self.url + "/invitations", + None, + ) + + def remove_invitation(self, invite_id): + """ + :calls: `DELETE /repos/:owner/:repo/invitations/:invitation_id `_ + :rtype: None + """ + assert isinstance(invite_id, int), invite_id + + headers, data = self._requester.requestJsonAndCheck( + "DELETE", self.url + "/invitations/" + str(invite_id) + ) + + def compare(self, base, head): + """ + :calls: `GET /repos/:owner/:repo/compare/:base...:head `_ + :param base: string + :param head: string + :rtype: :class:`github.Comparison.Comparison` + """ + assert isinstance(base, str), base + assert isinstance(head, str), head + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/compare/" + base + "..." + head + ) + return github.Comparison.Comparison( + self._requester, headers, data, completed=True + ) + + def create_git_blob(self, content, encoding): + """ + :calls: `POST /repos/:owner/:repo/git/blobs `_ + :param content: string + :param encoding: string + :rtype: :class:`github.GitBlob.GitBlob` + """ + assert isinstance(content, str), content + assert isinstance(encoding, str), encoding + post_parameters = { + "content": content, + "encoding": encoding, + } + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/blobs", input=post_parameters + ) + return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) + + def create_git_commit( + self, + message, + tree, + parents, + author=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/git/commits `_ + :param message: string + :param tree: :class:`github.GitTree.GitTree` + :param parents: list of :class:`github.GitCommit.GitCommit` + :param author: :class:`github.InputGitAuthor.InputGitAuthor` + :param committer: :class:`github.InputGitAuthor.InputGitAuthor` + :rtype: :class:`github.GitCommit.GitCommit` + """ + assert isinstance(message, str), message + assert isinstance(tree, github.GitTree.GitTree), tree + assert all( + isinstance(element, github.GitCommit.GitCommit) for element in parents + ), parents + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ), author + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ), committer + post_parameters = { + "message": message, + "tree": tree._identity, + "parents": [element._identity for element in parents], + } + if author is not github.GithubObject.NotSet: + post_parameters["author"] = author._identity + if committer is not github.GithubObject.NotSet: + post_parameters["committer"] = committer._identity + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/commits", input=post_parameters + ) + return github.GitCommit.GitCommit( + self._requester, headers, data, completed=True + ) + + def create_git_ref(self, ref, sha): + """ + :calls: `POST /repos/:owner/:repo/git/refs `_ + :param ref: string + :param sha: string + :rtype: :class:`github.GitRef.GitRef` + """ + assert isinstance(ref, str), ref + assert isinstance(sha, str), sha + post_parameters = { + "ref": ref, + "sha": sha, + } + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/refs", input=post_parameters + ) + return github.GitRef.GitRef(self._requester, headers, data, completed=True) + + def create_git_tag_and_release( + self, + tag, + tag_message, + release_name, + release_message, + object, + type, + tagger=github.GithubObject.NotSet, + draft=False, + prerelease=False, + ): + self.create_git_tag(tag, tag_message, object, type, tagger) + return self.create_git_release( + tag, + release_name, + release_message, + draft, + prerelease, + target_commitish=object, + ) + + def create_git_release( + self, + tag, + name, + message, + draft=False, + prerelease=False, + target_commitish=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/releases `_ + :param tag: string + :param name: string + :param message: string + :param draft: bool + :param prerelease: bool + :param target_commitish: string or :class:`github.Branch.Branch` or :class:`github.Commit.Commit` or :class:`github.GitCommit.GitCommit` + :rtype: :class:`github.GitRelease.GitRelease` + """ + assert isinstance(tag, str), tag + assert isinstance(name, str), name + assert isinstance(message, str), message + assert isinstance(draft, bool), draft + assert isinstance(prerelease, bool), prerelease + assert target_commitish is github.GithubObject.NotSet or isinstance( + target_commitish, + ( + str, + github.Branch.Branch, + github.Commit.Commit, + github.GitCommit.GitCommit, + ), + ), target_commitish + post_parameters = { + "tag_name": tag, + "name": name, + "body": message, + "draft": draft, + "prerelease": prerelease, + } + if isinstance(target_commitish, str): + post_parameters["target_commitish"] = target_commitish + elif isinstance(target_commitish, github.Branch.Branch): + post_parameters["target_commitish"] = target_commitish.name + elif isinstance( + target_commitish, (github.Commit.Commit, github.GitCommit.GitCommit) + ): + post_parameters["target_commitish"] = target_commitish.sha + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/releases", input=post_parameters + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True + ) + + def create_git_tag( + self, tag, message, object, type, tagger=github.GithubObject.NotSet + ): + """ + :calls: `POST /repos/:owner/:repo/git/tags `_ + :param tag: string + :param message: string + :param object: string + :param type: string + :param tagger: :class:`github.InputGitAuthor.InputGitAuthor` + :rtype: :class:`github.GitTag.GitTag` + """ + assert isinstance(tag, str), tag + assert isinstance(message, str), message + assert isinstance(object, str), object + assert isinstance(type, str), type + assert tagger is github.GithubObject.NotSet or isinstance( + tagger, github.InputGitAuthor + ), tagger + post_parameters = { + "tag": tag, + "message": message, + "object": object, + "type": type, + } + if tagger is not github.GithubObject.NotSet: + post_parameters["tagger"] = tagger._identity + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/tags", input=post_parameters + ) + return github.GitTag.GitTag(self._requester, headers, data, completed=True) + + def create_git_tree(self, tree, base_tree=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/git/trees `_ + :param tree: list of :class:`github.InputGitTreeElement.InputGitTreeElement` + :param base_tree: :class:`github.GitTree.GitTree` + :rtype: :class:`github.GitTree.GitTree` + """ + assert all( + isinstance(element, github.InputGitTreeElement) for element in tree + ), tree + assert base_tree is github.GithubObject.NotSet or isinstance( + base_tree, github.GitTree.GitTree + ), base_tree + post_parameters = { + "tree": [element._identity for element in tree], + } + if base_tree is not github.GithubObject.NotSet: + post_parameters["base_tree"] = base_tree._identity + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/git/trees", input=post_parameters + ) + return github.GitTree.GitTree(self._requester, headers, data, completed=True) + + def create_hook( + self, + name, + config, + events=github.GithubObject.NotSet, + active=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/hooks `_ + :param name: string + :param config: dict + :param events: list of string + :param active: bool + :rtype: :class:`github.Hook.Hook` + """ + assert isinstance(name, str), name + assert isinstance(config, dict), config + assert events is github.GithubObject.NotSet or all( + isinstance(element, str) for element in events + ), events + assert active is github.GithubObject.NotSet or isinstance(active, bool), active + post_parameters = { + "name": name, + "config": config, + } + if events is not github.GithubObject.NotSet: + post_parameters["events"] = events + if active is not github.GithubObject.NotSet: + post_parameters["active"] = active + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/hooks", input=post_parameters + ) + return github.Hook.Hook(self._requester, headers, data, completed=True) + + def create_issue( + self, + title, + body=github.GithubObject.NotSet, + assignee=github.GithubObject.NotSet, + milestone=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + assignees=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/issues `_ + :param title: string + :param body: string + :param assignee: string or :class:`github.NamedUser.NamedUser` + :param assignees: list of string or :class:`github.NamedUser.NamedUser` + :param milestone: :class:`github.Milestone.Milestone` + :param labels: list of :class:`github.Label.Label` + :rtype: :class:`github.Issue.Issue` + """ + assert isinstance(title, str), title + assert body is github.GithubObject.NotSet or isinstance(body, str), body + assert ( + assignee is github.GithubObject.NotSet + or isinstance(assignee, github.NamedUser.NamedUser) + or isinstance(assignee, str) + ), assignee + assert assignees is github.GithubObject.NotSet or all( + isinstance(element, github.NamedUser.NamedUser) or isinstance(element, str) + for element in assignees + ), assignees + assert milestone is github.GithubObject.NotSet or isinstance( + milestone, github.Milestone.Milestone + ), milestone + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) or isinstance(element, str) + for element in labels + ), labels + + post_parameters = { + "title": title, + } + if body is not github.GithubObject.NotSet: + post_parameters["body"] = body + if assignee is not github.GithubObject.NotSet: + if isinstance(assignee, str): + post_parameters["assignee"] = assignee + else: + post_parameters["assignee"] = assignee._identity + if assignees is not github.GithubObject.NotSet: + post_parameters["assignees"] = [ + element._identity + if isinstance(element, github.NamedUser.NamedUser) + else element + for element in assignees + ] + if milestone is not github.GithubObject.NotSet: + post_parameters["milestone"] = milestone._identity + if labels is not github.GithubObject.NotSet: + post_parameters["labels"] = [ + element.name if isinstance(element, github.Label.Label) else element + for element in labels + ] + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/issues", input=post_parameters + ) + return github.Issue.Issue(self._requester, headers, data, completed=True) + + def create_key(self, title, key, read_only=False): + """ + :calls: `POST /repos/:owner/:repo/keys `_ + :param title: string + :param key: string + :param read_only: bool + :rtype: :class:`github.RepositoryKey.RepositoryKey` + """ + assert isinstance(title, str), title + assert isinstance(key, str), key + assert isinstance(read_only, bool), read_only + post_parameters = { + "title": title, + "key": key, + "read_only": read_only, + } + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/keys", input=post_parameters + ) + return github.RepositoryKey.RepositoryKey( + self._requester, headers, data, completed=True + ) + + def create_label(self, name, color, description=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/labels `_ + :param name: string + :param color: string + :param description: string + :rtype: :class:`github.Label.Label` + """ + assert isinstance(name, str), name + assert isinstance(color, str), color + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + post_parameters = { + "name": name, + "color": color, + } + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + headers, data = self._requester.requestJsonAndCheck( + "POST", + self.url + "/labels", + input=post_parameters, + headers={"Accept": Consts.mediaTypeLabelDescriptionSearchPreview}, + ) + return github.Label.Label(self._requester, headers, data, completed=True) + + def create_milestone( + self, + title, + state=github.GithubObject.NotSet, + description=github.GithubObject.NotSet, + due_on=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/:owner/:repo/milestones `_ + :param title: string + :param state: string + :param description: string + :param due_on: datetime + :rtype: :class:`github.Milestone.Milestone` + """ + assert isinstance(title, str), title + assert state is github.GithubObject.NotSet or isinstance(state, str), state + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert due_on is github.GithubObject.NotSet or isinstance( + due_on, (datetime.datetime, datetime.date) + ), due_on + post_parameters = { + "title": title, + } + if state is not github.GithubObject.NotSet: + post_parameters["state"] = state + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if due_on is not github.GithubObject.NotSet: + if isinstance(due_on, datetime.date): + post_parameters["due_on"] = due_on.strftime("%Y-%m-%dT%H:%M:%SZ") + else: + post_parameters["due_on"] = due_on.isoformat() + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/milestones", input=post_parameters + ) + return github.Milestone.Milestone( + self._requester, headers, data, completed=True + ) + + def create_project(self, name, body=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/projects `_ + :param name: string + :param body: string + :rtype: :class:`github.Project.Project` + """ + assert isinstance(name, str), name + assert body is github.GithubObject.NotSet or isinstance(body, str), body + post_parameters = { + "name": name, + } + import_header = {"Accept": Consts.mediaTypeProjectsPreview} + if body is not github.GithubObject.NotSet: + post_parameters["body"] = body + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/projects", headers=import_header, input=post_parameters + ) + return github.Project.Project(self._requester, headers, data, completed=True) + + def create_pull(self, *args, **kwds): + """ + :calls: `POST /repos/:owner/:repo/pulls `_ + :param title: string + :param body: string + :param issue: :class:`github.Issue.Issue` + :param base: string + :param head: string + :param maintainer_can_modify: bool + :rtype: :class:`github.PullRequest.PullRequest` + """ + if len(args) + len(kwds) >= 4: + return self.__create_pull_1(*args, **kwds) + else: + return self.__create_pull_2(*args, **kwds) + + def __create_pull_1( + self, title, body, base, head, maintainer_can_modify=github.GithubObject.NotSet + ): + assert isinstance(title, str), title + assert isinstance(body, str), body + assert isinstance(base, str), base + assert isinstance(head, str), head + assert maintainer_can_modify is github.GithubObject.NotSet or isinstance( + maintainer_can_modify, bool + ), maintainer_can_modify + if maintainer_can_modify is not github.GithubObject.NotSet: + return self.__create_pull( + title=title, + body=body, + base=base, + head=head, + maintainer_can_modify=maintainer_can_modify, + ) + else: + return self.__create_pull(title=title, body=body, base=base, head=head) + + def __create_pull_2(self, issue, base, head): + assert isinstance(issue, github.Issue.Issue), issue + assert isinstance(base, str), base + assert isinstance(head, str), head + return self.__create_pull(issue=issue._identity, base=base, head=head) + + def __create_pull(self, **kwds): + post_parameters = kwds + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/pulls", input=post_parameters + ) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True + ) + + def create_source_import( + self, + vcs, + vcs_url, + vcs_username=github.GithubObject.NotSet, + vcs_password=github.GithubObject.NotSet, + ): + """ + :calls: `PUT /repos/:owner/:repo/import `_ + :param vcs: string + :param vcs_url: string + :param vcs_username: string + :param vcs_password: string + :rtype: :class:`github.SourceImport.SourceImport` + """ + assert isinstance(vcs, str), vcs + assert isinstance(vcs_url, str), vcs_url + assert vcs_username is github.GithubObject.NotSet or isinstance( + vcs_username, str + ), vcs_username + assert vcs_password is github.GithubObject.NotSet or isinstance( + vcs_password, str + ), vcs_password + put_parameters = {"vcs": vcs, "vcs_url": vcs_url} + + if vcs_username is not github.GithubObject.NotSet: + put_parameters["vcs_username"] = vcs_username + + if vcs_password is not github.GithubObject.NotSet: + put_parameters["vcs_password"] = vcs_password + + import_header = {"Accept": Consts.mediaTypeImportPreview} + + headers, data = self._requester.requestJsonAndCheck( + "PUT", self.url + "/import", headers=import_header, input=put_parameters + ) + + return github.SourceImport.SourceImport( + self._requester, headers, data, completed=False + ) + + def delete(self): + """ + :calls: `DELETE /repos/:owner/:repo `_ + :rtype: None + """ + headers, data = self._requester.requestJsonAndCheck("DELETE", self.url) + + def edit( + self, + name=None, + description=github.GithubObject.NotSet, + homepage=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, + has_issues=github.GithubObject.NotSet, + has_projects=github.GithubObject.NotSet, + has_wiki=github.GithubObject.NotSet, + has_downloads=github.GithubObject.NotSet, + default_branch=github.GithubObject.NotSet, + allow_squash_merge=github.GithubObject.NotSet, + allow_merge_commit=github.GithubObject.NotSet, + allow_rebase_merge=github.GithubObject.NotSet, + delete_branch_on_merge=github.GithubObject.NotSet, + archived=github.GithubObject.NotSet, + ): + """ + :calls: `PATCH /repos/:owner/:repo `_ + :param name: string + :param description: string + :param homepage: string + :param private: bool + :param has_issues: bool + :param has_projects: bool + :param has_wiki: bool + :param has_downloads: bool + :param default_branch: string + :param allow_squash_merge: bool + :param allow_merge_commit: bool + :param allow_rebase_merge: bool + :param delete_branch_on_merge: bool + :param archived: bool. Unarchiving repositories is currently not supported through API (https://developer.github.com/v3/repos/#edit) + :rtype: None + """ + if name is None: + name = self.name + assert isinstance(name, str), name + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert homepage is github.GithubObject.NotSet or isinstance( + homepage, str + ), homepage + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + assert has_issues is github.GithubObject.NotSet or isinstance( + has_issues, bool + ), has_issues + assert has_projects is github.GithubObject.NotSet or isinstance( + has_projects, bool + ), has_projects + assert has_wiki is github.GithubObject.NotSet or isinstance( + has_wiki, bool + ), has_wiki + assert has_downloads is github.GithubObject.NotSet or isinstance( + has_downloads, bool + ), has_downloads + assert default_branch is github.GithubObject.NotSet or isinstance( + default_branch, str + ), default_branch + assert allow_squash_merge is github.GithubObject.NotSet or isinstance( + allow_squash_merge, bool + ), allow_squash_merge + assert allow_merge_commit is github.GithubObject.NotSet or isinstance( + allow_merge_commit, bool + ), allow_merge_commit + assert allow_rebase_merge is github.GithubObject.NotSet or isinstance( + allow_rebase_merge, bool + ), allow_rebase_merge + assert delete_branch_on_merge is github.GithubObject.NotSet or isinstance( + delete_branch_on_merge, bool + ), delete_branch_on_merge + assert archived is github.GithubObject.NotSet or ( + isinstance(archived, bool) and archived is True + ), archived + post_parameters = { + "name": name, + } + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if homepage is not github.GithubObject.NotSet: + post_parameters["homepage"] = homepage + if private is not github.GithubObject.NotSet: + post_parameters["private"] = private + if has_issues is not github.GithubObject.NotSet: + post_parameters["has_issues"] = has_issues + if has_projects is not github.GithubObject.NotSet: + post_parameters["has_projects"] = has_projects + if has_wiki is not github.GithubObject.NotSet: + post_parameters["has_wiki"] = has_wiki + if has_downloads is not github.GithubObject.NotSet: + post_parameters["has_downloads"] = has_downloads + if default_branch is not github.GithubObject.NotSet: + post_parameters["default_branch"] = default_branch + if allow_squash_merge is not github.GithubObject.NotSet: + post_parameters["allow_squash_merge"] = allow_squash_merge + if allow_merge_commit is not github.GithubObject.NotSet: + post_parameters["allow_merge_commit"] = allow_merge_commit + if allow_rebase_merge is not github.GithubObject.NotSet: + post_parameters["allow_rebase_merge"] = allow_rebase_merge + if delete_branch_on_merge is not github.GithubObject.NotSet: + post_parameters["delete_branch_on_merge"] = delete_branch_on_merge + if archived is not github.GithubObject.NotSet: + post_parameters["archived"] = archived + headers, data = self._requester.requestJsonAndCheck( + "PATCH", self.url, input=post_parameters + ) + self._useAttributes(data) + + def get_archive_link(self, archive_format, ref=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/:archive_format/:ref `_ + :param archive_format: string + :param ref: string + :rtype: string + """ + assert isinstance(archive_format, str), archive_format + assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref + url = self.url + "/" + archive_format + if ref is not github.GithubObject.NotSet: + url += "/" + ref + headers, data = self._requester.requestJsonAndCheck("GET", url) + return headers["location"] + + def get_assignees(self): + """ + :calls: `GET /repos/:owner/:repo/assignees `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, self._requester, self.url + "/assignees", None + ) + + def get_branch(self, branch): + """ + :calls: `GET /repos/:owner/:repo/branches/:branch `_ + :param branch: string + :rtype: :class:`github.Branch.Branch` + """ + assert isinstance(branch, str), branch + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/branches/" + branch + ) + return github.Branch.Branch(self._requester, headers, data, completed=True) + + def get_branches(self): + """ + :calls: `GET /repos/:owner/:repo/branches `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Branch.Branch` + """ + return github.PaginatedList.PaginatedList( + github.Branch.Branch, self._requester, self.url + "/branches", None + ) + + def get_collaborators(self, affiliation=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/collaborators `_ + :param affiliation: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + + url_parameters = dict() + allowed_affiliations = ["outside", "direct", "all"] + if affiliation is not github.GithubObject.NotSet: + assert isinstance(affiliation, str), affiliation + assert ( + affiliation in allowed_affiliations + ), "Affiliation can be one of " + ", ".join(allowed_affiliations) + url_parameters["affiliation"] = affiliation + + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, + self._requester, + self.url + "/collaborators", + url_parameters, + ) + + def get_comment(self, id): + """ + :calls: `GET /repos/:owner/:repo/comments/:id `_ + :param id: integer + :rtype: :class:`github.CommitComment.CommitComment` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/comments/" + str(id) + ) + return github.CommitComment.CommitComment( + self._requester, headers, data, completed=True + ) + + def get_comments(self): + """ + :calls: `GET /repos/:owner/:repo/comments `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.CommitComment.CommitComment` + """ + return github.PaginatedList.PaginatedList( + github.CommitComment.CommitComment, + self._requester, + self.url + "/comments", + None, + ) + + def get_commit(self, sha): + """ + :calls: `GET /repos/:owner/:repo/commits/:sha `_ + :param sha: string + :rtype: :class:`github.Commit.Commit` + """ + assert isinstance(sha, str), sha + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/commits/" + sha + ) + return github.Commit.Commit(self._requester, headers, data, completed=True) + + def get_commits( + self, + sha=github.GithubObject.NotSet, + path=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + until=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/commits `_ + :param sha: string + :param path: string + :param since: datetime.datetime + :param until: datetime.datetime + :param author: string or :class:`github.NamedUser.NamedUser` or :class:`github.AuthenticatedUser.AuthenticatedUser` + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Commit.Commit` + """ + assert sha is github.GithubObject.NotSet or isinstance(sha, str), sha + assert path is github.GithubObject.NotSet or isinstance(path, str), path + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert until is github.GithubObject.NotSet or isinstance( + until, datetime.datetime + ), until + assert author is github.GithubObject.NotSet or isinstance( + author, + ( + str, + github.NamedUser.NamedUser, + github.AuthenticatedUser.AuthenticatedUser, + ), + ), author + url_parameters = dict() + if sha is not github.GithubObject.NotSet: + url_parameters["sha"] = sha + if path is not github.GithubObject.NotSet: + url_parameters["path"] = path + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + if until is not github.GithubObject.NotSet: + url_parameters["until"] = until.strftime("%Y-%m-%dT%H:%M:%SZ") + if author is not github.GithubObject.NotSet: + if isinstance( + author, + ( + github.NamedUser.NamedUser, + github.AuthenticatedUser.AuthenticatedUser, + ), + ): + url_parameters["author"] = author.login + else: + url_parameters["author"] = author + return github.PaginatedList.PaginatedList( + github.Commit.Commit, self._requester, self.url + "/commits", url_parameters + ) + + def get_contents(self, path, ref=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/contents/:path `_ + :param path: string + :param ref: string + :rtype: :class:`github.ContentFile.ContentFile` or a list of them + """ + assert isinstance(path, str), path + assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref + # Path of '/' should be the empty string. + if path == "/": + path = "" + url_parameters = dict() + if ref is not github.GithubObject.NotSet: + url_parameters["ref"] = ref + headers, data = self._requester.requestJsonAndCheck( + "GET", + self.url + "/contents/" + urllib.parse.quote(path), + parameters=url_parameters, + ) + + # Handle 302 redirect response + if headers.get("status") == "302 Found" and headers.get("location"): + headers, data = self._requester.requestJsonAndCheck( + "GET", headers["location"], parameters=url_parameters + ) + + if isinstance(data, list): + return [ + # Lazy completion only makes sense for files. See discussion + # here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130 + github.ContentFile.ContentFile( + self._requester, headers, item, completed=(item["type"] != "file") + ) + for item in data + ] + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True + ) + + def get_top_referrers(self): + """ + :calls: `GET /repos/:owner/:repo/traffic/popular/referrers `_ + :rtype: :class:`list` of :class:`github.Referrer.Referrer` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/traffic/popular/referrers" + ) + if isinstance(data, list): + return [ + github.Referrer.Referrer(self._requester, headers, item, completed=True) + for item in data + ] + + def get_top_paths(self): + """ + :calls: `GET /repos/:owner/:repo/traffic/popular/paths `_ + :rtype: :class:`list` of :class:`github.Path.Path` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/traffic/popular/paths" + ) + if isinstance(data, list): + return [ + github.Path.Path(self._requester, headers, item, completed=True) + for item in data + ] + + def get_views_traffic(self, per=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/traffic/views `_ + :param per: string, must be one of day or week, day by default + :rtype: None or list of :class:`github.View.View` + """ + assert per is github.GithubObject.NotSet or ( + isinstance(per, str) and (per == "day" or per == "week") + ), "per must be day or week, day by default" + url_parameters = dict() + if per is not github.GithubObject.NotSet: + url_parameters["per"] = per + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/traffic/views", parameters=url_parameters + ) + if ( + (isinstance(data, dict)) + and ("views" in data) + and (isinstance(data["views"], list)) + ): + data["views"] = [ + github.View.View(self._requester, headers, item, completed=True) + for item in data["views"] + ] + return data + + def get_clones_traffic(self, per=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/traffic/clones `_ + :param per: string, must be one of day or week, day by default + :rtype: None or list of :class:`github.Clone.Clone` + """ + assert per is github.GithubObject.NotSet or ( + isinstance(per, str) and (per == "day" or per == "week") + ), "per must be day or week, day by default" + url_parameters = dict() + if per is not github.GithubObject.NotSet: + url_parameters["per"] = per + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/traffic/clones", parameters=url_parameters + ) + if ( + (isinstance(data, dict)) + and ("clones" in data) + and (isinstance(data["clones"], list)) + ): + data["clones"] = [ + github.Clones.Clones(self._requester, headers, item, completed=True) + for item in data["clones"] + ] + return data + + def get_projects(self, state=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/projects `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Project.Project` + :param state: string + """ + + url_parameters = dict() + if state is not github.GithubObject.NotSet: + url_parameters["state"] = state + + return github.PaginatedList.PaginatedList( + github.Project.Project, + self._requester, + self.url + "/projects", + url_parameters, + {"Accept": Consts.mediaTypeProjectsPreview}, + ) + + def create_file( + self, + path, + message, + content, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): + """Create a file in this repository. + + :calls: `PUT /repos/:owner/:repo/contents/:path `_ + :param path: string, (required), path of the file in the repository + :param message: string, (required), commit message + :param content: string, (required), the actual data in the file + :param branch: string, (optional), branch to create the commit on. Defaults to the default branch of the repository + :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. + :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. + :rtype: { + 'content': :class:`ContentFile `:, + 'commit': :class:`Commit `} + """ + assert isinstance(path, str) + assert isinstance(message, str) + assert isinstance(content, (str, bytes)) + assert branch is github.GithubObject.NotSet or isinstance(branch, str) + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ) + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ) + + if not isinstance(content, bytes): + content = content.encode("utf-8") + content = b64encode(content).decode("utf-8") + put_parameters = {"message": message, "content": content} + + if branch is not github.GithubObject.NotSet: + put_parameters["branch"] = branch + if author is not github.GithubObject.NotSet: + put_parameters["author"] = author._identity + if committer is not github.GithubObject.NotSet: + put_parameters["committer"] = committer._identity + + headers, data = self._requester.requestJsonAndCheck( + "PUT", + self.url + "/contents/" + urllib.parse.quote(path), + input=put_parameters, + ) + + return { + "content": github.ContentFile.ContentFile( + self._requester, headers, data["content"], completed=False + ), + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + } + + def update_file( + self, + path, + message, + content, + sha, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): + """This method updates a file in a repository + + :calls: `PUT /repos/:owner/:repo/contents/:path `_ + :param path: string, Required. The content path. + :param message: string, Required. The commit message. + :param content: string, Required. The updated file content, either base64 encoded, or ready to be encoded. + :param sha: string, Required. The blob SHA of the file being replaced. + :param branch: string. The branch name. Default: the repository’s default branch (usually master) + :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. + :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. + :rtype: { + 'content': :class:`ContentFile `:, + 'commit': :class:`Commit `} + """ + assert isinstance(path, str) + assert isinstance(message, str) + assert isinstance(content, (str, bytes)) + assert isinstance(sha, str) + assert branch is github.GithubObject.NotSet or isinstance(branch, str) + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ) + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ) + + if not isinstance(content, bytes): + content = content.encode("utf-8") + content = b64encode(content).decode("utf-8") + + put_parameters = {"message": message, "content": content, "sha": sha} + + if branch is not github.GithubObject.NotSet: + put_parameters["branch"] = branch + if author is not github.GithubObject.NotSet: + put_parameters["author"] = author._identity + if committer is not github.GithubObject.NotSet: + put_parameters["committer"] = committer._identity + + headers, data = self._requester.requestJsonAndCheck( + "PUT", + self.url + "/contents/" + urllib.parse.quote(path), + input=put_parameters, + ) + + return { + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + "content": github.ContentFile.ContentFile( + self._requester, headers, data["content"], completed=False + ), + } + + def delete_file( + self, + path, + message, + sha, + branch=github.GithubObject.NotSet, + committer=github.GithubObject.NotSet, + author=github.GithubObject.NotSet, + ): + """This method deletes a file in a repository + + :calls: `DELETE /repos/:owner/:repo/contents/:path `_ + :param path: string, Required. The content path. + :param message: string, Required. The commit message. + :param sha: string, Required. The blob SHA of the file being replaced. + :param branch: string. The branch name. Default: the repository’s default branch (usually master) + :param committer: InputGitAuthor, (optional), if no information is given the authenticated user's information will be used. You must specify both a name and email. + :param author: InputGitAuthor, (optional), if omitted this will be filled in with committer information. If passed, you must specify both a name and email. + :rtype: { + 'content': :class:`null `:, + 'commit': :class:`Commit `} + """ + assert isinstance(path, str), "path must be str/unicode object" + assert isinstance(message, str), "message must be str/unicode object" + assert isinstance(sha, str), "sha must be a str/unicode object" + assert branch is github.GithubObject.NotSet or isinstance( + branch, str + ), "branch must be a str/unicode object" + assert author is github.GithubObject.NotSet or isinstance( + author, github.InputGitAuthor + ), "author must be a github.InputGitAuthor object" + assert committer is github.GithubObject.NotSet or isinstance( + committer, github.InputGitAuthor + ), "committer must be a github.InputGitAuthor object" + + url_parameters = {"message": message, "sha": sha} + if branch is not github.GithubObject.NotSet: + url_parameters["branch"] = branch + if author is not github.GithubObject.NotSet: + url_parameters["author"] = author._identity + if committer is not github.GithubObject.NotSet: + url_parameters["committer"] = committer._identity + + headers, data = self._requester.requestJsonAndCheck( + "DELETE", + self.url + "/contents/" + urllib.parse.quote(path), + input=url_parameters, + ) + + return { + "commit": github.Commit.Commit( + self._requester, headers, data["commit"], completed=True + ), + "content": github.GithubObject.NotSet, + } + + @deprecated( + reason=""" + Repository.get_dir_contents() is deprecated, use + Repository.get_contents() instead. + """ + ) + def get_dir_contents(self, path, ref=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/contents/:path `_ + :param path: string + :param ref: string + :rtype: list of :class:`github.ContentFile.ContentFile` + """ + return self.get_contents(path, ref=ref) + + def get_contributors(self, anon=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/contributors `_ + :param anon: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + url_parameters = dict() + if anon is not github.GithubObject.NotSet: + url_parameters["anon"] = anon + + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, + self._requester, + self.url + "/contributors", + url_parameters, + ) + + def get_download(self, id): + """ + :calls: `GET /repos/:owner/:repo/downloads/:id `_ + :param id: integer + :rtype: :class:`github.Download.Download` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/downloads/" + str(id) + ) + return github.Download.Download(self._requester, headers, data, completed=True) + + def get_downloads(self): + """ + :calls: `GET /repos/:owner/:repo/downloads `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Download.Download` + """ + return github.PaginatedList.PaginatedList( + github.Download.Download, self._requester, self.url + "/downloads", None + ) + + def get_events(self): + """ + :calls: `GET /repos/:owner/:repo/events `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` + """ + return github.PaginatedList.PaginatedList( + github.Event.Event, self._requester, self.url + "/events", None + ) + + def get_forks(self): + """ + :calls: `GET /repos/:owner/:repo/forks `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` + """ + return github.PaginatedList.PaginatedList( + Repository, self._requester, self.url + "/forks", None + ) + + def create_fork(self, organization=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/forks `_ + :param organization: string or "none" or "*" + :rtype: :class:`github.Repository.Repository` + """ + assert organization is github.GithubObject.NotSet or isinstance( + organization, str + ), organization + post_parameters = {} + if organization is not github.GithubObject.NotSet: + post_parameters["organization"] = organization + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/forks", input=post_parameters, + ) + return Repository(self._requester, headers, data, completed=True) + + def get_git_blob(self, sha): + """ + :calls: `GET /repos/:owner/:repo/git/blobs/:sha `_ + :param sha: string + :rtype: :class:`github.GitBlob.GitBlob` + """ + assert isinstance(sha, str), sha + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/git/blobs/" + sha + ) + return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) + + def get_git_commit(self, sha): + """ + :calls: `GET /repos/:owner/:repo/git/commits/:sha `_ + :param sha: string + :rtype: :class:`github.GitCommit.GitCommit` + """ + assert isinstance(sha, str), sha + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/git/commits/" + sha + ) + return github.GitCommit.GitCommit( + self._requester, headers, data, completed=True + ) + + def get_git_ref(self, ref): + """ + :calls: `GET /repos/:owner/:repo/git/refs/:ref `_ + :param ref: string + :rtype: :class:`github.GitRef.GitRef` + """ + prefix = "/git/refs/" + if not self._requester.FIX_REPO_GET_GIT_REF: + prefix = "/git/" + assert isinstance(ref, str), ref + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + prefix + ref + ) + return github.GitRef.GitRef(self._requester, headers, data, completed=True) + + def get_git_refs(self): + """ + :calls: `GET /repos/:owner/:repo/git/refs `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRef.GitRef` + """ + return github.PaginatedList.PaginatedList( + github.GitRef.GitRef, self._requester, self.url + "/git/refs", None + ) + + def get_git_tag(self, sha): + """ + :calls: `GET /repos/:owner/:repo/git/tags/:sha `_ + :param sha: string + :rtype: :class:`github.GitTag.GitTag` + """ + assert isinstance(sha, str), sha + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/git/tags/" + sha + ) + return github.GitTag.GitTag(self._requester, headers, data, completed=True) + + def get_git_tree(self, sha, recursive=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/git/trees/:sha `_ + :param sha: string + :param recursive: bool + :rtype: :class:`github.GitTree.GitTree` + """ + assert isinstance(sha, str), sha + assert recursive is github.GithubObject.NotSet or isinstance( + recursive, bool + ), recursive + url_parameters = dict() + if recursive is not github.GithubObject.NotSet and recursive: + # GitHub API requires the recursive parameter be set to 1. + url_parameters["recursive"] = 1 + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/git/trees/" + sha, parameters=url_parameters + ) + return github.GitTree.GitTree(self._requester, headers, data, completed=True) + + def get_hook(self, id): + """ + :calls: `GET /repos/:owner/:repo/hooks/:id `_ + :param id: integer + :rtype: :class:`github.Hook.Hook` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/hooks/" + str(id) + ) + return github.Hook.Hook(self._requester, headers, data, completed=True) + + def get_hooks(self): + """ + :calls: `GET /repos/:owner/:repo/hooks `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook` + """ + return github.PaginatedList.PaginatedList( + github.Hook.Hook, self._requester, self.url + "/hooks", None + ) + + def get_issue(self, number): + """ + :calls: `GET /repos/:owner/:repo/issues/:number `_ + :param number: integer + :rtype: :class:`github.Issue.Issue` + """ + assert isinstance(number, int), number + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/issues/" + str(number) + ) + return github.Issue.Issue(self._requester, headers, data, completed=True) + + def get_issues( + self, + milestone=github.GithubObject.NotSet, + state=github.GithubObject.NotSet, + assignee=github.GithubObject.NotSet, + mentioned=github.GithubObject.NotSet, + labels=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + creator=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/issues `_ + :param milestone: :class:`github.Milestone.Milestone` or "none" or "*" + :param state: string. `open`, `closed`, or `all`. If this is not set the GitHub API default behavior will be used. At the moment this is to return only open issues. This might change anytime on GitHub API side and it could be clever to explicitly specify the state value. + :param assignee: string or :class:`github.NamedUser.NamedUser` or "none" or "*" + :param mentioned: :class:`github.NamedUser.NamedUser` + :param labels: list of string or :class:`github.Label.Label` + :param sort: string + :param direction: string + :param since: datetime.datetime + :param creator: string or :class:`github.NamedUser.NamedUser` + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` + """ + assert ( + milestone is github.GithubObject.NotSet + or milestone == "*" + or milestone == "none" + or isinstance(milestone, github.Milestone.Milestone) + ), milestone + assert state is github.GithubObject.NotSet or isinstance(state, str), state + assert ( + assignee is github.GithubObject.NotSet + or isinstance(assignee, github.NamedUser.NamedUser) + or isinstance(assignee, str) + ), assignee + assert mentioned is github.GithubObject.NotSet or isinstance( + mentioned, github.NamedUser.NamedUser + ), mentioned + assert labels is github.GithubObject.NotSet or all( + isinstance(element, github.Label.Label) or isinstance(element, str) + for element in labels + ), labels + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert ( + creator is github.GithubObject.NotSet + or isinstance(creator, github.NamedUser.NamedUser) + or isinstance(creator, str) + ), creator + url_parameters = dict() + if milestone is not github.GithubObject.NotSet: + if isinstance(milestone, str): + url_parameters["milestone"] = milestone + else: + url_parameters["milestone"] = milestone._identity + if state is not github.GithubObject.NotSet: + url_parameters["state"] = state + if assignee is not github.GithubObject.NotSet: + if isinstance(assignee, str): + url_parameters["assignee"] = assignee + else: + url_parameters["assignee"] = assignee._identity + if mentioned is not github.GithubObject.NotSet: + url_parameters["mentioned"] = mentioned._identity + if labels is not github.GithubObject.NotSet: + url_parameters["labels"] = ",".join( + [ + label.name if isinstance(label, github.Label.Label) else label + for label in labels + ] + ) + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + if creator is not github.GithubObject.NotSet: + if isinstance(creator, str): + url_parameters["creator"] = creator + else: + url_parameters["creator"] = creator._identity + return github.PaginatedList.PaginatedList( + github.Issue.Issue, self._requester, self.url + "/issues", url_parameters + ) + + def get_issues_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/issues/comments `_ + :param sort: string + :param direction: string + :param since: datetime.datetime + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueComment.IssueComment` + """ + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + url_parameters = dict() + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + return github.PaginatedList.PaginatedList( + github.IssueComment.IssueComment, + self._requester, + self.url + "/issues/comments", + url_parameters, + ) + + def get_issues_event(self, id): + """ + :calls: `GET /repos/:owner/:repo/issues/events/:id `_ + :param id: integer + :rtype: :class:`github.IssueEvent.IssueEvent` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", + self.url + "/issues/events/" + str(id), + headers={"Accept": Consts.mediaTypeLockReasonPreview}, + ) + return github.IssueEvent.IssueEvent( + self._requester, headers, data, completed=True + ) + + def get_issues_events(self): + """ + :calls: `GET /repos/:owner/:repo/issues/events `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.IssueEvent.IssueEvent` + """ + return github.PaginatedList.PaginatedList( + github.IssueEvent.IssueEvent, + self._requester, + self.url + "/issues/events", + None, + headers={"Accept": Consts.mediaTypeLockReasonPreview}, + ) + + def get_key(self, id): + """ + :calls: `GET /repos/:owner/:repo/keys/:id `_ + :param id: integer + :rtype: :class:`github.RepositoryKey.RepositoryKey` + """ + assert isinstance(id, int), id + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/keys/" + str(id) + ) + return github.RepositoryKey.RepositoryKey( + self._requester, headers, data, completed=True + ) + + def get_keys(self): + """ + :calls: `GET /repos/:owner/:repo/keys `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.RepositoryKey.RepositoryKey` + """ + return github.PaginatedList.PaginatedList( + github.RepositoryKey.RepositoryKey, + self._requester, + self.url + "/keys", + None, + ) + + def get_label(self, name): + """ + :calls: `GET /repos/:owner/:repo/labels/:name `_ + :param name: string + :rtype: :class:`github.Label.Label` + """ + assert isinstance(name, str), name + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/labels/" + urllib.parse.quote(name) + ) + return github.Label.Label(self._requester, headers, data, completed=True) + + def get_labels(self): + """ + :calls: `GET /repos/:owner/:repo/labels `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` + """ + return github.PaginatedList.PaginatedList( + github.Label.Label, self._requester, self.url + "/labels", None + ) + + def get_languages(self): + """ + :calls: `GET /repos/:owner/:repo/languages `_ + :rtype: dict of string to integer + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/languages" + ) + return data + + def get_license(self): + """ + :calls: `GET /repos/:owner/:repo/license `_ + :rtype: :class:`github.ContentFile.ContentFile` + """ + + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/license" + ) + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True + ) + + def get_milestone(self, number): + """ + :calls: `GET /repos/:owner/:repo/milestones/:number `_ + :param number: integer + :rtype: :class:`github.Milestone.Milestone` + """ + assert isinstance(number, int), number + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/milestones/" + str(number) + ) + return github.Milestone.Milestone( + self._requester, headers, data, completed=True + ) + + def get_milestones( + self, + state=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/milestones `_ + :param state: string + :param sort: string + :param direction: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Milestone.Milestone` + """ + assert state is github.GithubObject.NotSet or isinstance(state, str), state + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + url_parameters = dict() + if state is not github.GithubObject.NotSet: + url_parameters["state"] = state + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + return github.PaginatedList.PaginatedList( + github.Milestone.Milestone, + self._requester, + self.url + "/milestones", + url_parameters, + ) + + def get_network_events(self): + """ + :calls: `GET /networks/:owner/:repo/events `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` + """ + return github.PaginatedList.PaginatedList( + github.Event.Event, + self._requester, + "/networks/" + self.owner.login + "/" + self.name + "/events", + None, + ) + + def get_pull(self, number): + """ + :calls: `GET /repos/:owner/:repo/pulls/:number `_ + :param number: integer + :rtype: :class:`github.PullRequest.PullRequest` + """ + assert isinstance(number, int), number + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/pulls/" + str(number) + ) + return github.PullRequest.PullRequest( + self._requester, headers, data, completed=True + ) + + def get_pulls( + self, + state=github.GithubObject.NotSet, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + base=github.GithubObject.NotSet, + head=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/pulls `_ + :param state: string + :param sort: string + :param direction: string + :param base: string + :param head: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequest.PullRequest` + """ + assert state is github.GithubObject.NotSet or isinstance(state, str), state + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert base is github.GithubObject.NotSet or isinstance(base, str), base + assert head is github.GithubObject.NotSet or isinstance(head, str), head + url_parameters = dict() + if state is not github.GithubObject.NotSet: + url_parameters["state"] = state + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + if base is not github.GithubObject.NotSet: + url_parameters["base"] = base + if head is not github.GithubObject.NotSet: + url_parameters["head"] = head + return github.PaginatedList.PaginatedList( + github.PullRequest.PullRequest, + self._requester, + self.url + "/pulls", + url_parameters, + ) + + def get_pulls_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/pulls/comments `_ + :param sort: string + :param direction: string + :param since: datetime.datetime + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` + """ + return self.get_pulls_review_comments(sort, direction, since) + + def get_pulls_review_comments( + self, + sort=github.GithubObject.NotSet, + direction=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/pulls/comments `_ + :param sort: string + :param direction: string + :param since: datetime.datetime + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestComment.PullRequestComment` + """ + assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + url_parameters = dict() + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction + if since is not github.GithubObject.NotSet: + url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + return github.PaginatedList.PaginatedList( + github.PullRequestComment.PullRequestComment, + self._requester, + self.url + "/pulls/comments", + url_parameters, + ) + + def get_readme(self, ref=github.GithubObject.NotSet): + """ + :calls: `GET /repos/:owner/:repo/readme `_ + :param ref: string + :rtype: :class:`github.ContentFile.ContentFile` + """ + assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref + url_parameters = dict() + if ref is not github.GithubObject.NotSet: + url_parameters["ref"] = ref + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/readme", parameters=url_parameters + ) + return github.ContentFile.ContentFile( + self._requester, headers, data, completed=True + ) + + def get_source_import(self): + """ + :calls: `GET /repos/:owner/:repo/import `_ + :rtype: :class:`github.SourceImport.SourceImport` + """ + import_header = {"Accept": Consts.mediaTypeImportPreview} + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/import", headers=import_header, + ) + if not data: + return None + else: + return github.SourceImport.SourceImport( + self._requester, headers, data, completed=True + ) + + def get_stargazers(self): + """ + :calls: `GET /repos/:owner/:repo/stargazers `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, self._requester, self.url + "/stargazers", None + ) + + def get_stargazers_with_dates(self): + """ + :calls: `GET /repos/:owner/:repo/stargazers `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Stargazer.Stargazer` + """ + return github.PaginatedList.PaginatedList( + github.Stargazer.Stargazer, + self._requester, + self.url + "/stargazers", + None, + headers={"Accept": Consts.mediaTypeStarringPreview}, + ) + + def get_stats_contributors(self): + """ + :calls: `GET /repos/:owner/:repo/stats/contributors `_ + :rtype: None or list of :class:`github.StatsContributor.StatsContributor` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/contributors" + ) + if not data: + return None + else: + return [ + github.StatsContributor.StatsContributor( + self._requester, headers, attributes, completed=True + ) + for attributes in data + ] + + def get_stats_commit_activity(self): + """ + :calls: `GET /repos/:owner/:repo/stats/commit_activity `_ + :rtype: None or list of :class:`github.StatsCommitActivity.StatsCommitActivity` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/commit_activity" + ) + if not data: + return None + else: + return [ + github.StatsCommitActivity.StatsCommitActivity( + self._requester, headers, attributes, completed=True + ) + for attributes in data + ] + + def get_stats_code_frequency(self): + """ + :calls: `GET /repos/:owner/:repo/stats/code_frequency `_ + :rtype: None or list of :class:`github.StatsCodeFrequency.StatsCodeFrequency` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/code_frequency" + ) + if not data: + return None + else: + return [ + github.StatsCodeFrequency.StatsCodeFrequency( + self._requester, headers, attributes, completed=True + ) + for attributes in data + ] + + def get_stats_participation(self): + """ + :calls: `GET /repos/:owner/:repo/stats/participation `_ + :rtype: None or :class:`github.StatsParticipation.StatsParticipation` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/participation" + ) + if not data: + return None + else: + return github.StatsParticipation.StatsParticipation( + self._requester, headers, data, completed=True + ) + + def get_stats_punch_card(self): + """ + :calls: `GET /repos/:owner/:repo/stats/punch_card `_ + :rtype: None or :class:`github.StatsPunchCard.StatsPunchCard` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/stats/punch_card" + ) + if not data: + return None + else: + return github.StatsPunchCard.StatsPunchCard( + self._requester, headers, data, completed=True + ) + + def get_subscribers(self): + """ + :calls: `GET /repos/:owner/:repo/subscribers `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, self._requester, self.url + "/subscribers", None + ) + + def get_tags(self): + """ + :calls: `GET /repos/:owner/:repo/tags `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Tag.Tag` + """ + return github.PaginatedList.PaginatedList( + github.Tag.Tag, self._requester, self.url + "/tags", None + ) + + def get_releases(self): + """ + :calls: `GET /repos/:owner/:repo/releases `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRelease.GitRelease` + """ + return github.PaginatedList.PaginatedList( + github.GitRelease.GitRelease, self._requester, self.url + "/releases", None + ) + + def get_release(self, id): + """ + :calls: `GET /repos/:owner/:repo/releases/:id `_ + :param id: int (release id), str (tag name) + :rtype: None or :class:`github.GitRelease.GitRelease` + """ + if isinstance(id, int): + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/releases/" + str(id) + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True + ) + elif isinstance(id, str): + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/releases/tags/" + id + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True + ) + + def get_latest_release(self): + """ + :calls: `GET /repos/:owner/:repo/releases/latest `_ + :rtype: :class:`github.GitRelease.GitRelease` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/releases/latest" + ) + return github.GitRelease.GitRelease( + self._requester, headers, data, completed=True + ) + + def get_teams(self): + """ + :calls: `GET /repos/:owner/:repo/teams `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` + """ + return github.PaginatedList.PaginatedList( + github.Team.Team, self._requester, self.url + "/teams", None + ) + + def get_topics(self): + """ + :calls: `GET /repos/:owner/:repo/topics `_ + :rtype: list of strings + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", + self.url + "/topics", + headers={"Accept": Consts.mediaTypeTopicsPreview}, + ) + return data["names"] + + def get_watchers(self): + """ + :calls: `GET /repos/:owner/:repo/watchers `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` + """ + return github.PaginatedList.PaginatedList( + github.NamedUser.NamedUser, self._requester, self.url + "/watchers", None + ) + + def has_in_assignees(self, assignee): + """ + :calls: `GET /repos/:owner/:repo/assignees/:assignee `_ + :param assignee: string or :class:`github.NamedUser.NamedUser` + :rtype: bool + """ + assert isinstance(assignee, github.NamedUser.NamedUser) or isinstance( + assignee, str + ), assignee + + if isinstance(assignee, github.NamedUser.NamedUser): + assignee = assignee._identity + + status, headers, data = self._requester.requestJson( + "GET", self.url + "/assignees/" + assignee + ) + return status == 204 + + def has_in_collaborators(self, collaborator): + """ + :calls: `GET /repos/:owner/:repo/collaborators/:user `_ + :param collaborator: string or :class:`github.NamedUser.NamedUser` + :rtype: bool + """ + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, str + ), collaborator + + if isinstance(collaborator, github.NamedUser.NamedUser): + collaborator = collaborator._identity + + status, headers, data = self._requester.requestJson( + "GET", self.url + "/collaborators/" + collaborator + ) + return status == 204 + + def _legacy_convert_issue(self, attributes): + convertedAttributes = { + "number": attributes["number"], + "url": "/repos" + urllib.parse.urlparse(attributes["html_url"]).path, + "user": { + "login": attributes["user"], + "url": "/users/" + attributes["user"], + }, + } + if "labels" in attributes: # pragma no branch + convertedAttributes["labels"] = [ + {"name": label} for label in attributes["labels"] + ] + for attr in ("title", "created_at", "comments", "body", "updated_at", "state"): + if attr in attributes: # pragma no branch + convertedAttributes[attr] = attributes[attr] + return convertedAttributes + + def legacy_search_issues(self, state, keyword): + """ + :calls: `GET /legacy/issues/search/:owner/:repository/:state/:keyword `_ + :param state: "open" or "closed" + :param keyword: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` + """ + assert state in ["open", "closed"], state + assert isinstance(keyword, str), keyword + headers, data = self._requester.requestJsonAndCheck( + "GET", + "/legacy/issues/search/" + + self.owner.login + + "/" + + self.name + + "/" + + state + + "/" + + urllib.parse.quote(keyword), + ) + return [ + github.Issue.Issue( + self._requester, + headers, + self._legacy_convert_issue(element), + completed=False, + ) + for element in data["issues"] + ] + + def get_notifications( + self, + all=github.GithubObject.NotSet, + participating=github.GithubObject.NotSet, + since=github.GithubObject.NotSet, + before=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/:owner/:repo/notifications `_ + :param all: bool + :param participating: bool + :param since: datetime.datetime + :param before: datetime.datetime + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification` + """ + + assert all is github.GithubObject.NotSet or isinstance(all, bool), all + assert participating is github.GithubObject.NotSet or isinstance( + participating, bool + ), participating + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert before is github.GithubObject.NotSet or isinstance( + before, datetime.datetime + ), before + + params = dict() + if all is not github.GithubObject.NotSet: + params["all"] = all + if participating is not github.GithubObject.NotSet: + params["participating"] = participating + if since is not github.GithubObject.NotSet: + params["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") + if before is not github.GithubObject.NotSet: + params["before"] = before.strftime("%Y-%m-%dT%H:%M:%SZ") + + return github.PaginatedList.PaginatedList( + github.Notification.Notification, + self._requester, + self.url + "/notifications", + params, + ) + + def mark_notifications_as_read(self, last_read_at=datetime.datetime.utcnow()): + """ + :calls: `PUT /repos/:owner/:repo/notifications `_ + :param last_read_at: datetime + """ + assert isinstance(last_read_at, datetime.datetime) + put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} + + headers, data = self._requester.requestJsonAndCheck( + "PUT", self.url + "/notifications", input=put_parameters + ) + + def merge(self, base, head, commit_message=github.GithubObject.NotSet): + """ + :calls: `POST /repos/:owner/:repo/merges `_ + :param base: string + :param head: string + :param commit_message: string + :rtype: :class:`github.Commit.Commit` + """ + assert isinstance(base, str), base + assert isinstance(head, str), head + assert commit_message is github.GithubObject.NotSet or isinstance( + commit_message, str + ), commit_message + post_parameters = { + "base": base, + "head": head, + } + if commit_message is not github.GithubObject.NotSet: + post_parameters["commit_message"] = commit_message + headers, data = self._requester.requestJsonAndCheck( + "POST", self.url + "/merges", input=post_parameters + ) + if data is None: + return None + else: + return github.Commit.Commit(self._requester, headers, data, completed=True) + + def replace_topics(self, topics): + """ + :calls: `PUT /repos/:owner/:repo/topics `_ + :param topics: list of strings + :rtype: None + """ + post_parameters = {"names": topics} + headers, data = self._requester.requestJsonAndCheck( + "PUT", + self.url + "/topics", + headers={"Accept": Consts.mediaTypeTopicsPreview}, + input=post_parameters, + ) + + def get_vulnerability_alert(self): + """ + :calls: `GET /repos/:owner/:repo/vulnerability-alerts `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "GET", + self.url + "/vulnerability-alerts", + headers={"Accept": Consts.vulnerabilityAlertsPreview}, + ) + return status == 204 + + def enable_vulnerability_alert(self): + """ + :calls: `PUT /repos/:owner/:repo/vulnerability-alerts `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "PUT", + self.url + "/vulnerability-alerts", + headers={"Accept": Consts.vulnerabilityAlertsPreview}, + ) + return status == 204 + + def disable_vulnerability_alert(self): + """ + :calls: `DELETE /repos/:owner/:repo/vulnerability-alerts `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "DELETE", + self.url + "/vulnerability-alerts", + headers={"Accept": Consts.vulnerabilityAlertsPreview}, + ) + return status == 204 + + def enable_automated_security_fixes(self): + """ + :calls: `PUT /repos/:owner/:repo/automated-security-fixes `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "PUT", + self.url + "/automated-security-fixes", + headers={"Accept": Consts.automatedSecurityFixes}, + ) + return status == 204 + + def disable_automated_security_fixes(self): + """ + :calls: `DELETE /repos/:owner/:repo/automated-security-fixes `_ + :rtype: bool + """ + status, _, _ = self._requester.requestJson( + "DELETE", + self.url + "/automated-security-fixes", + headers={"Accept": Consts.automatedSecurityFixes}, + ) + return status == 204 + + def remove_from_collaborators(self, collaborator): + """ + :calls: `DELETE /repos/:owner/:repo/collaborators/:user `_ + :param collaborator: string or :class:`github.NamedUser.NamedUser` + :rtype: None + """ + assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance( + collaborator, str + ), collaborator + + if isinstance(collaborator, github.NamedUser.NamedUser): + collaborator = collaborator._identity + + headers, data = self._requester.requestJsonAndCheck( + "DELETE", self.url + "/collaborators/" + collaborator + ) + + def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet): + """ + :calls: `POST /hub `_ + :param event: string + :param callback: string + :param secret: string + :rtype: None + """ + return self._hub("subscribe", event, callback, secret) + + def unsubscribe_from_hub(self, event, callback): + """ + :calls: `POST /hub `_ + :param event: string + :param callback: string + :param secret: string + :rtype: None + """ + return self._hub("unsubscribe", event, callback, github.GithubObject.NotSet) + + def _hub(self, mode, event, callback, secret): + assert isinstance(mode, str), mode + assert isinstance(event, str), event + assert isinstance(callback, str), callback + assert secret is github.GithubObject.NotSet or isinstance(secret, str), secret + + post_parameters = collections.OrderedDict() + post_parameters["hub.callback"] = callback + post_parameters["hub.topic"] = ( + "https://github.com/" + self.full_name + "/events/" + event + ) + post_parameters["hub.mode"] = mode + if secret is not github.GithubObject.NotSet: + post_parameters["hub.secret"] = secret + + headers, output = self._requester.requestMultipartAndCheck( + "POST", "/hub", input=post_parameters + ) + + @property + def _identity(self): + return self.owner.login + "/" + self.name + + def get_release_asset(self, id): + assert isinstance(id, (int)), id + + resp_headers, data = self._requester.requestJsonAndCheck( + "GET", self.url + "/releases/assets/" + str(id) + ) + return github.GitReleaseAsset.GitReleaseAsset( + self._requester, resp_headers, data, completed=True + ) + + def _initAttributes(self): + self._allow_merge_commit = github.GithubObject.NotSet + self._allow_rebase_merge = github.GithubObject.NotSet + self._allow_squash_merge = github.GithubObject.NotSet + self._archived = github.GithubObject.NotSet + self._archive_url = github.GithubObject.NotSet + self._assignees_url = github.GithubObject.NotSet + self._blobs_url = github.GithubObject.NotSet + self._branches_url = github.GithubObject.NotSet + self._clone_url = github.GithubObject.NotSet + self._collaborators_url = github.GithubObject.NotSet + self._comments_url = github.GithubObject.NotSet + self._commits_url = github.GithubObject.NotSet + self._compare_url = github.GithubObject.NotSet + self._contents_url = github.GithubObject.NotSet + self._contributors_url = github.GithubObject.NotSet + self._created_at = github.GithubObject.NotSet + self._default_branch = github.GithubObject.NotSet + self._delete_branch_on_merge = github.GithubObject.NotSet + self._description = github.GithubObject.NotSet + self._downloads_url = github.GithubObject.NotSet + self._events_url = github.GithubObject.NotSet + self._fork = github.GithubObject.NotSet + self._forks = github.GithubObject.NotSet + self._forks_count = github.GithubObject.NotSet + self._forks_url = github.GithubObject.NotSet + self._full_name = github.GithubObject.NotSet + self._git_commits_url = github.GithubObject.NotSet + self._git_refs_url = github.GithubObject.NotSet + self._git_tags_url = github.GithubObject.NotSet + self._git_url = github.GithubObject.NotSet + self._has_downloads = github.GithubObject.NotSet + self._has_issues = github.GithubObject.NotSet + self._has_projects = github.GithubObject.NotSet + self._has_wiki = github.GithubObject.NotSet + self._homepage = github.GithubObject.NotSet + self._hooks_url = github.GithubObject.NotSet + self._html_url = github.GithubObject.NotSet + self._id = github.GithubObject.NotSet + self._is_template = github.GithubObject.NotSet + self._issue_comment_url = github.GithubObject.NotSet + self._issue_events_url = github.GithubObject.NotSet + self._issues_url = github.GithubObject.NotSet + self._keys_url = github.GithubObject.NotSet + self._labels_url = github.GithubObject.NotSet + self._language = github.GithubObject.NotSet + self._languages_url = github.GithubObject.NotSet + self._master_branch = github.GithubObject.NotSet + self._merges_url = github.GithubObject.NotSet + self._milestones_url = github.GithubObject.NotSet + self._mirror_url = github.GithubObject.NotSet + self._name = github.GithubObject.NotSet + self._network_count = github.GithubObject.NotSet + self._notifications_url = github.GithubObject.NotSet + self._open_issues = github.GithubObject.NotSet + self._open_issues_count = github.GithubObject.NotSet + self._organization = github.GithubObject.NotSet + self._owner = github.GithubObject.NotSet + self._parent = github.GithubObject.NotSet + self._permissions = github.GithubObject.NotSet + self._private = github.GithubObject.NotSet + self._pulls_url = github.GithubObject.NotSet + self._pushed_at = github.GithubObject.NotSet + self._size = github.GithubObject.NotSet + self._source = github.GithubObject.NotSet + self._ssh_url = github.GithubObject.NotSet + self._stargazers_count = github.GithubObject.NotSet + self._stargazers_url = github.GithubObject.NotSet + self._statuses_url = github.GithubObject.NotSet + self._subscribers_url = github.GithubObject.NotSet + self._subscribers_count = github.GithubObject.NotSet + self._subscription_url = github.GithubObject.NotSet + self._svn_url = github.GithubObject.NotSet + self._tags_url = github.GithubObject.NotSet + self._teams_url = github.GithubObject.NotSet + self._topics = github.GithubObject.NotSet + self._trees_url = github.GithubObject.NotSet + self._updated_at = github.GithubObject.NotSet + self._url = github.GithubObject.NotSet + self._watchers = github.GithubObject.NotSet + self._watchers_count = github.GithubObject.NotSet + + def _useAttributes(self, attributes): + if "allow_merge_commit" in attributes: # pragma no branch + self._allow_merge_commit = self._makeBoolAttribute( + attributes["allow_merge_commit"] + ) + if "allow_rebase_merge" in attributes: # pragma no branch + self._allow_rebase_merge = self._makeBoolAttribute( + attributes["allow_rebase_merge"] + ) + if "allow_squash_merge" in attributes: # pragma no branch + self._allow_squash_merge = self._makeBoolAttribute( + attributes["allow_squash_merge"] + ) + if "archived" in attributes: # pragma no branch + self._archived = self._makeBoolAttribute(attributes["archived"]) + if "archive_url" in attributes: # pragma no branch + self._archive_url = self._makeStringAttribute(attributes["archive_url"]) + if "assignees_url" in attributes: # pragma no branch + self._assignees_url = self._makeStringAttribute(attributes["assignees_url"]) + if "blobs_url" in attributes: # pragma no branch + self._blobs_url = self._makeStringAttribute(attributes["blobs_url"]) + if "branches_url" in attributes: # pragma no branch + self._branches_url = self._makeStringAttribute(attributes["branches_url"]) + if "clone_url" in attributes: # pragma no branch + self._clone_url = self._makeStringAttribute(attributes["clone_url"]) + if "collaborators_url" in attributes: # pragma no branch + self._collaborators_url = self._makeStringAttribute( + attributes["collaborators_url"] + ) + if "comments_url" in attributes: # pragma no branch + self._comments_url = self._makeStringAttribute(attributes["comments_url"]) + if "commits_url" in attributes: # pragma no branch + self._commits_url = self._makeStringAttribute(attributes["commits_url"]) + if "compare_url" in attributes: # pragma no branch + self._compare_url = self._makeStringAttribute(attributes["compare_url"]) + if "contents_url" in attributes: # pragma no branch + self._contents_url = self._makeStringAttribute(attributes["contents_url"]) + if "contributors_url" in attributes: # pragma no branch + self._contributors_url = self._makeStringAttribute( + attributes["contributors_url"] + ) + if "created_at" in attributes: # pragma no branch + self._created_at = self._makeDatetimeAttribute(attributes["created_at"]) + if "default_branch" in attributes: # pragma no branch + self._default_branch = self._makeStringAttribute( + attributes["default_branch"] + ) + if "delete_branch_on_merge" in attributes: # pragma no branch + self._delete_branch_on_merge = self._makeBoolAttribute( + attributes["delete_branch_on_merge"] + ) + if "description" in attributes: # pragma no branch + self._description = self._makeStringAttribute(attributes["description"]) + if "downloads_url" in attributes: # pragma no branch + self._downloads_url = self._makeStringAttribute(attributes["downloads_url"]) + if "events_url" in attributes: # pragma no branch + self._events_url = self._makeStringAttribute(attributes["events_url"]) + if "fork" in attributes: # pragma no branch + self._fork = self._makeBoolAttribute(attributes["fork"]) + if "forks" in attributes: # pragma no branch + self._forks = self._makeIntAttribute(attributes["forks"]) + if "forks_count" in attributes: # pragma no branch + self._forks_count = self._makeIntAttribute(attributes["forks_count"]) + if "forks_url" in attributes: # pragma no branch + self._forks_url = self._makeStringAttribute(attributes["forks_url"]) + if "full_name" in attributes: # pragma no branch + self._full_name = self._makeStringAttribute(attributes["full_name"]) + if "git_commits_url" in attributes: # pragma no branch + self._git_commits_url = self._makeStringAttribute( + attributes["git_commits_url"] + ) + if "git_refs_url" in attributes: # pragma no branch + self._git_refs_url = self._makeStringAttribute(attributes["git_refs_url"]) + if "git_tags_url" in attributes: # pragma no branch + self._git_tags_url = self._makeStringAttribute(attributes["git_tags_url"]) + if "git_url" in attributes: # pragma no branch + self._git_url = self._makeStringAttribute(attributes["git_url"]) + if "has_downloads" in attributes: # pragma no branch + self._has_downloads = self._makeBoolAttribute(attributes["has_downloads"]) + if "has_issues" in attributes: # pragma no branch + self._has_issues = self._makeBoolAttribute(attributes["has_issues"]) + if "has_projects" in attributes: # pragma no branch + self._has_projects = self._makeBoolAttribute(attributes["has_projects"]) + if "has_wiki" in attributes: # pragma no branch + self._has_wiki = self._makeBoolAttribute(attributes["has_wiki"]) + if "homepage" in attributes: # pragma no branch + self._homepage = self._makeStringAttribute(attributes["homepage"]) + if "hooks_url" in attributes: # pragma no branch + self._hooks_url = self._makeStringAttribute(attributes["hooks_url"]) + if "html_url" in attributes: # pragma no branch + self._html_url = self._makeStringAttribute(attributes["html_url"]) + if "id" in attributes: # pragma no branch + self._id = self._makeIntAttribute(attributes["id"]) + if "is_template" in attributes: # pragma no branch + self._is_template = self._makeBoolAttribute(attributes["is_template"]) + if "issue_comment_url" in attributes: # pragma no branch + self._issue_comment_url = self._makeStringAttribute( + attributes["issue_comment_url"] + ) + if "issue_events_url" in attributes: # pragma no branch + self._issue_events_url = self._makeStringAttribute( + attributes["issue_events_url"] + ) + if "issues_url" in attributes: # pragma no branch + self._issues_url = self._makeStringAttribute(attributes["issues_url"]) + if "keys_url" in attributes: # pragma no branch + self._keys_url = self._makeStringAttribute(attributes["keys_url"]) + if "labels_url" in attributes: # pragma no branch + self._labels_url = self._makeStringAttribute(attributes["labels_url"]) + if "language" in attributes: # pragma no branch + self._language = self._makeStringAttribute(attributes["language"]) + if "languages_url" in attributes: # pragma no branch + self._languages_url = self._makeStringAttribute(attributes["languages_url"]) + if "master_branch" in attributes: # pragma no branch + self._master_branch = self._makeStringAttribute(attributes["master_branch"]) + if "merges_url" in attributes: # pragma no branch + self._merges_url = self._makeStringAttribute(attributes["merges_url"]) + if "milestones_url" in attributes: # pragma no branch + self._milestones_url = self._makeStringAttribute( + attributes["milestones_url"] + ) + if "mirror_url" in attributes: # pragma no branch + self._mirror_url = self._makeStringAttribute(attributes["mirror_url"]) + if "name" in attributes: # pragma no branch + self._name = self._makeStringAttribute(attributes["name"]) + if "network_count" in attributes: # pragma no branch + self._network_count = self._makeIntAttribute(attributes["network_count"]) + if "notifications_url" in attributes: # pragma no branch + self._notifications_url = self._makeStringAttribute( + attributes["notifications_url"] + ) + if "open_issues" in attributes: # pragma no branch + self._open_issues = self._makeIntAttribute(attributes["open_issues"]) + if "open_issues_count" in attributes: # pragma no branch + self._open_issues_count = self._makeIntAttribute( + attributes["open_issues_count"] + ) + if "organization" in attributes: # pragma no branch + self._organization = self._makeClassAttribute( + github.Organization.Organization, attributes["organization"] + ) + if "owner" in attributes: # pragma no branch + self._owner = self._makeClassAttribute( + github.NamedUser.NamedUser, attributes["owner"] + ) + if "parent" in attributes: # pragma no branch + self._parent = self._makeClassAttribute(Repository, attributes["parent"]) + if "permissions" in attributes: # pragma no branch + self._permissions = self._makeClassAttribute( + github.Permissions.Permissions, attributes["permissions"] + ) + if "private" in attributes: # pragma no branch + self._private = self._makeBoolAttribute(attributes["private"]) + if "pulls_url" in attributes: # pragma no branch + self._pulls_url = self._makeStringAttribute(attributes["pulls_url"]) + if "pushed_at" in attributes: # pragma no branch + self._pushed_at = self._makeDatetimeAttribute(attributes["pushed_at"]) + if "size" in attributes: # pragma no branch + self._size = self._makeIntAttribute(attributes["size"]) + if "source" in attributes: # pragma no branch + self._source = self._makeClassAttribute(Repository, attributes["source"]) + if "ssh_url" in attributes: # pragma no branch + self._ssh_url = self._makeStringAttribute(attributes["ssh_url"]) + if "stargazers_count" in attributes: # pragma no branch + self._stargazers_count = self._makeIntAttribute( + attributes["stargazers_count"] + ) + if "stargazers_url" in attributes: # pragma no branch + self._stargazers_url = self._makeStringAttribute( + attributes["stargazers_url"] + ) + if "statuses_url" in attributes: # pragma no branch + self._statuses_url = self._makeStringAttribute(attributes["statuses_url"]) + if "subscribers_url" in attributes: # pragma no branch + self._subscribers_url = self._makeStringAttribute( + attributes["subscribers_url"] + ) + if "subscribers_count" in attributes: # pragma no branch + self._subscribers_count = self._makeIntAttribute( + attributes["subscribers_count"] + ) + if "subscription_url" in attributes: # pragma no branch + self._subscription_url = self._makeStringAttribute( + attributes["subscription_url"] + ) + if "svn_url" in attributes: # pragma no branch + self._svn_url = self._makeStringAttribute(attributes["svn_url"]) + if "tags_url" in attributes: # pragma no branch + self._tags_url = self._makeStringAttribute(attributes["tags_url"]) + if "teams_url" in attributes: # pragma no branch + self._teams_url = self._makeStringAttribute(attributes["teams_url"]) + if "trees_url" in attributes: # pragma no branch + self._trees_url = self._makeStringAttribute(attributes["trees_url"]) + if "topics" in attributes: # pragma no branch + self._topics = self._makeListOfStringsAttribute(attributes["topics"]) + if "updated_at" in attributes: # pragma no branch + self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"]) + if "url" in attributes: # pragma no branch + self._url = self._makeStringAttribute(attributes["url"]) + if "watchers" in attributes: # pragma no branch + self._watchers = self._makeIntAttribute(attributes["watchers"]) + if "watchers_count" in attributes: # pragma no branch + self._watchers_count = self._makeIntAttribute(attributes["watchers_count"]) From d8c105c362a89a9b4bc2183a5fc12c6194bdc147 Mon Sep 17 00:00:00 2001 From: Isac Souza Date: Tue, 29 Sep 2020 20:27:44 -0300 Subject: [PATCH 20/25] Fix formatting --- github/AuthenticatedUser.py | 10 +++++----- github/Organization.py | 10 +++++----- tests/AuthenticatedUser.py | 16 +++++++++++++--- tests/Organization.py | 16 +++++++++++++--- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 3d50493eac..18875a4f42 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -502,11 +502,11 @@ def create_fork(self, repo): ) def create_repo_from_template( - self, - name, - repo, - description=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, + self, + name, + repo, + description=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, ): """ :calls: `POST /repos/:template_owner/:template_repo/generate ` diff --git a/github/Organization.py b/github/Organization.py index 4bc02b70fa..3374b050ee 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -404,11 +404,11 @@ def create_fork(self, repo): ) def create_repo_from_template( - self, - name, - repo, - description=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, + self, + name, + repo, + description=github.GithubObject.NotSet, + private=github.GithubObject.NotSet, ): """self.name :calls: `POST /repos/:template_owner/:template_repo/generate `_ diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index 276d1b3a9f..624fc4b3e8 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -666,8 +666,13 @@ def testCreateFork(self): def testCreateRepoFromTemplate(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") - repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo) - self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/hello-world-docker-action-new") + repo = self.user.create_repo_from_template( + "hello-world-docker-action-new", template_repo + ) + self.assertEqual( + repo.url, + "https://api.github.com/repos/jacquev6/hello-world-docker-action-new", + ) self.assertEqual(repo.is_template, False) def testCreateRepoFromTemplateWithAllArguments(self): @@ -675,7 +680,12 @@ def testCreateRepoFromTemplateWithAllArguments(self): description = "My repo from template" private = True - repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) + repo = self.user.create_repo_from_template( + "hello-world-docker-action-new", + template_repo, + description=description, + private=private, + ) self.assertEqual(repo.description, description) self.assertTrue(repo.private) diff --git a/tests/Organization.py b/tests/Organization.py index 42151eeb03..aaae619fa9 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -359,8 +359,13 @@ def testCreateFork(self): def testCreateRepoFromTemplate(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") - repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo) - self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new") + repo = self.org.create_repo_from_template( + "hello-world-docker-action-new", template_repo + ) + self.assertEqual( + repo.url, + "https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new", + ) self.assertEqual(repo.is_template, False) def testCreateRepoFromTemplateWithAllArguments(self): @@ -368,7 +373,12 @@ def testCreateRepoFromTemplateWithAllArguments(self): description = "My repo from template" private = True - repo = self.org.create_repo_from_template("hello-world-docker-action-new", template_repo, description=description, private=private) + repo = self.org.create_repo_from_template( + "hello-world-docker-action-new", + template_repo, + description=description, + private=private, + ) self.assertEqual(repo.description, description) self.assertTrue(repo.private) From 6ddabf78bc642fba32a466a869f02319656a4753 Mon Sep 17 00:00:00 2001 From: KimSia Sim Date: Thu, 21 Oct 2021 20:14:19 +0800 Subject: [PATCH 21/25] =?UTF-8?q?=E2=99=BB=20Changes=20based=20on=20feedba?= =?UTF-8?q?ck=20at=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See link https://github.com/PyGithub/PyGithub/pull/2012/files/e35e31d537920d8c3d0ab389a374c8c6486e477e --- github/AuthenticatedUser.py | 211 ++++++++---------------------------- tests/AuthenticatedUser.py | 38 ++----- tests/Organization.py | 2 +- 3 files changed, 54 insertions(+), 197 deletions(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index f2c9f998ab..cd95812c0c 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -448,18 +448,12 @@ def create_authorization( isinstance(element, str) for element in scopes ), scopes assert note is github.GithubObject.NotSet or isinstance(note, str), note - assert note_url is github.GithubObject.NotSet or isinstance( - note_url, str - ), note_url - assert client_id is github.GithubObject.NotSet or isinstance( - client_id, str - ), client_id + assert note_url is github.GithubObject.NotSet or isinstance(note_url, str), note_url + assert client_id is github.GithubObject.NotSet or isinstance(client_id, str), client_id assert client_secret is github.GithubObject.NotSet or isinstance( client_secret, str ), client_secret - assert onetime_password is None or isinstance( - onetime_password, str - ), onetime_password + assert onetime_password is None or isinstance(onetime_password, str), onetime_password post_parameters = dict() if scopes is not github.GithubObject.NotSet: post_parameters["scopes"] = scopes @@ -483,9 +477,7 @@ def create_authorization( input=post_parameters, headers=request_header, ) - return github.Authorization.Authorization( - self._requester, headers, data, completed=True - ) + return github.Authorization.Authorization(self._requester, headers, data, completed=True) def create_fork(self, repo): """ @@ -497,9 +489,7 @@ def create_fork(self, repo): headers, data = self._requester.requestJsonAndCheck( "POST", f"/repos/{repo.owner.login}/{repo.name}/forks" ) - return github.Repository.Repository( - self._requester, headers, data, completed=True - ) + return github.Repository.Repository(self._requester, headers, data, completed=True) def create_repo_from_template( self, @@ -521,9 +511,7 @@ def create_repo_from_template( assert description is github.GithubObject.NotSet or isinstance( description, str ), description - assert private is github.GithubObject.NotSet or isinstance( - private, bool - ), private + assert private is github.GithubObject.NotSet or isinstance(private, bool), private post_parameters = { "name": name, "owner": self.login, @@ -534,54 +522,11 @@ def create_repo_from_template( post_parameters["private"] = private headers, data = self._requester.requestJsonAndCheck( "POST", - "/repos/" + repo.owner.login + "/" + repo.name + "/generate", + f"/repos/{repo.owner.login}/{repo.name}/generate", input=post_parameters, headers={"Accept": Consts.mediaTypeTemplatesPreview}, ) - return github.Repository.Repository( - self._requester, headers, data, completed=True - ) - - def create_repo_from_template( - self, - name, - repo, - description=github.GithubObject.NotSet, - private=github.GithubObject.NotSet, - ): - """ - :calls: `POST /repos/:template_owner/:template_repo/generate ` - :param name: string - :param repo :class:`github.Repository.Repository` - :param description: string - :param private: bool - :rtype: :class:`github.Repository.Repository` - """ - assert isinstance(name, str), name - assert isinstance(repo, github.Repository.Repository), repo - assert description is github.GithubObject.NotSet or isinstance( - description, str - ), description - assert private is github.GithubObject.NotSet or isinstance( - private, bool - ), private - post_parameters = { - "name": name, - "owner": self.login, - } - if description is not github.GithubObject.NotSet: - post_parameters["description"] = description - if private is not github.GithubObject.NotSet: - post_parameters["private"] = private - headers, data = self._requester.requestJsonAndCheck( - "POST", - "/repos/" + repo.owner.login + "/" + repo.name + "/generate", - input=post_parameters, - headers={"Accept": Consts.mediaTypeTemplatesPreview}, - ) - return github.Repository.Repository( - self._requester, headers, data, completed=True - ) + return github.Repository.Repository(self._requester, headers, data, completed=True) def create_gist(self, public, files, description=github.GithubObject.NotSet): """ @@ -604,9 +549,7 @@ def create_gist(self, public, files, description=github.GithubObject.NotSet): } if description is not github.GithubObject.NotSet: post_parameters["description"] = description - headers, data = self._requester.requestJsonAndCheck( - "POST", "/gists", input=post_parameters - ) + headers, data = self._requester.requestJsonAndCheck("POST", "/gists", input=post_parameters) return github.Gist.Gist(self._requester, headers, data, completed=True) def create_key(self, title, key): @@ -689,27 +632,17 @@ def create_repo( assert description is github.GithubObject.NotSet or isinstance( description, str ), description - assert homepage is github.GithubObject.NotSet or isinstance( - homepage, str - ), homepage - assert private is github.GithubObject.NotSet or isinstance( - private, bool - ), private - assert has_issues is github.GithubObject.NotSet or isinstance( - has_issues, bool - ), has_issues - assert has_wiki is github.GithubObject.NotSet or isinstance( - has_wiki, bool - ), has_wiki + assert homepage is github.GithubObject.NotSet or isinstance(homepage, str), homepage + assert private is github.GithubObject.NotSet or isinstance(private, bool), private + assert has_issues is github.GithubObject.NotSet or isinstance(has_issues, bool), has_issues + assert has_wiki is github.GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki assert has_downloads is github.GithubObject.NotSet or isinstance( has_downloads, bool ), has_downloads assert has_projects is github.GithubObject.NotSet or isinstance( has_projects, bool ), has_projects - assert auto_init is github.GithubObject.NotSet or isinstance( - auto_init, bool - ), auto_init + assert auto_init is github.GithubObject.NotSet or isinstance(auto_init, bool), auto_init assert license_template is github.GithubObject.NotSet or isinstance( license_template, str ), license_template @@ -762,9 +695,7 @@ def create_repo( headers, data = self._requester.requestJsonAndCheck( "POST", "/user/repos", input=post_parameters ) - return github.Repository.Repository( - self._requester, headers, data, completed=True - ) + return github.Repository.Repository(self._requester, headers, data, completed=True) def edit( self, @@ -790,15 +721,9 @@ def edit( assert name is github.GithubObject.NotSet or isinstance(name, str), name assert email is github.GithubObject.NotSet or isinstance(email, str), email assert blog is github.GithubObject.NotSet or isinstance(blog, str), blog - assert company is github.GithubObject.NotSet or isinstance( - company, str - ), company - assert location is github.GithubObject.NotSet or isinstance( - location, str - ), location - assert hireable is github.GithubObject.NotSet or isinstance( - hireable, bool - ), hireable + assert company is github.GithubObject.NotSet or isinstance(company, str), company + assert location is github.GithubObject.NotSet or isinstance(location, str), location + assert hireable is github.GithubObject.NotSet or isinstance(hireable, bool), hireable assert bio is github.GithubObject.NotSet or isinstance(bio, str), bio post_parameters = dict() if name is not github.GithubObject.NotSet: @@ -815,9 +740,7 @@ def edit( post_parameters["hireable"] = hireable if bio is not github.GithubObject.NotSet: post_parameters["bio"] = bio - headers, data = self._requester.requestJsonAndCheck( - "PATCH", "/user", input=post_parameters - ) + headers, data = self._requester.requestJsonAndCheck("PATCH", "/user", input=post_parameters) self._useAttributes(data) def get_authorization(self, id): @@ -827,12 +750,8 @@ def get_authorization(self, id): :rtype: :class:`github.Authorization.Authorization` """ assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck( - "GET", f"/authorizations/{id}" - ) - return github.Authorization.Authorization( - self._requester, headers, data, completed=True - ) + headers, data = self._requester.requestJsonAndCheck("GET", f"/authorizations/{id}") + return github.Authorization.Authorization(self._requester, headers, data, completed=True) def get_authorizations(self): """ @@ -885,9 +804,7 @@ def get_gists(self, since=github.GithubObject.NotSet): :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") @@ -921,12 +838,8 @@ def get_issues( isinstance(element, github.Label.Label) for element in labels ), labels assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction + assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -970,12 +883,8 @@ def get_user_issues( isinstance(element, github.Label.Label) for element in labels ), labels assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since + assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction + assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -1019,12 +928,8 @@ def get_notification(self, id): """ assert isinstance(id, str), id - headers, data = self._requester.requestJsonAndCheck( - "GET", f"/notifications/threads/{id}" - ) - return github.Notification.Notification( - self._requester, headers, data, completed=True - ) + headers, data = self._requester.requestJsonAndCheck("GET", f"/notifications/threads/{id}") + return github.Notification.Notification(self._requester, headers, data, completed=True) def get_notifications( self, @@ -1046,12 +951,8 @@ def get_notifications( assert participating is github.GithubObject.NotSet or isinstance( participating, bool ), participating - assert since is github.GithubObject.NotSet or isinstance( - since, datetime.datetime - ), since - assert before is github.GithubObject.NotSet or isinstance( - before, datetime.datetime - ), before + assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert before is github.GithubObject.NotSet or isinstance(before, datetime.datetime), before params = dict() if all is not github.GithubObject.NotSet: @@ -1097,12 +998,8 @@ def get_repo(self, name): :rtype: :class:`github.Repository.Repository` """ assert isinstance(name, str), name - headers, data = self._requester.requestJsonAndCheck( - "GET", f"/repos/{self.login}/{name}" - ) - return github.Repository.Repository( - self._requester, headers, data, completed=True - ) + headers, data = self._requester.requestJsonAndCheck("GET", f"/repos/{self.login}/{name}") + return github.Repository.Repository(self._requester, headers, data, completed=True) def get_repos( self, @@ -1121,17 +1018,13 @@ def get_repos( :param direction: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ - assert visibility is github.GithubObject.NotSet or isinstance( - visibility, str - ), visibility + assert visibility is github.GithubObject.NotSet or isinstance(visibility, str), visibility assert affiliation is github.GithubObject.NotSet or isinstance( affiliation, str ), affiliation assert type is github.GithubObject.NotSet or isinstance(type, str), type assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance( - direction, str - ), direction + assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction url_parameters = dict() if visibility is not github.GithubObject.NotSet: url_parameters["visibility"] = visibility @@ -1328,9 +1221,7 @@ def accept_invitation(self, invitation): :param invitation: :class:`github.Invitation.Invitation` or int :rtype: None """ - assert isinstance(invitation, github.Invitation.Invitation) or isinstance( - invitation, int - ) + assert isinstance(invitation, github.Invitation.Invitation) or isinstance(invitation, int) if isinstance(invitation, github.Invitation.Invitation): invitation = invitation.id @@ -1383,9 +1274,7 @@ def create_migration( input=post_parameters, headers={"Accept": Consts.mediaTypeMigrationPreview}, ) - return github.Migration.Migration( - self._requester, headers, data, completed=True - ) + return github.Migration.Migration(self._requester, headers, data, completed=True) def get_migrations(self): """ @@ -1406,12 +1295,8 @@ def get_organization_membership(self, org): :rtype: :class:`github.Membership.Membership` """ assert isinstance(org, str) - headers, data = self._requester.requestJsonAndCheck( - "GET", f"/user/memberships/orgs/{org}" - ) - return github.Membership.Membership( - self._requester, headers, data, completed=True - ) + headers, data = self._requester.requestJsonAndCheck("GET", f"/user/memberships/orgs/{org}") + return github.Membership.Membership(self._requester, headers, data, completed=True) def _initAttributes(self): self._avatar_url = github.GithubObject.NotSet @@ -1498,13 +1383,9 @@ def _useAttributes(self, attributes): if "node_id" in attributes: # pragma no branch self._node_id = self._makeStringAttribute(attributes["node_id"]) if "organizations_url" in attributes: # pragma no branch - self._organizations_url = self._makeStringAttribute( - attributes["organizations_url"] - ) + self._organizations_url = self._makeStringAttribute(attributes["organizations_url"]) if "owned_private_repos" in attributes: # pragma no branch - self._owned_private_repos = self._makeIntAttribute( - attributes["owned_private_repos"] - ) + self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"]) if "plan" in attributes: # pragma no branch self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"]) if "private_gists" in attributes: # pragma no branch @@ -1514,9 +1395,7 @@ def _useAttributes(self, attributes): if "public_repos" in attributes: # pragma no branch self._public_repos = self._makeIntAttribute(attributes["public_repos"]) if "received_events_url" in attributes: # pragma no branch - self._received_events_url = self._makeStringAttribute( - attributes["received_events_url"] - ) + self._received_events_url = self._makeStringAttribute(attributes["received_events_url"]) if "repos_url" in attributes: # pragma no branch self._repos_url = self._makeStringAttribute(attributes["repos_url"]) if "site_admin" in attributes: # pragma no branch @@ -1524,13 +1403,9 @@ def _useAttributes(self, attributes): if "starred_url" in attributes: # pragma no branch self._starred_url = self._makeStringAttribute(attributes["starred_url"]) if "subscriptions_url" in attributes: # pragma no branch - self._subscriptions_url = self._makeStringAttribute( - attributes["subscriptions_url"] - ) + self._subscriptions_url = self._makeStringAttribute(attributes["subscriptions_url"]) if "total_private_repos" in attributes: # pragma no branch - self._total_private_repos = self._makeIntAttribute( - attributes["total_private_repos"] - ) + self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"]) if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) if "updated_at" in attributes: # pragma no branch diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index 624fc4b3e8..9252bdeaff 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -323,9 +323,7 @@ def testSubscriptions(self): self.assertTrue(self.user.has_in_subscriptions(gitflow)) def testGetAuthorizations(self): - self.assertListKeyEqual( - self.user.get_authorizations(), lambda a: a.id, [372294] - ) + self.assertListKeyEqual(self.user.get_authorizations(), lambda a: a.id, [372294]) def testCreateRepository(self): repo = self.user.create_repo(name="TestPyGithub") @@ -410,9 +408,7 @@ def testGetEvents(self): def testGetOrganizationEvents(self): self.assertListKeyBegin( - self.user.get_organization_events( - self.g.get_organization("BeaverSoftware") - ), + self.user.get_organization_events(self.g.get_organization("BeaverSoftware")), lambda e: e.type, ["CreateEvent", "CreateEvent", "PushEvent", "PushEvent"], ) @@ -613,9 +609,7 @@ def testGetKeys(self): ) def testGetOrgs(self): - self.assertListKeyEqual( - self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"] - ) + self.assertListKeyEqual(self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"]) def testGetRepos(self): self.assertListKeyEqual( @@ -666,14 +660,12 @@ def testCreateFork(self): def testCreateRepoFromTemplate(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") - repo = self.user.create_repo_from_template( - "hello-world-docker-action-new", template_repo - ) + repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo) self.assertEqual( repo.url, "https://api.github.com/repos/jacquev6/hello-world-docker-action-new", ) - self.assertEqual(repo.is_template, False) + self.assertFalse(repo.is_template) def testCreateRepoFromTemplateWithAllArguments(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") @@ -697,9 +689,7 @@ def testGetNotification(self): self.assertEqual(notification.subject.title, "Feature/coveralls") self.assertEqual(notification.subject.type, "PullRequest") self.assertEqual(notification.repository.id, 8432784) - self.assertEqual( - notification.updated_at, datetime.datetime(2013, 3, 15, 5, 43, 11) - ) + self.assertEqual(notification.updated_at, datetime.datetime(2013, 3, 15, 5, 43, 11)) self.assertEqual(notification.url, None) self.assertEqual(notification.subject.url, None) self.assertEqual(notification.subject.latest_comment_url, None) @@ -717,14 +707,10 @@ def testGetNotifications(self): ) def testGetNotificationsWithOtherArguments(self): - self.assertListKeyEqual( - self.user.get_notifications(all=True), lambda n: n.id, [] - ) + self.assertListKeyEqual(self.user.get_notifications(all=True), lambda n: n.id, []) def testMarkNotificationsAsRead(self): - self.user.mark_notifications_as_read( - datetime.datetime(2018, 10, 18, 18, 20, 0o1, 0) - ) + self.user.mark_notifications_as_read(datetime.datetime(2018, 10, 18, 18, 20, 0o1, 0)) def testGetTeams(self): self.assertListKeyEqual( @@ -758,18 +744,14 @@ def testGetInvitations(self): invitation.url, "https://api.github.com/user/repository_invitations/17285388", ) - self.assertEqual( - invitation.html_url, "https://github.com/jacquev6/PyGithub/invitations" - ) + self.assertEqual(invitation.html_url, "https://github.com/jacquev6/PyGithub/invitations") self.assertEqual(invitation.repository.name, "PyGithub") self.assertEqual(invitation.invitee.login, "foobar-test1") self.assertEqual(invitation.inviter.login, "jacquev6") def testCreateMigration(self): self.assertTrue( - isinstance( - self.user.create_migration(["sample-repo"]), github.Migration.Migration - ) + isinstance(self.user.create_migration(["sample-repo"]), github.Migration.Migration) ) def testGetMigrations(self): diff --git a/tests/Organization.py b/tests/Organization.py index aaae619fa9..4478e67dca 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -366,7 +366,7 @@ def testCreateRepoFromTemplate(self): repo.url, "https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new", ) - self.assertEqual(repo.is_template, False) + self.assertFalse(repo.is_template) def testCreateRepoFromTemplateWithAllArguments(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") From 679858c37bc8d8ab1e8c5707399789745f504f88 Mon Sep 17 00:00:00 2001 From: KimSia Sim Date: Sun, 24 Oct 2021 13:54:49 +0800 Subject: [PATCH 22/25] =?UTF-8?q?=E2=99=BBRestore=20the=20original=20linti?= =?UTF-8?q?ng=20used=20in=20PyGithub=20main=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- github/AuthenticatedUser.py | 162 +++++++++++++++++++++++++++--------- github/Consts.py | 2 +- github/Organization.py | 2 +- tests/AuthenticatedUser.py | 32 +++++-- 4 files changed, 147 insertions(+), 51 deletions(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 5fd5652331..0655834e08 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -456,12 +456,18 @@ def create_authorization( isinstance(element, str) for element in scopes ), scopes assert note is github.GithubObject.NotSet or isinstance(note, str), note - assert note_url is github.GithubObject.NotSet or isinstance(note_url, str), note_url - assert client_id is github.GithubObject.NotSet or isinstance(client_id, str), client_id + assert note_url is github.GithubObject.NotSet or isinstance( + note_url, str + ), note_url + assert client_id is github.GithubObject.NotSet or isinstance( + client_id, str + ), client_id assert client_secret is github.GithubObject.NotSet or isinstance( client_secret, str ), client_secret - assert onetime_password is None or isinstance(onetime_password, str), onetime_password + assert onetime_password is None or isinstance( + onetime_password, str + ), onetime_password post_parameters = dict() if scopes is not github.GithubObject.NotSet: post_parameters["scopes"] = scopes @@ -485,7 +491,9 @@ def create_authorization( input=post_parameters, headers=request_header, ) - return github.Authorization.Authorization(self._requester, headers, data, completed=True) + return github.Authorization.Authorization( + self._requester, headers, data, completed=True + ) def create_fork(self, repo): """ @@ -497,7 +505,9 @@ def create_fork(self, repo): headers, data = self._requester.requestJsonAndCheck( "POST", f"/repos/{repo.owner.login}/{repo.name}/forks" ) - return github.Repository.Repository(self._requester, headers, data, completed=True) + return github.Repository.Repository( + self._requester, headers, data, completed=True + ) def create_repo_from_template( self, @@ -507,7 +517,7 @@ def create_repo_from_template( private=github.GithubObject.NotSet, ): """ - :calls: `POST /repos/:template_owner/:template_repo/generate ` + :calls: `POST /repos/{template_owner}/{template_repo}/generate `_ :param name: string :param repo :class:`github.Repository.Repository` :param description: string @@ -557,7 +567,9 @@ def create_gist(self, public, files, description=github.GithubObject.NotSet): } if description is not github.GithubObject.NotSet: post_parameters["description"] = description - headers, data = self._requester.requestJsonAndCheck("POST", "/gists", input=post_parameters) + headers, data = self._requester.requestJsonAndCheck( + "POST", "/gists", input=post_parameters + ) return github.Gist.Gist(self._requester, headers, data, completed=True) def create_key(self, title, key): @@ -640,17 +652,27 @@ def create_repo( assert description is github.GithubObject.NotSet or isinstance( description, str ), description - assert homepage is github.GithubObject.NotSet or isinstance(homepage, str), homepage - assert private is github.GithubObject.NotSet or isinstance(private, bool), private - assert has_issues is github.GithubObject.NotSet or isinstance(has_issues, bool), has_issues - assert has_wiki is github.GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki + assert homepage is github.GithubObject.NotSet or isinstance( + homepage, str + ), homepage + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private + assert has_issues is github.GithubObject.NotSet or isinstance( + has_issues, bool + ), has_issues + assert has_wiki is github.GithubObject.NotSet or isinstance( + has_wiki, bool + ), has_wiki assert has_downloads is github.GithubObject.NotSet or isinstance( has_downloads, bool ), has_downloads assert has_projects is github.GithubObject.NotSet or isinstance( has_projects, bool ), has_projects - assert auto_init is github.GithubObject.NotSet or isinstance(auto_init, bool), auto_init + assert auto_init is github.GithubObject.NotSet or isinstance( + auto_init, bool + ), auto_init assert license_template is github.GithubObject.NotSet or isinstance( license_template, str ), license_template @@ -703,7 +725,9 @@ def create_repo( headers, data = self._requester.requestJsonAndCheck( "POST", "/user/repos", input=post_parameters ) - return github.Repository.Repository(self._requester, headers, data, completed=True) + return github.Repository.Repository( + self._requester, headers, data, completed=True + ) def edit( self, @@ -729,9 +753,15 @@ def edit( assert name is github.GithubObject.NotSet or isinstance(name, str), name assert email is github.GithubObject.NotSet or isinstance(email, str), email assert blog is github.GithubObject.NotSet or isinstance(blog, str), blog - assert company is github.GithubObject.NotSet or isinstance(company, str), company - assert location is github.GithubObject.NotSet or isinstance(location, str), location - assert hireable is github.GithubObject.NotSet or isinstance(hireable, bool), hireable + assert company is github.GithubObject.NotSet or isinstance( + company, str + ), company + assert location is github.GithubObject.NotSet or isinstance( + location, str + ), location + assert hireable is github.GithubObject.NotSet or isinstance( + hireable, bool + ), hireable assert bio is github.GithubObject.NotSet or isinstance(bio, str), bio post_parameters = dict() if name is not github.GithubObject.NotSet: @@ -748,7 +778,9 @@ def edit( post_parameters["hireable"] = hireable if bio is not github.GithubObject.NotSet: post_parameters["bio"] = bio - headers, data = self._requester.requestJsonAndCheck("PATCH", "/user", input=post_parameters) + headers, data = self._requester.requestJsonAndCheck( + "PATCH", "/user", input=post_parameters + ) self._useAttributes(data) def get_authorization(self, id): @@ -758,8 +790,12 @@ def get_authorization(self, id): :rtype: :class:`github.Authorization.Authorization` """ assert isinstance(id, int), id - headers, data = self._requester.requestJsonAndCheck("GET", f"/authorizations/{id}") - return github.Authorization.Authorization(self._requester, headers, data, completed=True) + headers, data = self._requester.requestJsonAndCheck( + "GET", f"/authorizations/{id}" + ) + return github.Authorization.Authorization( + self._requester, headers, data, completed=True + ) def get_authorizations(self): """ @@ -812,7 +848,9 @@ def get_gists(self, since=github.GithubObject.NotSet): :param since: datetime.datetime format YYYY-MM-DDTHH:MM:SSZ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist` """ - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if since is not github.GithubObject.NotSet: url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ") @@ -846,8 +884,12 @@ def get_issues( isinstance(element, github.Label.Label) for element in labels ), labels assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -891,8 +933,12 @@ def get_user_issues( isinstance(element, github.Label.Label) for element in labels ), labels assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since url_parameters = dict() if filter is not github.GithubObject.NotSet: url_parameters["filter"] = filter @@ -936,8 +982,12 @@ def get_notification(self, id): """ assert isinstance(id, str), id - headers, data = self._requester.requestJsonAndCheck("GET", f"/notifications/threads/{id}") - return github.Notification.Notification(self._requester, headers, data, completed=True) + headers, data = self._requester.requestJsonAndCheck( + "GET", f"/notifications/threads/{id}" + ) + return github.Notification.Notification( + self._requester, headers, data, completed=True + ) def get_notifications( self, @@ -959,8 +1009,12 @@ def get_notifications( assert participating is github.GithubObject.NotSet or isinstance( participating, bool ), participating - assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since - assert before is github.GithubObject.NotSet or isinstance(before, datetime.datetime), before + assert since is github.GithubObject.NotSet or isinstance( + since, datetime.datetime + ), since + assert before is github.GithubObject.NotSet or isinstance( + before, datetime.datetime + ), before params = dict() if all is not github.GithubObject.NotSet: @@ -1008,8 +1062,12 @@ def get_repo(self, name): :rtype: :class:`github.Repository.Repository` """ assert isinstance(name, str), name - headers, data = self._requester.requestJsonAndCheck("GET", f"/repos/{self.login}/{name}") - return github.Repository.Repository(self._requester, headers, data, completed=True) + headers, data = self._requester.requestJsonAndCheck( + "GET", f"/repos/{self.login}/{name}" + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True + ) def get_repos( self, @@ -1028,13 +1086,17 @@ def get_repos( :param direction: string :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ - assert visibility is github.GithubObject.NotSet or isinstance(visibility, str), visibility + assert visibility is github.GithubObject.NotSet or isinstance( + visibility, str + ), visibility assert affiliation is github.GithubObject.NotSet or isinstance( affiliation, str ), affiliation assert type is github.GithubObject.NotSet or isinstance(type, str), type assert sort is github.GithubObject.NotSet or isinstance(sort, str), sort - assert direction is github.GithubObject.NotSet or isinstance(direction, str), direction + assert direction is github.GithubObject.NotSet or isinstance( + direction, str + ), direction url_parameters = dict() if visibility is not github.GithubObject.NotSet: url_parameters["visibility"] = visibility @@ -1231,7 +1293,9 @@ def accept_invitation(self, invitation): :param invitation: :class:`github.Invitation.Invitation` or int :rtype: None """ - assert isinstance(invitation, github.Invitation.Invitation) or isinstance(invitation, int) + assert isinstance(invitation, github.Invitation.Invitation) or isinstance( + invitation, int + ) if isinstance(invitation, github.Invitation.Invitation): invitation = invitation.id @@ -1284,7 +1348,9 @@ def create_migration( input=post_parameters, headers={"Accept": Consts.mediaTypeMigrationPreview}, ) - return github.Migration.Migration(self._requester, headers, data, completed=True) + return github.Migration.Migration( + self._requester, headers, data, completed=True + ) def get_migrations(self): """ @@ -1305,8 +1371,12 @@ def get_organization_membership(self, org): :rtype: :class:`github.Membership.Membership` """ assert isinstance(org, str) - headers, data = self._requester.requestJsonAndCheck("GET", f"/user/memberships/orgs/{org}") - return github.Membership.Membership(self._requester, headers, data, completed=True) + headers, data = self._requester.requestJsonAndCheck( + "GET", f"/user/memberships/orgs/{org}" + ) + return github.Membership.Membership( + self._requester, headers, data, completed=True + ) def _initAttributes(self): self._avatar_url = github.GithubObject.NotSet @@ -1394,9 +1464,13 @@ def _useAttributes(self, attributes): if "node_id" in attributes: # pragma no branch self._node_id = self._makeStringAttribute(attributes["node_id"]) if "organizations_url" in attributes: # pragma no branch - self._organizations_url = self._makeStringAttribute(attributes["organizations_url"]) + self._organizations_url = self._makeStringAttribute( + attributes["organizations_url"] + ) if "owned_private_repos" in attributes: # pragma no branch - self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"]) + self._owned_private_repos = self._makeIntAttribute( + attributes["owned_private_repos"] + ) if "plan" in attributes: # pragma no branch self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"]) if "private_gists" in attributes: # pragma no branch @@ -1406,7 +1480,9 @@ def _useAttributes(self, attributes): if "public_repos" in attributes: # pragma no branch self._public_repos = self._makeIntAttribute(attributes["public_repos"]) if "received_events_url" in attributes: # pragma no branch - self._received_events_url = self._makeStringAttribute(attributes["received_events_url"]) + self._received_events_url = self._makeStringAttribute( + attributes["received_events_url"] + ) if "repos_url" in attributes: # pragma no branch self._repos_url = self._makeStringAttribute(attributes["repos_url"]) if "site_admin" in attributes: # pragma no branch @@ -1414,9 +1490,13 @@ def _useAttributes(self, attributes): if "starred_url" in attributes: # pragma no branch self._starred_url = self._makeStringAttribute(attributes["starred_url"]) if "subscriptions_url" in attributes: # pragma no branch - self._subscriptions_url = self._makeStringAttribute(attributes["subscriptions_url"]) + self._subscriptions_url = self._makeStringAttribute( + attributes["subscriptions_url"] + ) if "total_private_repos" in attributes: # pragma no branch - self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"]) + self._total_private_repos = self._makeIntAttribute( + attributes["total_private_repos"] + ) if "type" in attributes: # pragma no branch self._type = self._makeStringAttribute(attributes["type"]) if "updated_at" in attributes: # pragma no branch diff --git a/github/Consts.py b/github/Consts.py index 3d83cc8f3b..e8a232b8ae 100644 --- a/github/Consts.py +++ b/github/Consts.py @@ -102,7 +102,7 @@ # https://developer.github.com/changes/2019-07-16-repository-templates-api/ mediaTypeTemplatesPreview = "application/vnd.github.baptiste-preview+json" -# https://developer.github.com/v3/search/#highlighting-code-search-results-1 +# https://docs.github.com/en/rest/reference/search#highlighting-code-search-results-1 highLightSearchPreview = "application/vnd.github.v3.text-match+json" # https://developer.github.com/changes/2018-02-22-protected-branches-required-signatures/ diff --git a/github/Organization.py b/github/Organization.py index ffd704a53c..dcc97c1ad2 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -411,7 +411,7 @@ def create_repo_from_template( private=github.GithubObject.NotSet, ): """self.name - :calls: `POST /repos/:template_owner/:template_repo/generate `_ + :calls: `POST /repos/{template_owner}/{template_repo}/generate `_ :param name: string :param repo :class:`github.Repository.Repository` :param description: string diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index 1d87514ffe..c4a378d12e 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -324,7 +324,9 @@ def testSubscriptions(self): self.assertTrue(self.user.has_in_subscriptions(gitflow)) def testGetAuthorizations(self): - self.assertListKeyEqual(self.user.get_authorizations(), lambda a: a.id, [372294]) + self.assertListKeyEqual( + self.user.get_authorizations(), lambda a: a.id, [372294] + ) def testCreateRepository(self): repo = self.user.create_repo(name="TestPyGithub") @@ -409,7 +411,9 @@ def testGetEvents(self): def testGetOrganizationEvents(self): self.assertListKeyBegin( - self.user.get_organization_events(self.g.get_organization("BeaverSoftware")), + self.user.get_organization_events( + self.g.get_organization("BeaverSoftware") + ), lambda e: e.type, ["CreateEvent", "CreateEvent", "PushEvent", "PushEvent"], ) @@ -610,7 +614,9 @@ def testGetKeys(self): ) def testGetOrgs(self): - self.assertListKeyEqual(self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"]) + self.assertListKeyEqual( + self.user.get_orgs(), lambda o: o.login, ["BeaverSoftware"] + ) def testGetRepos(self): self.assertListKeyEqual( @@ -690,7 +696,9 @@ def testGetNotification(self): self.assertEqual(notification.subject.title, "Feature/coveralls") self.assertEqual(notification.subject.type, "PullRequest") self.assertEqual(notification.repository.id, 8432784) - self.assertEqual(notification.updated_at, datetime.datetime(2013, 3, 15, 5, 43, 11)) + self.assertEqual( + notification.updated_at, datetime.datetime(2013, 3, 15, 5, 43, 11) + ) self.assertEqual(notification.url, None) self.assertEqual(notification.subject.url, None) self.assertEqual(notification.subject.latest_comment_url, None) @@ -708,10 +716,14 @@ def testGetNotifications(self): ) def testGetNotificationsWithOtherArguments(self): - self.assertListKeyEqual(self.user.get_notifications(all=True), lambda n: n.id, []) + self.assertListKeyEqual( + self.user.get_notifications(all=True), lambda n: n.id, [] + ) def testMarkNotificationsAsRead(self): - self.user.mark_notifications_as_read(datetime.datetime(2018, 10, 18, 18, 20, 0o1, 0)) + self.user.mark_notifications_as_read( + datetime.datetime(2018, 10, 18, 18, 20, 0o1, 0) + ) def testGetTeams(self): self.assertListKeyEqual( @@ -745,14 +757,18 @@ def testGetInvitations(self): invitation.url, "https://api.github.com/user/repository_invitations/17285388", ) - self.assertEqual(invitation.html_url, "https://github.com/jacquev6/PyGithub/invitations") + self.assertEqual( + invitation.html_url, "https://github.com/jacquev6/PyGithub/invitations" + ) self.assertEqual(invitation.repository.name, "PyGithub") self.assertEqual(invitation.invitee.login, "foobar-test1") self.assertEqual(invitation.inviter.login, "jacquev6") def testCreateMigration(self): self.assertTrue( - isinstance(self.user.create_migration(["sample-repo"]), github.Migration.Migration) + isinstance( + self.user.create_migration(["sample-repo"]), github.Migration.Migration + ) ) def testGetMigrations(self): From 891f450e167c8f5119c5ec82ba87ebc4feaf0262 Mon Sep 17 00:00:00 2001 From: KimSia Sim Date: Sun, 24 Oct 2021 14:04:13 +0800 Subject: [PATCH 23/25] Squashed commit of the following: commit 6452ddfeb4d2dfd31a998f8a2e573295818d7c51 Author: Steve Kowalik Date: Sun Oct 24 15:21:31 2021 +1100 Add Repository.rename_branch method (#2089) The GitHub API exposes an endpoint to rename a branch, so we should support calling it. Sadly, there is not enough information to add that method to the Branch class, so expose it in the Repository object. Fixes #1901 commit c8a945bb422b862a5a32001749f77457a6d55374 Author: Claire Johns <42869556+johnsc1@users.noreply.github.com> Date: Sun Oct 24 00:15:31 2021 -0400 Add function to delete pending reviews on a pull request (#1897) Add a delete method to PullRequestReview to allow dismissing them. Fixes #1856 Co-authored-by: bagashvilit Co-authored-by: WonjoonC commit f1faf941ecac3619fb410904727ced182b4e4fe1 Author: Steve Kowalik Date: Fri Oct 22 08:39:31 2021 +1100 Cover all code paths in search_commits (#2087) The search_commits method was only very lightly tested, meaning over half of it was not covered. Write another test case, covering all code paths. --- github/MainClass.py | 10 +++------ github/PullRequestReview.py | 9 ++++++++ github/PullRequestReview.pyi | 1 + github/Repository.py | 21 ++++++++++++++++++ github/Repository.pyi | 3 +++ tests/PullRequestReview.py | 1 + tests/PullRequestReview1856.py | 14 ++++++++++++ .../PullRequestReview1856.setUp.txt | 22 +++++++++++++++++++ .../PullRequestReview1856.testDelete.txt | 22 +++++++++++++++++++ .../Repository.testRenameBranchObject.txt | 22 +++++++++++++++++++ .../Repository.testRenameBranchString.txt | 11 ++++++++++ tests/ReplayData/Search.testSearchCommits.txt | 11 ++++++++++ tests/Repository.py | 7 ++++++ tests/Search.py | 9 ++++++++ 14 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 tests/PullRequestReview1856.py create mode 100644 tests/ReplayData/PullRequestReview1856.setUp.txt create mode 100644 tests/ReplayData/PullRequestReview1856.testDelete.txt create mode 100644 tests/ReplayData/Repository.testRenameBranchObject.txt create mode 100644 tests/ReplayData/Repository.testRenameBranchString.txt create mode 100644 tests/ReplayData/Search.testSearchCommits.txt diff --git a/github/MainClass.py b/github/MainClass.py index 579b1d83a6..5b626ad265 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -598,19 +598,15 @@ def search_commits( """ assert isinstance(query, str), query url_parameters = dict() - if ( - sort is not github.GithubObject.NotSet - ): # pragma no branch (Should be covered) + if sort is not github.GithubObject.NotSet: assert sort in ("author-date", "committer-date"), sort url_parameters["sort"] = sort - if ( - order is not github.GithubObject.NotSet - ): # pragma no branch (Should be covered) + if order is not github.GithubObject.NotSet: assert order in ("asc", "desc"), order url_parameters["order"] = order query_chunks = [] - if query: # pragma no branch (Should be covered) + if query: query_chunks.append(query) for qualifier, value in qualifiers.items(): diff --git a/github/PullRequestReview.py b/github/PullRequestReview.py index 34eed25afd..bd70f68f2b 100644 --- a/github/PullRequestReview.py +++ b/github/PullRequestReview.py @@ -105,6 +105,15 @@ def dismiss(self, message): input=post_parameters, ) + def delete(self): + """ + :calls: `DELETE /repos/:owner/:repo/pulls/:number/reviews/:review_id `_ + :rtype: None + """ + headers, data = self._requester.requestJsonAndCheck( + "DELETE", f"{self.pull_request_url}/reviews/{self.id}" + ) + def _initAttributes(self): self._id = github.GithubObject.NotSet self._user = github.GithubObject.NotSet diff --git a/github/PullRequestReview.pyi b/github/PullRequestReview.pyi index 269da086ce..e67bcc22ed 100644 --- a/github/PullRequestReview.pyi +++ b/github/PullRequestReview.pyi @@ -13,6 +13,7 @@ class PullRequestReview(CompletableGithubObject): @property def commit_id(self) -> str: ... def dismiss(self, message: str) -> None: ... + def delete(self) -> None: ... @property def html_url(self) -> str: ... @property diff --git a/github/Repository.py b/github/Repository.py index f1af79073e..1f7effa17f 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -1548,6 +1548,27 @@ def get_branch(self, branch): ) return github.Branch.Branch(self._requester, headers, data, completed=True) + def rename_branch(self, branch, new_name): + """ + :calls: `POST /repos/{owner}/{repo}/branches/{branch}/rename ` + :param branch: :class:`github.Branch.Branch` or string + :param new_name: string + :rtype: bool + + NOTE: This method does not return the branch since it may take some + time to fully complete server-side. + """ + is_branch = isinstance(branch, github.Branch.Branch) + assert isinstance(branch, str) or is_branch, branch + assert isinstance(new_name, str), new_name + if is_branch: + branch = branch.name + parameters = {"new_name": new_name} + status, _, _ = self._requester.requestJson( + "POST", f"{self.url}/branches/{branch}/rename", input=parameters + ) + return status == 201 + def get_branches(self): """ :calls: `GET /repos/{owner}/{repo}/branches `_ diff --git a/github/Repository.pyi b/github/Repository.pyi index fd876a363a..eb0dffdd14 100644 --- a/github/Repository.pyi +++ b/github/Repository.pyi @@ -307,6 +307,9 @@ class Repository(CompletableGithubObject): ) -> str: ... def get_assignees(self) -> PaginatedList[NamedUser]: ... def get_branch(self, branch: str) -> Branch: ... + def rename_branch( + self, branch: Union[str, Branch], new_name: str + ) -> bool: ... def get_branches(self) -> PaginatedList[Branch]: ... def get_check_run(self, check_run_id: int) -> CheckRun: ... def get_check_suite(self, check_suite_id: int) -> CheckSuite: ... diff --git a/tests/PullRequestReview.py b/tests/PullRequestReview.py index a2e317cc46..2594c7d8ed 100644 --- a/tests/PullRequestReview.py +++ b/tests/PullRequestReview.py @@ -32,6 +32,7 @@ class PullRequestReview(Framework.TestCase): def setUp(self): super().setUp() + self.repo = self.g.get_repo("PyGithub/PyGithub", lazy=True) self.pull = self.repo.get_pull(538) diff --git a/tests/PullRequestReview1856.py b/tests/PullRequestReview1856.py new file mode 100644 index 0000000000..4343bac016 --- /dev/null +++ b/tests/PullRequestReview1856.py @@ -0,0 +1,14 @@ +from . import Framework + + +class PullRequestReview1856(Framework.TestCase): + def setUp(self): + super().setUp() + pumpkin_repo = self.g.get_repo("CS481-Team-Pumpkin/PyGithub", lazy=True) + self.pumpkin_pull = pumpkin_repo.get_pull(4) + self.pullreview = self.pumpkin_pull.get_review(631460061) + + def testDelete(self): + self.pullreview.delete() + reviews = self.pumpkin_pull.get_reviews() + self.assertEqual(list(reviews), []) diff --git a/tests/ReplayData/PullRequestReview1856.setUp.txt b/tests/ReplayData/PullRequestReview1856.setUp.txt new file mode 100644 index 0000000000..70ffa8a9c3 --- /dev/null +++ b/tests/ReplayData/PullRequestReview1856.setUp.txt @@ -0,0 +1,22 @@ +https +GET +api.github.com +None +/repos/CS481-Team-Pumpkin/PyGithub/pulls/4 +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Thu, 08 Apr 2021 14:27:12 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"8639f2457cf97f5885ced460b20f8f7d17d5c09930e448de42e75b78426cd8e8"'), ('Last-Modified', 'Thu, 08 Apr 2021 14:23:05 GMT'), ('X-OAuth-Scopes', 'admin:org, repo'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4993'), ('X-RateLimit-Reset', '1617895279'), ('X-RateLimit-Used', '7'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', 'EB48:109EA:37F217:38E505:606F12C0')] +{"url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4","id":611598215,"node_id":"MDExOlB1bGxSZXF1ZXN0NjExNTk4MjE1","html_url":"https://github.com/CS481-Team-Pumpkin/PyGithub/pull/4","diff_url":"https://github.com/CS481-Team-Pumpkin/PyGithub/pull/4.diff","patch_url":"https://github.com/CS481-Team-Pumpkin/PyGithub/pull/4.patch","issue_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues/4","number":4,"state":"open","locked":false,"title":"Test commit","user":{"login":"bagashvilit","id":46755932,"node_id":"MDQ6VXNlcjQ2NzU1OTMy","avatar_url":"https://avatars.githubusercontent.com/u/46755932?v=4","gravatar_id":"","url":"https://api.github.com/users/bagashvilit","html_url":"https://github.com/bagashvilit","followers_url":"https://api.github.com/users/bagashvilit/followers","following_url":"https://api.github.com/users/bagashvilit/following{/other_user}","gists_url":"https://api.github.com/users/bagashvilit/gists{/gist_id}","starred_url":"https://api.github.com/users/bagashvilit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bagashvilit/subscriptions","organizations_url":"https://api.github.com/users/bagashvilit/orgs","repos_url":"https://api.github.com/users/bagashvilit/repos","events_url":"https://api.github.com/users/bagashvilit/events{/privacy}","received_events_url":"https://api.github.com/users/bagashvilit/received_events","type":"User","site_admin":false},"body":"","created_at":"2021-04-08T14:16:39Z","updated_at":"2021-04-08T14:23:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"07c3d56fa500c0f03a403136ba62cbbec6f148b0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"draft":false,"commits_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4/commits","review_comments_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4/comments","review_comment_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues/4/comments","statuses_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/statuses/a99c92b2ba68464a1a05d7fa8ef55e3a98803e5f","head":{"label":"CS481-Team-Pumpkin:test_delete_pending_review","ref":"test_delete_pending_review","sha":"a99c92b2ba68464a1a05d7fa8ef55e3a98803e5f","user":{"login":"CS481-Team-Pumpkin","id":80543978,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNTQzOTc4","avatar_url":"https://avatars.githubusercontent.com/u/80543978?v=4","gravatar_id":"","url":"https://api.github.com/users/CS481-Team-Pumpkin","html_url":"https://github.com/CS481-Team-Pumpkin","followers_url":"https://api.github.com/users/CS481-Team-Pumpkin/followers","following_url":"https://api.github.com/users/CS481-Team-Pumpkin/following{/other_user}","gists_url":"https://api.github.com/users/CS481-Team-Pumpkin/gists{/gist_id}","starred_url":"https://api.github.com/users/CS481-Team-Pumpkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CS481-Team-Pumpkin/subscriptions","organizations_url":"https://api.github.com/users/CS481-Team-Pumpkin/orgs","repos_url":"https://api.github.com/users/CS481-Team-Pumpkin/repos","events_url":"https://api.github.com/users/CS481-Team-Pumpkin/events{/privacy}","received_events_url":"https://api.github.com/users/CS481-Team-Pumpkin/received_events","type":"Organization","site_admin":false},"repo":{"id":347169081,"node_id":"MDEwOlJlcG9zaXRvcnkzNDcxNjkwODE=","name":"PyGithub","full_name":"CS481-Team-Pumpkin/PyGithub","private":false,"owner":{"login":"CS481-Team-Pumpkin","id":80543978,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNTQzOTc4","avatar_url":"https://avatars.githubusercontent.com/u/80543978?v=4","gravatar_id":"","url":"https://api.github.com/users/CS481-Team-Pumpkin","html_url":"https://github.com/CS481-Team-Pumpkin","followers_url":"https://api.github.com/users/CS481-Team-Pumpkin/followers","following_url":"https://api.github.com/users/CS481-Team-Pumpkin/following{/other_user}","gists_url":"https://api.github.com/users/CS481-Team-Pumpkin/gists{/gist_id}","starred_url":"https://api.github.com/users/CS481-Team-Pumpkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CS481-Team-Pumpkin/subscriptions","organizations_url":"https://api.github.com/users/CS481-Team-Pumpkin/orgs","repos_url":"https://api.github.com/users/CS481-Team-Pumpkin/repos","events_url":"https://api.github.com/users/CS481-Team-Pumpkin/events{/privacy}","received_events_url":"https://api.github.com/users/CS481-Team-Pumpkin/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/CS481-Team-Pumpkin/PyGithub","description":"Typed interactions with the GitHub API v3","fork":true,"url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub","forks_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/forks","keys_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/teams","hooks_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/hooks","issue_events_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues/events{/number}","events_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/events","assignees_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/assignees{/user}","branches_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/branches{/branch}","tags_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/tags","blobs_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/refs{/sha}","trees_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/statuses/{sha}","languages_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/languages","stargazers_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/stargazers","contributors_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/contributors","subscribers_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/subscribers","subscription_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/subscription","commits_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/commits{/sha}","git_commits_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/commits{/sha}","comments_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/comments{/number}","issue_comment_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues/comments{/number}","contents_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/contents/{+path}","compare_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/merges","archive_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/downloads","issues_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues{/number}","pulls_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls{/number}","milestones_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/milestones{/number}","notifications_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/labels{/name}","releases_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/releases{/id}","deployments_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/deployments","created_at":"2021-03-12T18:58:51Z","updated_at":"2021-04-02T17:52:24Z","pushed_at":"2021-04-08T14:16:39Z","git_url":"git://github.com/CS481-Team-Pumpkin/PyGithub.git","ssh_url":"git@github.com:CS481-Team-Pumpkin/PyGithub.git","clone_url":"https://github.com/CS481-Team-Pumpkin/PyGithub.git","svn_url":"https://github.com/CS481-Team-Pumpkin/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":13338,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":3,"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"},"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"CS481-Team-Pumpkin:master","ref":"master","sha":"7f0a239bc797a071e512b763dfd3e4339191dc18","user":{"login":"CS481-Team-Pumpkin","id":80543978,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNTQzOTc4","avatar_url":"https://avatars.githubusercontent.com/u/80543978?v=4","gravatar_id":"","url":"https://api.github.com/users/CS481-Team-Pumpkin","html_url":"https://github.com/CS481-Team-Pumpkin","followers_url":"https://api.github.com/users/CS481-Team-Pumpkin/followers","following_url":"https://api.github.com/users/CS481-Team-Pumpkin/following{/other_user}","gists_url":"https://api.github.com/users/CS481-Team-Pumpkin/gists{/gist_id}","starred_url":"https://api.github.com/users/CS481-Team-Pumpkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CS481-Team-Pumpkin/subscriptions","organizations_url":"https://api.github.com/users/CS481-Team-Pumpkin/orgs","repos_url":"https://api.github.com/users/CS481-Team-Pumpkin/repos","events_url":"https://api.github.com/users/CS481-Team-Pumpkin/events{/privacy}","received_events_url":"https://api.github.com/users/CS481-Team-Pumpkin/received_events","type":"Organization","site_admin":false},"repo":{"id":347169081,"node_id":"MDEwOlJlcG9zaXRvcnkzNDcxNjkwODE=","name":"PyGithub","full_name":"CS481-Team-Pumpkin/PyGithub","private":false,"owner":{"login":"CS481-Team-Pumpkin","id":80543978,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNTQzOTc4","avatar_url":"https://avatars.githubusercontent.com/u/80543978?v=4","gravatar_id":"","url":"https://api.github.com/users/CS481-Team-Pumpkin","html_url":"https://github.com/CS481-Team-Pumpkin","followers_url":"https://api.github.com/users/CS481-Team-Pumpkin/followers","following_url":"https://api.github.com/users/CS481-Team-Pumpkin/following{/other_user}","gists_url":"https://api.github.com/users/CS481-Team-Pumpkin/gists{/gist_id}","starred_url":"https://api.github.com/users/CS481-Team-Pumpkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CS481-Team-Pumpkin/subscriptions","organizations_url":"https://api.github.com/users/CS481-Team-Pumpkin/orgs","repos_url":"https://api.github.com/users/CS481-Team-Pumpkin/repos","events_url":"https://api.github.com/users/CS481-Team-Pumpkin/events{/privacy}","received_events_url":"https://api.github.com/users/CS481-Team-Pumpkin/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/CS481-Team-Pumpkin/PyGithub","description":"Typed interactions with the GitHub API v3","fork":true,"url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub","forks_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/forks","keys_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/teams","hooks_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/hooks","issue_events_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues/events{/number}","events_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/events","assignees_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/assignees{/user}","branches_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/branches{/branch}","tags_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/tags","blobs_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/refs{/sha}","trees_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/statuses/{sha}","languages_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/languages","stargazers_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/stargazers","contributors_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/contributors","subscribers_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/subscribers","subscription_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/subscription","commits_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/commits{/sha}","git_commits_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/git/commits{/sha}","comments_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/comments{/number}","issue_comment_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues/comments{/number}","contents_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/contents/{+path}","compare_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/merges","archive_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/downloads","issues_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues{/number}","pulls_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls{/number}","milestones_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/milestones{/number}","notifications_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/labels{/name}","releases_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/releases{/id}","deployments_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/deployments","created_at":"2021-03-12T18:58:51Z","updated_at":"2021-04-02T17:52:24Z","pushed_at":"2021-04-08T14:16:39Z","git_url":"git://github.com/CS481-Team-Pumpkin/PyGithub.git","ssh_url":"git@github.com:CS481-Team-Pumpkin/PyGithub.git","clone_url":"https://github.com/CS481-Team-Pumpkin/PyGithub.git","svn_url":"https://github.com/CS481-Team-Pumpkin/PyGithub","homepage":"https://pygithub.readthedocs.io/","size":13338,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":3,"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"},"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4"},"html":{"href":"https://github.com/CS481-Team-Pumpkin/PyGithub/pull/4"},"issue":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues/4"},"comments":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/statuses/a99c92b2ba68464a1a05d7fa8ef55e3a98803e5f"}},"author_association":"MEMBER","auto_merge":null,"active_lock_reason":null,"merged":false,"mergeable":true,"rebaseable":true,"mergeable_state":"clean","merged_by":null,"comments":0,"review_comments":1,"maintainer_can_modify":false,"commits":1,"additions":1,"deletions":0,"changed_files":1} + +https +GET +api.github.com +None +/repos/CS481-Team-Pumpkin/PyGithub/pulls/4/reviews/631460061 +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Thu, 08 Apr 2021 14:27:13 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"2cb2134a474a60fa86391e682a41332b9ce4e92e41b9e7d2039ce2e6c64ae80e"'), ('X-OAuth-Scopes', 'admin:org, repo'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4992'), ('X-RateLimit-Reset', '1617895279'), ('X-RateLimit-Used', '8'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', 'EB4A:950E:125F8E:13037F:606F12C0')] +{"id":631460061,"node_id":"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3NjMxNDYwMDYx","user":{"login":"bagashvilit","id":46755932,"node_id":"MDQ6VXNlcjQ2NzU1OTMy","avatar_url":"https://avatars.githubusercontent.com/u/46755932?v=4","gravatar_id":"","url":"https://api.github.com/users/bagashvilit","html_url":"https://github.com/bagashvilit","followers_url":"https://api.github.com/users/bagashvilit/followers","following_url":"https://api.github.com/users/bagashvilit/following{/other_user}","gists_url":"https://api.github.com/users/bagashvilit/gists{/gist_id}","starred_url":"https://api.github.com/users/bagashvilit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bagashvilit/subscriptions","organizations_url":"https://api.github.com/users/bagashvilit/orgs","repos_url":"https://api.github.com/users/bagashvilit/repos","events_url":"https://api.github.com/users/bagashvilit/events{/privacy}","received_events_url":"https://api.github.com/users/bagashvilit/received_events","type":"User","site_admin":false},"body":"","state":"PENDING","html_url":"https://github.com/CS481-Team-Pumpkin/PyGithub/pull/4#pullrequestreview-631460061","pull_request_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4","author_association":"MEMBER","_links":{"html":{"href":"https://github.com/CS481-Team-Pumpkin/PyGithub/pull/4#pullrequestreview-631460061"},"pull_request":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4"}},"commit_id":"a99c92b2ba68464a1a05d7fa8ef55e3a98803e5f"} + diff --git a/tests/ReplayData/PullRequestReview1856.testDelete.txt b/tests/ReplayData/PullRequestReview1856.testDelete.txt new file mode 100644 index 0000000000..47bb025c03 --- /dev/null +++ b/tests/ReplayData/PullRequestReview1856.testDelete.txt @@ -0,0 +1,22 @@ +https +DELETE +api.github.com +None +/repos/CS481-Team-Pumpkin/PyGithub/pulls/4/reviews/631460061 +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Thu, 08 Apr 2021 14:27:14 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"2cb2134a474a60fa86391e682a41332b9ce4e92e41b9e7d2039ce2e6c64ae80e"'), ('X-OAuth-Scopes', 'admin:org, repo'), ('X-Accepted-OAuth-Scopes', 'public_repo, repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4991'), ('X-RateLimit-Reset', '1617895279'), ('X-RateLimit-Used', '9'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', 'EB4C:74D7:85110:8A249:606F12C1')] +{"id":631460061,"node_id":"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3NjMxNDYwMDYx","user":{"login":"bagashvilit","id":46755932,"node_id":"MDQ6VXNlcjQ2NzU1OTMy","avatar_url":"https://avatars.githubusercontent.com/u/46755932?v=4","gravatar_id":"","url":"https://api.github.com/users/bagashvilit","html_url":"https://github.com/bagashvilit","followers_url":"https://api.github.com/users/bagashvilit/followers","following_url":"https://api.github.com/users/bagashvilit/following{/other_user}","gists_url":"https://api.github.com/users/bagashvilit/gists{/gist_id}","starred_url":"https://api.github.com/users/bagashvilit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bagashvilit/subscriptions","organizations_url":"https://api.github.com/users/bagashvilit/orgs","repos_url":"https://api.github.com/users/bagashvilit/repos","events_url":"https://api.github.com/users/bagashvilit/events{/privacy}","received_events_url":"https://api.github.com/users/bagashvilit/received_events","type":"User","site_admin":false},"body":"","state":"PENDING","html_url":"https://github.com/CS481-Team-Pumpkin/PyGithub/pull/4#pullrequestreview-631460061","pull_request_url":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4","author_association":"MEMBER","_links":{"html":{"href":"https://github.com/CS481-Team-Pumpkin/PyGithub/pull/4#pullrequestreview-631460061"},"pull_request":{"href":"https://api.github.com/repos/CS481-Team-Pumpkin/PyGithub/pulls/4"}},"commit_id":"a99c92b2ba68464a1a05d7fa8ef55e3a98803e5f"} + +https +GET +api.github.com +None +/repos/CS481-Team-Pumpkin/PyGithub/pulls/4/reviews +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Thu, 08 Apr 2021 14:27:14 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '2'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', '"82184cd6a599c0bb646629f3cbc867fb158314f97d57df6e35f0e910ed328f22"'), ('X-OAuth-Scopes', 'admin:org, repo'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4990'), ('X-RateLimit-Reset', '1617895279'), ('X-RateLimit-Used', '10'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', 'EB4E:109E6:83D8B:8CA9B:606F12C2')] +[] + diff --git a/tests/ReplayData/Repository.testRenameBranchObject.txt b/tests/ReplayData/Repository.testRenameBranchObject.txt new file mode 100644 index 0000000000..23abea565e --- /dev/null +++ b/tests/ReplayData/Repository.testRenameBranchObject.txt @@ -0,0 +1,22 @@ +https +GET +api.github.com +None +/repos/jacquev6/PyGithub/branches/neat-new-feature +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Sat, 23 Oct 2021 04:32:06 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"7b4b9377dbba34db4d606bcfaadf8997f690d2fb7afc15982857269ba17e8a90"'), ('X-OAuth-Scopes', 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4998'), ('X-RateLimit-Reset', '1634967125'), ('X-RateLimit-Used', '2'), ('X-RateLimit-Resource', 'core'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '82FE:7C71:69CE0C:7107D9:61739046')] +{"name":"neat-new-feature","commit":{"sha":"dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","node_id":"C_kwDOB7W4ZNoAKGRiZmJmN2YwN2I4MWQ2MTZkNGRhMDMyYmNmYTdjYTkwZGNkNzk1NzU","commit":{"author":{"name":"Steve Kowalik","email":"steven@wedontsleep.org","date":"2021-10-21T04:06:06Z"},"committer":{"name":"Steve Kowalik","email":"steven@wedontsleep.org","date":"2021-10-21T04:06:06Z"},"message":"WIP: branch rename","tree":{"sha":"81e30fe50ff2b1c8e8cb819d181b3a285e9a9c94","url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/81e30fe50ff2b1c8e8cb819d181b3a285e9a9c94"},"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","comment_count":0,"verification":{"verified":false,"reason":"unsigned","signature":null,"payload":null}},"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","html_url":"https://github.com/jacquev6/PyGithub/commit/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","comments_url":"https://api.github.com/repos/jacquev6/PyGithub/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575/comments","author":{"login":"jacquev6","id":15225059,"node_id":"MDQ6VXNlcjE1MjI1MDU5","avatar_url":"https://avatars.githubusercontent.com/u/15225059?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"committer":{"login":"jacquev6","id":15225059,"node_id":"MDQ6VXNlcjE1MjI1MDU5","avatar_url":"https://avatars.githubusercontent.com/u/15225059?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"parents":[{"sha":"93b92cd2fce560080dc66aef3b94427623046c5d","url":"https://api.github.com/repos/jacquev6/PyGithub/commits/93b92cd2fce560080dc66aef3b94427623046c5d","html_url":"https://github.com/jacquev6/PyGithub/commit/93b92cd2fce560080dc66aef3b94427623046c5d"}]},"_links":{"self":"https://api.github.com/repos/jacquev6/PyGithub/branches/neat-new-feature","html":"https://github.com/jacquev6/PyGithub/tree/neat-new-feature"},"protected":false,"protection":{"enabled":false,"required_status_checks":{"enforcement_level":"off","contexts":[]}},"protection_url":"https://api.github.com/repos/jacquev6/PyGithub/branches/neat-new-feature/protection"} + +https +POST +api.github.com +None +/repos/jacquev6/PyGithub/branches/neat-new-feature/rename +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"new_name": "terrible-idea"} +201 +[('Server', 'GitHub.com'), ('Date', 'Sat, 23 Oct 2021 04:32:07 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '3748'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', '"21b924f024389f2dad56ec7b61664d88fa432e59b6068797da15b3b1718799a1"'), ('X-OAuth-Scopes', 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4996'), ('X-RateLimit-Reset', '1634967125'), ('X-RateLimit-Used', '4'), ('X-RateLimit-Resource', 'core'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '8302:7C71:69CE3F:710812:61739046')] +{"name":"terrible-idea","commit":{"sha":"dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","node_id":"C_kwDOB7W4ZNoAKGRiZmJmN2YwN2I4MWQ2MTZkNGRhMDMyYmNmYTdjYTkwZGNkNzk1NzU","commit":{"author":{"name":"Steve Kowalik","email":"steven@wedontsleep.org","date":"2021-10-21T04:06:06Z"},"committer":{"name":"Steve Kowalik","email":"steven@wedontsleep.org","date":"2021-10-21T04:06:06Z"},"message":"WIP: branch rename","tree":{"sha":"81e30fe50ff2b1c8e8cb819d181b3a285e9a9c94","url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/81e30fe50ff2b1c8e8cb819d181b3a285e9a9c94"},"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","comment_count":0,"verification":{"verified":false,"reason":"unsigned","signature":null,"payload":null}},"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","html_url":"https://github.com/jacquev6/PyGithub/commit/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","comments_url":"https://api.github.com/repos/jacquev6/PyGithub/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575/comments","author":{"login":"jacquev6","id":15225059,"node_id":"MDQ6VXNlcjE1MjI1MDU5","avatar_url":"https://avatars.githubusercontent.com/u/15225059?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"committer":{"login":"jacquev6","id":15225059,"node_id":"MDQ6VXNlcjE1MjI1MDU5","avatar_url":"https://avatars.githubusercontent.com/u/15225059?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"parents":[{"sha":"93b92cd2fce560080dc66aef3b94427623046c5d","url":"https://api.github.com/repos/jacquev6/PyGithub/commits/93b92cd2fce560080dc66aef3b94427623046c5d","html_url":"https://github.com/jacquev6/PyGithub/commit/93b92cd2fce560080dc66aef3b94427623046c5d"}]},"_links":{"self":"https://api.github.com/repos/jacquev6/PyGithub/branches/terrible-idea","html":"https://github.com/jacquev6/PyGithub/tree/terrible-idea"},"protected":false,"protection":{"enabled":false,"required_status_checks":{"enforcement_level":"off","contexts":[]}},"protection_url":"https://api.github.com/repos/jacquev6/PyGithub/branches/terrible-idea/protection"} + diff --git a/tests/ReplayData/Repository.testRenameBranchString.txt b/tests/ReplayData/Repository.testRenameBranchString.txt new file mode 100644 index 0000000000..193c642eda --- /dev/null +++ b/tests/ReplayData/Repository.testRenameBranchString.txt @@ -0,0 +1,11 @@ +https +POST +api.github.com +None +/repos/jacquev6/PyGithub/branches/neat-new-feature/rename +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"new_name": "terrible-idea"} +201 +[('Server', 'GitHub.com'), ('Date', 'Sat, 23 Oct 2021 04:32:07 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '3748'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', '"21b924f024389f2dad56ec7b61664d88fa432e59b6068797da15b3b1718799a1"'), ('X-OAuth-Scopes', 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4996'), ('X-RateLimit-Reset', '1634967125'), ('X-RateLimit-Used', '4'), ('X-RateLimit-Resource', 'core'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '8302:7C71:69CE3F:710812:61739046')] +{"name":"terrible-idea","commit":{"sha":"dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","node_id":"C_kwDOB7W4ZNoAKGRiZmJmN2YwN2I4MWQ2MTZkNGRhMDMyYmNmYTdjYTkwZGNkNzk1NzU","commit":{"author":{"name":"Steve Kowalik","email":"steven@wedontsleep.org","date":"2021-10-21T04:06:06Z"},"committer":{"name":"Steve Kowalik","email":"steven@wedontsleep.org","date":"2021-10-21T04:06:06Z"},"message":"WIP: branch rename","tree":{"sha":"81e30fe50ff2b1c8e8cb819d181b3a285e9a9c94","url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/81e30fe50ff2b1c8e8cb819d181b3a285e9a9c94"},"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","comment_count":0,"verification":{"verified":false,"reason":"unsigned","signature":null,"payload":null}},"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","html_url":"https://github.com/jacquev6/PyGithub/commit/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575","comments_url":"https://api.github.com/repos/jacquev6/PyGithub/commits/dbfbf7f07b81d616d4da032bcfa7ca90dcd79575/comments","author":{"login":"jacquev6","id":15225059,"node_id":"MDQ6VXNlcjE1MjI1MDU5","avatar_url":"https://avatars.githubusercontent.com/u/15225059?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"committer":{"login":"jacquev6","id":15225059,"node_id":"MDQ6VXNlcjE1MjI1MDU5","avatar_url":"https://avatars.githubusercontent.com/u/15225059?v=4","gravatar_id":"","url":"https://api.github.com/users/jacquev6","html_url":"https://github.com/jacquev6","followers_url":"https://api.github.com/users/jacquev6/followers","following_url":"https://api.github.com/users/jacquev6/following{/other_user}","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","organizations_url":"https://api.github.com/users/jacquev6/orgs","repos_url":"https://api.github.com/users/jacquev6/repos","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","received_events_url":"https://api.github.com/users/jacquev6/received_events","type":"User","site_admin":false},"parents":[{"sha":"93b92cd2fce560080dc66aef3b94427623046c5d","url":"https://api.github.com/repos/jacquev6/PyGithub/commits/93b92cd2fce560080dc66aef3b94427623046c5d","html_url":"https://github.com/jacquev6/PyGithub/commit/93b92cd2fce560080dc66aef3b94427623046c5d"}]},"_links":{"self":"https://api.github.com/repos/jacquev6/PyGithub/branches/terrible-idea","html":"https://github.com/jacquev6/PyGithub/tree/terrible-idea"},"protected":false,"protection":{"enabled":false,"required_status_checks":{"enforcement_level":"off","contexts":[]}},"protection_url":"https://api.github.com/repos/jacquev6/PyGithub/branches/terrible-idea/protection"} + diff --git a/tests/ReplayData/Search.testSearchCommits.txt b/tests/ReplayData/Search.testSearchCommits.txt new file mode 100644 index 0000000000..357d2fcd15 --- /dev/null +++ b/tests/ReplayData/Search.testSearchCommits.txt @@ -0,0 +1,11 @@ +https +GET +api.github.com +None +/search/commits?sort=author-date&order=asc&q=hash%3A1265747e992ba7d34a469b6b2f527809f8bf7067+merge%3Afalse&per_page=1 +{'Accept': 'application/vnd.github.cloak-preview', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('Server', 'GitHub.com'), ('Date', 'Thu, 21 Oct 2021 04:54:24 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Cache-Control', 'no-cache'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('X-OAuth-Scopes', 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; param=cloak-preview'), ('Link', '; rel="next", ; rel="last"'), ('X-RateLimit-Limit', '30'), ('X-RateLimit-Remaining', '28'), ('X-RateLimit-Reset', '1634792071'), ('X-RateLimit-Used', '2'), ('X-RateLimit-Resource', 'search'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', 'DB8E:3107:5AE85E:63CFBA:6170F280')] +{"total_count":2,"incomplete_results":false,"items":[{"url":"https://api.github.com/repos/PyGithub/PyGithub/commits/1265747e992ba7d34a469b6b2f527809f8bf7067","sha":"1265747e992ba7d34a469b6b2f527809f8bf7067","node_id":"MDY6Q29tbWl0MzU0NDQ5MDoxMjY1NzQ3ZTk5MmJhN2QzNGE0NjliNmIyZjUyNzgwOWY4YmY3MDY3","html_url":"https://github.com/PyGithub/PyGithub/commit/1265747e992ba7d34a469b6b2f527809f8bf7067","comments_url":"https://api.github.com/repos/PyGithub/PyGithub/commits/1265747e992ba7d34a469b6b2f527809f8bf7067/comments","commit":{"url":"https://api.github.com/repos/PyGithub/PyGithub/git/commits/1265747e992ba7d34a469b6b2f527809f8bf7067","author":{"date":"2021-06-02T15:00:00.000+10:00","name":"Steve Kowalik","email":"steven@wedontsleep.org"},"committer":{"date":"2021-06-02T15:00:00.000+10:00","name":"GitHub","email":"noreply@github.com"},"message":"Do not transform requestHeaders when logging (#1965)\n\nRequester.__log() sanitizes the headers of the request so that\r\nauthentication details are not logged, but this has the side effect of\r\nmeaning that future requests that use the same Requester object will\r\nfail. Usually, this is perfectly fine, since almost every method will\r\nonly make one request -- where this falls down is when we make another\r\nafter a redirect. Make a copy of the requestHeaders, and sanitize those.\r\n\r\nFixes #1959","tree":{"url":"https://api.github.com/repos/PyGithub/PyGithub/git/trees/6e5b9e20c26a6b3ba8c5481a8e2896bb72a91bbb","sha":"6e5b9e20c26a6b3ba8c5481a8e2896bb72a91bbb"},"comment_count":0},"author":{"login":"s-t-e-v-e-n-k","id":15225059,"node_id":"MDQ6VXNlcjE1MjI1MDU5","avatar_url":"https://avatars.githubusercontent.com/u/15225059?v=4","gravatar_id":"","url":"https://api.github.com/users/s-t-e-v-e-n-k","html_url":"https://github.com/s-t-e-v-e-n-k","followers_url":"https://api.github.com/users/s-t-e-v-e-n-k/followers","following_url":"https://api.github.com/users/s-t-e-v-e-n-k/following{/other_user}","gists_url":"https://api.github.com/users/s-t-e-v-e-n-k/gists{/gist_id}","starred_url":"https://api.github.com/users/s-t-e-v-e-n-k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s-t-e-v-e-n-k/subscriptions","organizations_url":"https://api.github.com/users/s-t-e-v-e-n-k/orgs","repos_url":"https://api.github.com/users/s-t-e-v-e-n-k/repos","events_url":"https://api.github.com/users/s-t-e-v-e-n-k/events{/privacy}","received_events_url":"https://api.github.com/users/s-t-e-v-e-n-k/received_events","type":"User","site_admin":false},"committer":{"login":"web-flow","id":19864447,"node_id":"MDQ6VXNlcjE5ODY0NDQ3","avatar_url":"https://avatars.githubusercontent.com/u/19864447?v=4","gravatar_id":"","url":"https://api.github.com/users/web-flow","html_url":"https://github.com/web-flow","followers_url":"https://api.github.com/users/web-flow/followers","following_url":"https://api.github.com/users/web-flow/following{/other_user}","gists_url":"https://api.github.com/users/web-flow/gists{/gist_id}","starred_url":"https://api.github.com/users/web-flow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/web-flow/subscriptions","organizations_url":"https://api.github.com/users/web-flow/orgs","repos_url":"https://api.github.com/users/web-flow/repos","events_url":"https://api.github.com/users/web-flow/events{/privacy}","received_events_url":"https://api.github.com/users/web-flow/received_events","type":"User","site_admin":false},"parents":[{"url":"https://api.github.com/repos/PyGithub/PyGithub/commits/ed7d0fe94f063d228a7dd95b7df5ae1bedb0707a","html_url":"https://github.com/PyGithub/PyGithub/commit/ed7d0fe94f063d228a7dd95b7df5ae1bedb0707a","sha":"ed7d0fe94f063d228a7dd95b7df5ae1bedb0707a"}],"repository":{"id":3544490,"node_id":"MDEwOlJlcG9zaXRvcnkzNTQ0NDkw","name":"PyGithub","full_name":"PyGithub/PyGithub","private":false,"owner":{"login":"PyGithub","id":11288996,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExMjg4OTk2","avatar_url":"https://avatars.githubusercontent.com/u/11288996?v=4","gravatar_id":"","url":"https://api.github.com/users/PyGithub","html_url":"https://github.com/PyGithub","followers_url":"https://api.github.com/users/PyGithub/followers","following_url":"https://api.github.com/users/PyGithub/following{/other_user}","gists_url":"https://api.github.com/users/PyGithub/gists{/gist_id}","starred_url":"https://api.github.com/users/PyGithub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PyGithub/subscriptions","organizations_url":"https://api.github.com/users/PyGithub/orgs","repos_url":"https://api.github.com/users/PyGithub/repos","events_url":"https://api.github.com/users/PyGithub/events{/privacy}","received_events_url":"https://api.github.com/users/PyGithub/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/PyGithub/PyGithub","description":"Typed interactions with the GitHub API v3","fork":false,"url":"https://api.github.com/repos/PyGithub/PyGithub","forks_url":"https://api.github.com/repos/PyGithub/PyGithub/forks","keys_url":"https://api.github.com/repos/PyGithub/PyGithub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PyGithub/PyGithub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PyGithub/PyGithub/teams","hooks_url":"https://api.github.com/repos/PyGithub/PyGithub/hooks","issue_events_url":"https://api.github.com/repos/PyGithub/PyGithub/issues/events{/number}","events_url":"https://api.github.com/repos/PyGithub/PyGithub/events","assignees_url":"https://api.github.com/repos/PyGithub/PyGithub/assignees{/user}","branches_url":"https://api.github.com/repos/PyGithub/PyGithub/branches{/branch}","tags_url":"https://api.github.com/repos/PyGithub/PyGithub/tags","blobs_url":"https://api.github.com/repos/PyGithub/PyGithub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PyGithub/PyGithub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PyGithub/PyGithub/git/refs{/sha}","trees_url":"https://api.github.com/repos/PyGithub/PyGithub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PyGithub/PyGithub/statuses/{sha}","languages_url":"https://api.github.com/repos/PyGithub/PyGithub/languages","stargazers_url":"https://api.github.com/repos/PyGithub/PyGithub/stargazers","contributors_url":"https://api.github.com/repos/PyGithub/PyGithub/contributors","subscribers_url":"https://api.github.com/repos/PyGithub/PyGithub/subscribers","subscription_url":"https://api.github.com/repos/PyGithub/PyGithub/subscription","commits_url":"https://api.github.com/repos/PyGithub/PyGithub/commits{/sha}","git_commits_url":"https://api.github.com/repos/PyGithub/PyGithub/git/commits{/sha}","comments_url":"https://api.github.com/repos/PyGithub/PyGithub/comments{/number}","issue_comment_url":"https://api.github.com/repos/PyGithub/PyGithub/issues/comments{/number}","contents_url":"https://api.github.com/repos/PyGithub/PyGithub/contents/{+path}","compare_url":"https://api.github.com/repos/PyGithub/PyGithub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PyGithub/PyGithub/merges","archive_url":"https://api.github.com/repos/PyGithub/PyGithub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PyGithub/PyGithub/downloads","issues_url":"https://api.github.com/repos/PyGithub/PyGithub/issues{/number}","pulls_url":"https://api.github.com/repos/PyGithub/PyGithub/pulls{/number}","milestones_url":"https://api.github.com/repos/PyGithub/PyGithub/milestones{/number}","notifications_url":"https://api.github.com/repos/PyGithub/PyGithub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PyGithub/PyGithub/labels{/name}","releases_url":"https://api.github.com/repos/PyGithub/PyGithub/releases{/id}","deployments_url":"https://api.github.com/repos/PyGithub/PyGithub/deployments"},"score":1.0}]} + diff --git a/tests/Repository.py b/tests/Repository.py index cdc78b761b..a7befe38cd 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -1324,6 +1324,13 @@ def testGetBranch(self): branch = self.repo.get_branch("develop") self.assertEqual(branch.commit.sha, "03058a36164d2a7d946db205f25538434fa27d94") + def testRenameBranchObject(self): + branch = self.repo.get_branch("neat-new-feature") + self.assertTrue(self.repo.rename_branch(branch, "terrible-idea")) + + def testRenameBranchString(self): + self.assertTrue(self.repo.rename_branch("neat-new-feature", "terrible-idea")) + def testMergeWithoutMessage(self): commit = self.repo.merge("branchForBase", "branchForHead") self.assertEqual( diff --git a/tests/Search.py b/tests/Search.py index f7e2ffe175..aa6c2b2a46 100644 --- a/tests/Search.py +++ b/tests/Search.py @@ -195,6 +195,15 @@ def testPaginateSearchCommits(self): ) self.assertEqual(commits.totalCount, 3) + def testSearchCommits(self): + commits = self.g.search_commits( + query="hash:1265747e992ba7d34a469b6b2f527809f8bf7067", + sort="author-date", + order="asc", + merge="false", + ) + self.assertEqual(commits.totalCount, 2) + def testSearchTopics(self): topics = self.g.search_topics("python", repositories=">950") self.assertListKeyBegin( From 3c91ac8446f1915f37ad1881a8b98fcfbf3a57fa Mon Sep 17 00:00:00 2001 From: KimSia Sim Date: Sun, 24 Oct 2021 21:06:48 +0800 Subject: [PATCH 24/25] =?UTF-8?q?=E2=99=BB=20Restore=20back=20to=20origina?= =?UTF-8?q?l=20in=20main=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- github/MainClass.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/github/MainClass.py b/github/MainClass.py index 5b626ad265..be21ca1d7a 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -598,10 +598,14 @@ def search_commits( """ assert isinstance(query, str), query url_parameters = dict() - if sort is not github.GithubObject.NotSet: + if ( + sort is not github.GithubObject.NotSet + ): # pragma no branch (Should be covered) assert sort in ("author-date", "committer-date"), sort url_parameters["sort"] = sort - if order is not github.GithubObject.NotSet: + if ( + order is not github.GithubObject.NotSet + ): # pragma no branch (Should be covered) assert order in ("asc", "desc"), order url_parameters["order"] = order From 8531073b3d27dca59e21e5304e350e7a2b20de40 Mon Sep 17 00:00:00 2001 From: KimSia Sim <245021+simkimsia@users.noreply.github.com> Date: Sun, 24 Oct 2021 21:08:41 +0800 Subject: [PATCH 25/25] =?UTF-8?q?=E2=99=BB=20Make=20changes=20so=20it's=20?= =?UTF-8?q?closer=20to=20main=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ♻Rewrite to make things conform closer to main branch ♻ Fix f string ♻ Change to f string And also switch to the accept header recommended in https://docs.github.com/en/rest/reference/repos#create-a-repository-using-a-template ♻ Move away from `application/vnd.github.baptiste-preview+json` ✅Make tests pass ✅Fix tests 🎨 FIX: the formatting by running `tox -elint` --- github/AuthenticatedUser.py | 12 +- github/Organization.py | 6 +- github/Repository.py | 718 ++++++++++++++---- tests/AuthenticatedUser.py | 4 +- tests/Organization.py | 1 - ...ticatedUser.testCreateRepoFromTemplate.txt | 2 +- ...CreateRepoFromTemplateWithAllArguments.txt | 2 +- ...rganization.testCreateRepoFromTemplate.txt | 2 +- ...CreateRepoFromTemplateWithAllArguments.txt | 2 +- 9 files changed, 602 insertions(+), 147 deletions(-) diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py index 0655834e08..43018a5c60 100644 --- a/github/AuthenticatedUser.py +++ b/github/AuthenticatedUser.py @@ -517,7 +517,7 @@ def create_repo_from_template( private=github.GithubObject.NotSet, ): """ - :calls: `POST /repos/{template_owner}/{template_repo}/generate `_ + :calls: `POST /repos/{template_owner}/{template_repo}/generate `_ :param name: string :param repo :class:`github.Repository.Repository` :param description: string @@ -529,7 +529,9 @@ def create_repo_from_template( assert description is github.GithubObject.NotSet or isinstance( description, str ), description - assert private is github.GithubObject.NotSet or isinstance(private, bool), private + assert private is github.GithubObject.NotSet or isinstance( + private, bool + ), private post_parameters = { "name": name, "owner": self.login, @@ -542,9 +544,11 @@ def create_repo_from_template( "POST", f"/repos/{repo.owner.login}/{repo.name}/generate", input=post_parameters, - headers={"Accept": Consts.mediaTypeTemplatesPreview}, + headers={"Accept": "application/vnd.github.v3+json"}, + ) + return github.Repository.Repository( + self._requester, headers, data, completed=True ) - return github.Repository.Repository(self._requester, headers, data, completed=True) def create_gist(self, public, files, description=github.GithubObject.NotSet): """ diff --git a/github/Organization.py b/github/Organization.py index dcc97c1ad2..30901d68c9 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -411,7 +411,7 @@ def create_repo_from_template( private=github.GithubObject.NotSet, ): """self.name - :calls: `POST /repos/{template_owner}/{template_repo}/generate `_ + :calls: `POST /repos/{template_owner}/{template_repo}/generate `_ :param name: string :param repo :class:`github.Repository.Repository` :param description: string @@ -436,9 +436,9 @@ def create_repo_from_template( post_parameters["private"] = private headers, data = self._requester.requestJsonAndCheck( "POST", - "/repos/" + repo.owner.login + "/" + repo.name + "/generate", + f"/repos/{repo.owner.login}/{repo.name}/generate", input=post_parameters, - headers={"Accept": Consts.mediaTypeTemplatesPreview}, + headers={"Accept": "application/vnd.github.v3+json"}, ) return github.Repository.Repository( self._requester, headers, data, completed=True diff --git a/github/Repository.py b/github/Repository.py index 1f7effa17f..2ad4f6d2ec 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - ############################ Copyrights and license ############################ # # # Copyright 2012 Christopher Gilbert # @@ -66,6 +64,7 @@ # Copyright 2018 Zilei Gu # # Copyright 2018 Yves Zumbach # # Copyright 2018 Leying Chen # +# Copyright 2020 Pascal Hofmann # # # # This file is part of PyGithub. # # http://pygithub.readthedocs.io/ # @@ -93,11 +92,14 @@ from deprecated import deprecated import github.Branch +import github.CheckRun +import github.CheckSuite import github.Clones import github.Commit import github.CommitComment import github.Comparison import github.ContentFile +import github.Deployment import github.Download import github.Event import github.GitBlob @@ -120,10 +122,13 @@ import github.Path import github.Permissions import github.Project +import github.PublicKey import github.PullRequest import github.Referrer import github.Repository import github.RepositoryKey +import github.RepositoryPreferences +import github.SelfHostedActionsRunner import github.SourceImport import github.Stargazer import github.StatsCodeFrequency @@ -134,6 +139,8 @@ import github.Tag import github.Team import github.View +import github.Workflow +import github.WorkflowRun from . import Consts @@ -290,6 +297,14 @@ def delete_branch_on_merge(self): self._completeIfNotSet(self._delete_branch_on_merge) return self._delete_branch_on_merge.value + @property + def deployments_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._deployments_url) + return self._deployments_url.value + @property def description(self): """ @@ -402,6 +417,14 @@ def has_issues(self): self._completeIfNotSet(self._has_issues) return self._has_issues.value + @property + def has_pages(self): + """ + :type: bool + """ + self._completeIfNotSet(self._has_pages) + return self._has_pages.value + @property def has_projects(self): """ @@ -642,6 +665,14 @@ def pushed_at(self): self._completeIfNotSet(self._pushed_at) return self._pushed_at.value + @property + def releases_url(self): + """ + :type: string + """ + self._completeIfNotSet(self._releases_url) + return self._releases_url.value + @property def size(self): """ @@ -811,7 +842,7 @@ def add_to_collaborators(self, collaborator, permission=github.GithubObject.NotS put_parameters = None headers, data = self._requester.requestJsonAndCheck( - "PUT", self.url + "/collaborators/" + collaborator, input=put_parameters + "PUT", f"{self.url}/collaborators/{collaborator}", input=put_parameters ) # return an invitation object if there's data returned by the API. If data is empty # there's a pending invitation for the given user. @@ -833,31 +864,32 @@ def get_collaborator_permission(self, collaborator): if isinstance(collaborator, github.NamedUser.NamedUser): collaborator = collaborator._identity headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/collaborators/" + collaborator + "/permission", + "GET", + f"{self.url}/collaborators/{collaborator}/permission", ) return data["permission"] def get_pending_invitations(self): """ - :calls: `GET /repos/:owner/:repo/invitations `_ + :calls: `GET /repos/{owner}/{repo}/invitations `_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Invitation.Invitation` """ return github.PaginatedList.PaginatedList( github.Invitation.Invitation, self._requester, - self.url + "/invitations", + f"{self.url}/invitations", None, ) def remove_invitation(self, invite_id): """ - :calls: `DELETE /repos/:owner/:repo/invitations/:invitation_id `_ + :calls: `DELETE /repos/{owner}/{repo}/invitations/{invitation_id} `_ :rtype: None """ assert isinstance(invite_id, int), invite_id headers, data = self._requester.requestJsonAndCheck( - "DELETE", self.url + "/invitations/" + str(invite_id) + "DELETE", f"{self.url}/invitations/{invite_id}" ) def compare(self, base, head): @@ -870,7 +902,7 @@ def compare(self, base, head): assert isinstance(base, str), base assert isinstance(head, str), head headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/compare/" + base + "..." + head + "GET", f"{self.url}/compare/{base}...{head}" ) return github.Comparison.Comparison( self._requester, headers, data, completed=True @@ -890,7 +922,7 @@ def create_git_blob(self, content, encoding): "encoding": encoding, } headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/blobs", input=post_parameters + "POST", f"{self.url}/git/blobs", input=post_parameters ) return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) @@ -932,7 +964,7 @@ def create_git_commit( if committer is not github.GithubObject.NotSet: post_parameters["committer"] = committer._identity headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/commits", input=post_parameters + "POST", f"{self.url}/git/commits", input=post_parameters ) return github.GitCommit.GitCommit( self._requester, headers, data, completed=True @@ -952,7 +984,7 @@ def create_git_ref(self, ref, sha): "sha": sha, } headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/refs", input=post_parameters + "POST", f"{self.url}/git/refs", input=post_parameters ) return github.GitRef.GitRef(self._requester, headers, data, completed=True) @@ -968,6 +1000,20 @@ def create_git_tag_and_release( draft=False, prerelease=False, ): + """ + Convenience function that calls :meth:`Repository.create_git_tag` and + :meth:`Repository.create_git_release`. + :param tag: string + :param tag_message: string + :param release_name: string + :param release_message: string + :param object: string + :param type: string + :param tagger: :class:github.InputGitAuthor.InputGitAuthor + :param draft: bool + :param prerelease: bool + :rtype: :class:`github.GitRelease.GitRelease` + """ self.create_git_tag(tag, tag_message, object, type, tagger) return self.create_git_release( tag, @@ -1027,7 +1073,7 @@ def create_git_release( ): post_parameters["target_commitish"] = target_commitish.sha headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/releases", input=post_parameters + "POST", f"{self.url}/releases", input=post_parameters ) return github.GitRelease.GitRelease( self._requester, headers, data, completed=True @@ -1061,7 +1107,7 @@ def create_git_tag( if tagger is not github.GithubObject.NotSet: post_parameters["tagger"] = tagger._identity headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/tags", input=post_parameters + "POST", f"{self.url}/git/tags", input=post_parameters ) return github.GitTag.GitTag(self._requester, headers, data, completed=True) @@ -1084,7 +1130,7 @@ def create_git_tree(self, tree, base_tree=github.GithubObject.NotSet): if base_tree is not github.GithubObject.NotSet: post_parameters["base_tree"] = base_tree._identity headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/git/trees", input=post_parameters + "POST", f"{self.url}/git/trees", input=post_parameters ) return github.GitTree.GitTree(self._requester, headers, data, completed=True) @@ -1118,7 +1164,7 @@ def create_hook( if active is not github.GithubObject.NotSet: post_parameters["active"] = active headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/hooks", input=post_parameters + "POST", f"{self.url}/hooks", input=post_parameters ) return github.Hook.Hook(self._requester, headers, data, completed=True) @@ -1185,7 +1231,7 @@ def create_issue( for element in labels ] headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/issues", input=post_parameters + "POST", f"{self.url}/issues", input=post_parameters ) return github.Issue.Issue(self._requester, headers, data, completed=True) @@ -1206,7 +1252,7 @@ def create_key(self, title, key, read_only=False): "read_only": read_only, } headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/keys", input=post_parameters + "POST", f"{self.url}/keys", input=post_parameters ) return github.RepositoryKey.RepositoryKey( self._requester, headers, data, completed=True @@ -1233,7 +1279,7 @@ def create_label(self, name, color, description=github.GithubObject.NotSet): post_parameters["description"] = description headers, data = self._requester.requestJsonAndCheck( "POST", - self.url + "/labels", + f"{self.url}/labels", input=post_parameters, headers={"Accept": Consts.mediaTypeLabelDescriptionSearchPreview}, ) @@ -1275,7 +1321,7 @@ def create_milestone( else: post_parameters["due_on"] = due_on.isoformat() headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/milestones", input=post_parameters + "POST", f"{self.url}/milestones", input=post_parameters ) return github.Milestone.Milestone( self._requester, headers, data, completed=True @@ -1283,7 +1329,7 @@ def create_milestone( def create_project(self, name, body=github.GithubObject.NotSet): """ - :calls: `POST /repos/:owner/:repo/projects `_ + :calls: `POST /repos/{owner}/{repo}/projects `_ :param name: string :param body: string :rtype: :class:`github.Project.Project` @@ -1297,7 +1343,7 @@ def create_project(self, name, body=github.GithubObject.NotSet): if body is not github.GithubObject.NotSet: post_parameters["body"] = body headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/projects", headers=import_header, input=post_parameters + "POST", f"{self.url}/projects", headers=import_header, input=post_parameters ) return github.Project.Project(self._requester, headers, data, completed=True) @@ -1309,6 +1355,7 @@ def create_pull(self, *args, **kwds): :param issue: :class:`github.Issue.Issue` :param base: string :param head: string + :param draft: bool :param maintainer_can_modify: bool :rtype: :class:`github.PullRequest.PullRequest` """ @@ -1318,7 +1365,13 @@ def create_pull(self, *args, **kwds): return self.__create_pull_2(*args, **kwds) def __create_pull_1( - self, title, body, base, head, maintainer_can_modify=github.GithubObject.NotSet + self, + title, + body, + base, + head, + maintainer_can_modify=github.GithubObject.NotSet, + draft=False, ): assert isinstance(title, str), title assert isinstance(body, str), body @@ -1327,6 +1380,7 @@ def __create_pull_1( assert maintainer_can_modify is github.GithubObject.NotSet or isinstance( maintainer_can_modify, bool ), maintainer_can_modify + assert isinstance(draft, bool), draft if maintainer_can_modify is not github.GithubObject.NotSet: return self.__create_pull( title=title, @@ -1334,9 +1388,12 @@ def __create_pull_1( base=base, head=head, maintainer_can_modify=maintainer_can_modify, + draft=draft, ) else: - return self.__create_pull(title=title, body=body, base=base, head=head) + return self.__create_pull( + title=title, body=body, base=base, head=head, draft=draft + ) def __create_pull_2(self, issue, base, head): assert isinstance(issue, github.Issue.Issue), issue @@ -1346,13 +1403,67 @@ def __create_pull_2(self, issue, base, head): def __create_pull(self, **kwds): post_parameters = kwds + headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/pulls", input=post_parameters + "POST", f"{self.url}/pulls", input=post_parameters ) return github.PullRequest.PullRequest( self._requester, headers, data, completed=True ) + def create_repository_dispatch( + self, event_type, client_payload=github.GithubObject.NotSet + ): + """ + :calls: POST /repos/{owner}/{repo}/dispatches + :param event_type: string + :param client_payload: dict + :rtype: bool + """ + assert isinstance(event_type, str), event_type + assert client_payload is github.GithubObject.NotSet or isinstance( + client_payload, dict + ), client_payload + post_parameters = {"event_type": event_type} + if client_payload is not github.GithubObject.NotSet: + post_parameters["client_payload"] = client_payload + status, headers, data = self._requester.requestJson( + "POST", f"{self.url}/dispatches", input=post_parameters + ) + return status == 204 + + def create_secret(self, secret_name, unencrypted_value): + """ + :calls: `PUT /repos/{owner}/{repo}/actions/secrets/{secret_name} `_ + :param secret_name: string + :param unencrypted_value: string + :rtype: bool + """ + assert isinstance(secret_name, str), secret_name + assert isinstance(unencrypted_value, str), unencrypted_value + public_key = self.get_public_key() + payload = public_key.encrypt(unencrypted_value) + put_parameters = { + "key_id": public_key.key_id, + "encrypted_value": payload, + } + status, headers, data = self._requester.requestJson( + "PUT", f"{self.url}/actions/secrets/{secret_name}", input=put_parameters + ) + return status == 201 + + def delete_secret(self, secret_name): + """ + :calls: `DELETE /repos/{owner}/{repo}/actions/secrets/{secret_name} `_ + :param secret_name: string + :rtype: bool + """ + assert isinstance(secret_name, str), secret_name + status, headers, data = self._requester.requestJson( + "DELETE", f"{self.url}/actions/secrets/{secret_name}" + ) + return status == 204 + def create_source_import( self, vcs, @@ -1387,7 +1498,7 @@ def create_source_import( import_header = {"Accept": Consts.mediaTypeImportPreview} headers, data = self._requester.requestJsonAndCheck( - "PUT", self.url + "/import", headers=import_header, input=put_parameters + "PUT", f"{self.url}/import", headers=import_header, input=put_parameters ) return github.SourceImport.SourceImport( @@ -1521,9 +1632,9 @@ def get_archive_link(self, archive_format, ref=github.GithubObject.NotSet): """ assert isinstance(archive_format, str), archive_format assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref - url = self.url + "/" + archive_format + url = f"{self.url}/{archive_format}" if ref is not github.GithubObject.NotSet: - url += "/" + ref + url += f"/{ref}" headers, data = self._requester.requestJsonAndCheck("GET", url) return headers["location"] @@ -1533,7 +1644,7 @@ def get_assignees(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, self.url + "/assignees", None + github.NamedUser.NamedUser, self._requester, f"{self.url}/assignees", None ) def get_branch(self, branch): @@ -1544,7 +1655,7 @@ def get_branch(self, branch): """ assert isinstance(branch, str), branch headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/branches/" + branch + "GET", f"{self.url}/branches/{branch}" ) return github.Branch.Branch(self._requester, headers, data, completed=True) @@ -1575,7 +1686,7 @@ def get_branches(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Branch.Branch` """ return github.PaginatedList.PaginatedList( - github.Branch.Branch, self._requester, self.url + "/branches", None + github.Branch.Branch, self._requester, f"{self.url}/branches", None ) def get_collaborators(self, affiliation=github.GithubObject.NotSet): @@ -1591,13 +1702,13 @@ def get_collaborators(self, affiliation=github.GithubObject.NotSet): assert isinstance(affiliation, str), affiliation assert ( affiliation in allowed_affiliations - ), "Affiliation can be one of " + ", ".join(allowed_affiliations) + ), f"Affiliation can be one of {', '.join(allowed_affiliations)}" url_parameters["affiliation"] = affiliation return github.PaginatedList.PaginatedList( github.NamedUser.NamedUser, self._requester, - self.url + "/collaborators", + f"{self.url}/collaborators", url_parameters, ) @@ -1609,7 +1720,7 @@ def get_comment(self, id): """ assert isinstance(id, int), id headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/comments/" + str(id) + "GET", f"{self.url}/comments/{id}" ) return github.CommitComment.CommitComment( self._requester, headers, data, completed=True @@ -1623,7 +1734,7 @@ def get_comments(self): return github.PaginatedList.PaginatedList( github.CommitComment.CommitComment, self._requester, - self.url + "/comments", + f"{self.url}/comments", None, ) @@ -1635,7 +1746,7 @@ def get_commit(self, sha): """ assert isinstance(sha, str), sha headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/commits/" + sha + "GET", f"{self.url}/commits/{sha}" ) return github.Commit.Commit(self._requester, headers, data, completed=True) @@ -1693,7 +1804,7 @@ def get_commits( else: url_parameters["author"] = author return github.PaginatedList.PaginatedList( - github.Commit.Commit, self._requester, self.url + "/commits", url_parameters + github.Commit.Commit, self._requester, f"{self.url}/commits", url_parameters ) def get_contents(self, path, ref=github.GithubObject.NotSet): @@ -1713,7 +1824,7 @@ def get_contents(self, path, ref=github.GithubObject.NotSet): url_parameters["ref"] = ref headers, data = self._requester.requestJsonAndCheck( "GET", - self.url + "/contents/" + urllib.parse.quote(path), + f"{self.url}/contents/{urllib.parse.quote(path)}", parameters=url_parameters, ) @@ -1736,13 +1847,145 @@ def get_contents(self, path, ref=github.GithubObject.NotSet): self._requester, headers, data, completed=True ) + def get_deployments( + self, + sha=github.GithubObject.NotSet, + ref=github.GithubObject.NotSet, + task=github.GithubObject.NotSet, + environment=github.GithubObject.NotSet, + ): + """ + :calls: `GET /repos/{owner}/{repo}/deployments `_ + :param: sha: string + :param: ref: string + :param: task: string + :param: environment: string + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Deployment.Deployment` + """ + assert sha is github.GithubObject.NotSet or isinstance(sha, str), sha + assert ref is github.GithubObject.NotSet or isinstance(ref, str), ref + assert task is github.GithubObject.NotSet or isinstance(task, str), task + assert environment is github.GithubObject.NotSet or isinstance( + environment, str + ), environment + parameters = {} + if sha is not github.GithubObject.NotSet: + parameters["sha"] = sha + if ref is not github.GithubObject.NotSet: + parameters["ref"] = ref + if task is not github.GithubObject.NotSet: + parameters["task"] = task + if environment is not github.GithubObject.NotSet: + parameters["environment"] = environment + return github.PaginatedList.PaginatedList( + github.Deployment.Deployment, + self._requester, + f"{self.url}/deployments", + parameters, + headers={"Accept": Consts.deploymentEnhancementsPreview}, + ) + + def get_deployment(self, id_): + """ + :calls: `GET /repos/{owner}/{repo}/deployments/{deployment_id} `_ + :param: id_: int + :rtype: :class:`github.Deployment.Deployment` + """ + assert isinstance(id_, int), id_ + headers, data = self._requester.requestJsonAndCheck( + "GET", + f"{self.url}/deployments/{id_}", + headers={"Accept": Consts.deploymentEnhancementsPreview}, + ) + return github.Deployment.Deployment( + self._requester, headers, data, completed=True + ) + + def create_deployment( + self, + ref, + task=github.GithubObject.NotSet, + auto_merge=github.GithubObject.NotSet, + required_contexts=github.GithubObject.NotSet, + payload=github.GithubObject.NotSet, + environment=github.GithubObject.NotSet, + description=github.GithubObject.NotSet, + transient_environment=github.GithubObject.NotSet, + production_environment=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/{owner}/{repo}/deployments `_ + :param: ref: string + :param: task: string + :param: auto_merge: bool + :param: required_contexts: list of status contexts + :param: payload: dict + :param: environment: string + :param: description: string + :param: transient_environment: bool + :param: production_environment: bool + :rtype: :class:`github.Deployment.Deployment` + """ + assert isinstance(ref, str), ref + assert task is github.GithubObject.NotSet or isinstance(task, str), task + assert auto_merge is github.GithubObject.NotSet or isinstance( + auto_merge, bool + ), auto_merge + assert required_contexts is github.GithubObject.NotSet or isinstance( + required_contexts, list + ), required_contexts # need to do better checking here + assert payload is github.GithubObject.NotSet or isinstance( + payload, dict + ), payload + assert environment is github.GithubObject.NotSet or isinstance( + environment, str + ), environment + assert description is github.GithubObject.NotSet or isinstance( + description, str + ), description + assert transient_environment is github.GithubObject.NotSet or isinstance( + transient_environment, bool + ), transient_environment + assert production_environment is github.GithubObject.NotSet or isinstance( + production_environment, bool + ), production_environment + + post_parameters = {"ref": ref} + if task is not github.GithubObject.NotSet: + post_parameters["task"] = task + if auto_merge is not github.GithubObject.NotSet: + post_parameters["auto_merge"] = auto_merge + if required_contexts is not github.GithubObject.NotSet: + post_parameters["required_contexts"] = required_contexts + if payload is not github.GithubObject.NotSet: + post_parameters["payload"] = payload + if environment is not github.GithubObject.NotSet: + post_parameters["environment"] = environment + if description is not github.GithubObject.NotSet: + post_parameters["description"] = description + if transient_environment is not github.GithubObject.NotSet: + post_parameters["transient_environment"] = transient_environment + if production_environment is not github.GithubObject.NotSet: + post_parameters["production_environment"] = production_environment + + headers, data = self._requester.requestJsonAndCheck( + "POST", + f"{self.url}/deployments", + input=post_parameters, + headers={"Accept": Consts.deploymentEnhancementsPreview}, + ) + + return github.Deployment.Deployment( + self._requester, headers, data, completed=True + ) + def get_top_referrers(self): """ - :calls: `GET /repos/:owner/:repo/traffic/popular/referrers `_ + :calls: `GET /repos/{owner}/{repo}/traffic/popular/referrers `_ :rtype: :class:`list` of :class:`github.Referrer.Referrer` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/traffic/popular/referrers" + "GET", f"{self.url}/traffic/popular/referrers" ) if isinstance(data, list): return [ @@ -1752,11 +1995,11 @@ def get_top_referrers(self): def get_top_paths(self): """ - :calls: `GET /repos/:owner/:repo/traffic/popular/paths `_ + :calls: `GET /repos/{owner}/{repo}/traffic/popular/paths `_ :rtype: :class:`list` of :class:`github.Path.Path` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/traffic/popular/paths" + "GET", f"{self.url}/traffic/popular/paths" ) if isinstance(data, list): return [ @@ -1766,7 +2009,7 @@ def get_top_paths(self): def get_views_traffic(self, per=github.GithubObject.NotSet): """ - :calls: `GET /repos/:owner/:repo/traffic/views `_ + :calls: `GET /repos/{owner}/{repo}/traffic/views `_ :param per: string, must be one of day or week, day by default :rtype: None or list of :class:`github.View.View` """ @@ -1777,7 +2020,7 @@ def get_views_traffic(self, per=github.GithubObject.NotSet): if per is not github.GithubObject.NotSet: url_parameters["per"] = per headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/traffic/views", parameters=url_parameters + "GET", f"{self.url}/traffic/views", parameters=url_parameters ) if ( (isinstance(data, dict)) @@ -1792,9 +2035,9 @@ def get_views_traffic(self, per=github.GithubObject.NotSet): def get_clones_traffic(self, per=github.GithubObject.NotSet): """ - :calls: `GET /repos/:owner/:repo/traffic/clones `_ + :calls: `GET /repos/{owner}/{repo}/traffic/clones `_ :param per: string, must be one of day or week, day by default - :rtype: None or list of :class:`github.Clone.Clone` + :rtype: None or list of :class:`github.Clones.Clones` """ assert per is github.GithubObject.NotSet or ( isinstance(per, str) and (per == "day" or per == "week") @@ -1803,7 +2046,7 @@ def get_clones_traffic(self, per=github.GithubObject.NotSet): if per is not github.GithubObject.NotSet: url_parameters["per"] = per headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/traffic/clones", parameters=url_parameters + "GET", f"{self.url}/traffic/clones", parameters=url_parameters ) if ( (isinstance(data, dict)) @@ -1818,7 +2061,7 @@ def get_clones_traffic(self, per=github.GithubObject.NotSet): def get_projects(self, state=github.GithubObject.NotSet): """ - :calls: `GET /repos/:owner/:repo/projects `_ + :calls: `GET /repos/{owner}/{repo}/projects `_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Project.Project` :param state: string """ @@ -1830,7 +2073,7 @@ def get_projects(self, state=github.GithubObject.NotSet): return github.PaginatedList.PaginatedList( github.Project.Project, self._requester, - self.url + "/projects", + f"{self.url}/projects", url_parameters, {"Accept": Consts.mediaTypeProjectsPreview}, ) @@ -1846,7 +2089,7 @@ def create_file( ): """Create a file in this repository. - :calls: `PUT /repos/:owner/:repo/contents/:path `_ + :calls: `PUT /repos/{owner}/{repo}/contents/{path} `_ :param path: string, (required), path of the file in the repository :param message: string, (required), commit message :param content: string, (required), the actual data in the file @@ -1882,7 +2125,7 @@ def create_file( headers, data = self._requester.requestJsonAndCheck( "PUT", - self.url + "/contents/" + urllib.parse.quote(path), + f"{self.url}/contents/{urllib.parse.quote(path)}", input=put_parameters, ) @@ -1907,7 +2150,7 @@ def update_file( ): """This method updates a file in a repository - :calls: `PUT /repos/:owner/:repo/contents/:path `_ + :calls: `PUT /repos/{owner}/{repo}/contents/{path} `_ :param path: string, Required. The content path. :param message: string, Required. The commit message. :param content: string, Required. The updated file content, either base64 encoded, or ready to be encoded. @@ -1946,7 +2189,7 @@ def update_file( headers, data = self._requester.requestJsonAndCheck( "PUT", - self.url + "/contents/" + urllib.parse.quote(path), + f"{self.url}/contents/{urllib.parse.quote(path)}", input=put_parameters, ) @@ -1970,7 +2213,6 @@ def delete_file( ): """This method deletes a file in a repository - :calls: `DELETE /repos/{owner}/{repo}/contents/{path} `_ :param path: string, Required. The content path. :param message: string, Required. The commit message. @@ -2005,7 +2247,7 @@ def delete_file( headers, data = self._requester.requestJsonAndCheck( "DELETE", - self.url + "/contents/" + urllib.parse.quote(path), + f"{self.url}/contents/{urllib.parse.quote(path)}", input=url_parameters, ) @@ -2044,7 +2286,7 @@ def get_contributors(self, anon=github.GithubObject.NotSet): return github.PaginatedList.PaginatedList( github.NamedUser.NamedUser, self._requester, - self.url + "/contributors", + f"{self.url}/contributors", url_parameters, ) @@ -2056,7 +2298,7 @@ def get_download(self, id): """ assert isinstance(id, int), id headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/downloads/" + str(id) + "GET", f"{self.url}/downloads/{id}" ) return github.Download.Download(self._requester, headers, data, completed=True) @@ -2066,7 +2308,7 @@ def get_downloads(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Download.Download` """ return github.PaginatedList.PaginatedList( - github.Download.Download, self._requester, self.url + "/downloads", None + github.Download.Download, self._requester, f"{self.url}/downloads", None ) def get_events(self): @@ -2075,7 +2317,7 @@ def get_events(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event` """ return github.PaginatedList.PaginatedList( - github.Event.Event, self._requester, self.url + "/events", None + github.Event.Event, self._requester, f"{self.url}/events", None ) def get_forks(self): @@ -2084,7 +2326,7 @@ def get_forks(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ return github.PaginatedList.PaginatedList( - Repository, self._requester, self.url + "/forks", None + Repository, self._requester, f"{self.url}/forks", None ) def create_fork(self, organization=github.GithubObject.NotSet): @@ -2100,7 +2342,9 @@ def create_fork(self, organization=github.GithubObject.NotSet): if organization is not github.GithubObject.NotSet: post_parameters["organization"] = organization headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/forks", input=post_parameters, + "POST", + f"{self.url}/forks", + input=post_parameters, ) return Repository(self._requester, headers, data, completed=True) @@ -2112,7 +2356,7 @@ def get_git_blob(self, sha): """ assert isinstance(sha, str), sha headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/git/blobs/" + sha + "GET", f"{self.url}/git/blobs/{sha}" ) return github.GitBlob.GitBlob(self._requester, headers, data, completed=True) @@ -2124,7 +2368,7 @@ def get_git_commit(self, sha): """ assert isinstance(sha, str), sha headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/git/commits/" + sha + "GET", f"{self.url}/git/commits/{sha}" ) return github.GitCommit.GitCommit( self._requester, headers, data, completed=True @@ -2141,7 +2385,7 @@ def get_git_ref(self, ref): prefix = "/git/" assert isinstance(ref, str), ref headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + prefix + ref + "GET", f"{self.url}{prefix}{ref}" ) return github.GitRef.GitRef(self._requester, headers, data, completed=True) @@ -2175,7 +2419,7 @@ def get_git_tag(self, sha): """ assert isinstance(sha, str), sha headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/git/tags/" + sha + "GET", f"{self.url}/git/tags/{sha}" ) return github.GitTag.GitTag(self._requester, headers, data, completed=True) @@ -2195,7 +2439,7 @@ def get_git_tree(self, sha, recursive=github.GithubObject.NotSet): # GitHub API requires the recursive parameter be set to 1. url_parameters["recursive"] = 1 headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/git/trees/" + sha, parameters=url_parameters + "GET", f"{self.url}/git/trees/{sha}", parameters=url_parameters ) return github.GitTree.GitTree(self._requester, headers, data, completed=True) @@ -2207,7 +2451,7 @@ def get_hook(self, id): """ assert isinstance(id, int), id headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/hooks/" + str(id) + "GET", f"{self.url}/hooks/{id}" ) return github.Hook.Hook(self._requester, headers, data, completed=True) @@ -2217,7 +2461,7 @@ def get_hooks(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Hook.Hook` """ return github.PaginatedList.PaginatedList( - github.Hook.Hook, self._requester, self.url + "/hooks", None + github.Hook.Hook, self._requester, f"{self.url}/hooks", None ) def get_issue(self, number): @@ -2228,7 +2472,7 @@ def get_issue(self, number): """ assert isinstance(number, int), number headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/issues/" + str(number) + "GET", f"{self.url}/issues/{number}" ) return github.Issue.Issue(self._requester, headers, data, completed=True) @@ -2322,7 +2566,7 @@ def get_issues( else: url_parameters["creator"] = creator._identity return github.PaginatedList.PaginatedList( - github.Issue.Issue, self._requester, self.url + "/issues", url_parameters + github.Issue.Issue, self._requester, f"{self.url}/issues", url_parameters ) def get_issues_comments( @@ -2355,7 +2599,7 @@ def get_issues_comments( return github.PaginatedList.PaginatedList( github.IssueComment.IssueComment, self._requester, - self.url + "/issues/comments", + f"{self.url}/issues/comments", url_parameters, ) @@ -2368,7 +2612,7 @@ def get_issues_event(self, id): assert isinstance(id, int), id headers, data = self._requester.requestJsonAndCheck( "GET", - self.url + "/issues/events/" + str(id), + f"{self.url}/issues/events/{id}", headers={"Accept": Consts.mediaTypeLockReasonPreview}, ) return github.IssueEvent.IssueEvent( @@ -2383,7 +2627,7 @@ def get_issues_events(self): return github.PaginatedList.PaginatedList( github.IssueEvent.IssueEvent, self._requester, - self.url + "/issues/events", + f"{self.url}/issues/events", None, headers={"Accept": Consts.mediaTypeLockReasonPreview}, ) @@ -2396,7 +2640,7 @@ def get_key(self, id): """ assert isinstance(id, int), id headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/keys/" + str(id) + "GET", f"{self.url}/keys/{id}" ) return github.RepositoryKey.RepositoryKey( self._requester, headers, data, completed=True @@ -2410,7 +2654,7 @@ def get_keys(self): return github.PaginatedList.PaginatedList( github.RepositoryKey.RepositoryKey, self._requester, - self.url + "/keys", + f"{self.url}/keys", None, ) @@ -2422,7 +2666,7 @@ def get_label(self, name): """ assert isinstance(name, str), name headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/labels/" + urllib.parse.quote(name) + "GET", f"{self.url}/labels/{urllib.parse.quote(name)}" ) return github.Label.Label(self._requester, headers, data, completed=True) @@ -2432,7 +2676,7 @@ def get_labels(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Label.Label` """ return github.PaginatedList.PaginatedList( - github.Label.Label, self._requester, self.url + "/labels", None + github.Label.Label, self._requester, f"{self.url}/labels", None ) def get_languages(self): @@ -2441,18 +2685,18 @@ def get_languages(self): :rtype: dict of string to integer """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/languages" + "GET", f"{self.url}/languages" ) return data def get_license(self): """ - :calls: `GET /repos/:owner/:repo/license `_ + :calls: `GET /repos/{owner}/{repo}/license `_ :rtype: :class:`github.ContentFile.ContentFile` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/license" + "GET", f"{self.url}/license" ) return github.ContentFile.ContentFile( self._requester, headers, data, completed=True @@ -2466,7 +2710,7 @@ def get_milestone(self, number): """ assert isinstance(number, int), number headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/milestones/" + str(number) + "GET", f"{self.url}/milestones/{number}" ) return github.Milestone.Milestone( self._requester, headers, data, completed=True @@ -2500,7 +2744,7 @@ def get_milestones( return github.PaginatedList.PaginatedList( github.Milestone.Milestone, self._requester, - self.url + "/milestones", + f"{self.url}/milestones", url_parameters, ) @@ -2512,10 +2756,22 @@ def get_network_events(self): return github.PaginatedList.PaginatedList( github.Event.Event, self._requester, - "/networks/" + self.owner.login + "/" + self.name + "/events", + f"/networks/{self.owner.login}/{self.name}/events", None, ) + def get_public_key(self): + """ + :calls: `GET /repos/{owner}/{repo}/actions/secrets/public-key `_ + :rtype: :class:`github.PublicKey.PublicKey` + """ + headers, data = self._requester.requestJsonAndCheck( + "GET", f"{self.url}/actions/secrets/public-key" + ) + return github.PublicKey.PublicKey( + self._requester, headers, data, completed=True + ) + def get_pull(self, number): """ :calls: `GET /repos/{owner}/{repo}/pulls/{number} `_ @@ -2524,7 +2780,7 @@ def get_pull(self, number): """ assert isinstance(number, int), number headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/pulls/" + str(number) + "GET", f"{self.url}/pulls/{number}" ) return github.PullRequest.PullRequest( self._requester, headers, data, completed=True @@ -2568,7 +2824,7 @@ def get_pulls( return github.PaginatedList.PaginatedList( github.PullRequest.PullRequest, self._requester, - self.url + "/pulls", + f"{self.url}/pulls", url_parameters, ) @@ -2617,7 +2873,7 @@ def get_pulls_review_comments( return github.PaginatedList.PaginatedList( github.PullRequestComment.PullRequestComment, self._requester, - self.url + "/pulls/comments", + f"{self.url}/pulls/comments", url_parameters, ) @@ -2632,12 +2888,39 @@ def get_readme(self, ref=github.GithubObject.NotSet): if ref is not github.GithubObject.NotSet: url_parameters["ref"] = ref headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/readme", parameters=url_parameters + "GET", f"{self.url}/readme", parameters=url_parameters ) return github.ContentFile.ContentFile( self._requester, headers, data, completed=True ) + def get_self_hosted_runner(self, runner_id): + """ + :calls: `GET /repos/{owner}/{repo}/actions/runners/{id} `_ + :param runner_id: int + :rtype: :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` + """ + assert isinstance(runner_id, int), runner_id + headers, data = self._requester.requestJsonAndCheck( + "GET", f"{self.url}/actions/runners/{runner_id}" + ) + return github.SelfHostedActionsRunner.SelfHostedActionsRunner( + self._requester, headers, data, completed=True + ) + + def get_self_hosted_runners(self): + """ + :calls: `GET /repos/{owner}/{repo}/actions/runners `_ + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` + """ + return github.PaginatedList.PaginatedList( + github.SelfHostedActionsRunner.SelfHostedActionsRunner, + self._requester, + f"{self.url}/actions/runners", + None, + list_item="runners", + ) + def get_source_import(self): """ :calls: `GET /repos/{owner}/{repo}/import `_ @@ -2645,7 +2928,9 @@ def get_source_import(self): """ import_header = {"Accept": Consts.mediaTypeImportPreview} headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/import", headers=import_header, + "GET", + f"{self.url}/import", + headers=import_header, ) if not data: return None @@ -2660,7 +2945,7 @@ def get_stargazers(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, self.url + "/stargazers", None + github.NamedUser.NamedUser, self._requester, f"{self.url}/stargazers", None ) def get_stargazers_with_dates(self): @@ -2671,7 +2956,7 @@ def get_stargazers_with_dates(self): return github.PaginatedList.PaginatedList( github.Stargazer.Stargazer, self._requester, - self.url + "/stargazers", + f"{self.url}/stargazers", None, headers={"Accept": Consts.mediaTypeStarringPreview}, ) @@ -2682,7 +2967,7 @@ def get_stats_contributors(self): :rtype: None or list of :class:`github.StatsContributor.StatsContributor` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/contributors" + "GET", f"{self.url}/stats/contributors" ) if not data: return None @@ -2700,7 +2985,7 @@ def get_stats_commit_activity(self): :rtype: None or list of :class:`github.StatsCommitActivity.StatsCommitActivity` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/commit_activity" + "GET", f"{self.url}/stats/commit_activity" ) if not data: return None @@ -2718,7 +3003,7 @@ def get_stats_code_frequency(self): :rtype: None or list of :class:`github.StatsCodeFrequency.StatsCodeFrequency` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/code_frequency" + "GET", f"{self.url}/stats/code_frequency" ) if not data: return None @@ -2736,7 +3021,7 @@ def get_stats_participation(self): :rtype: None or :class:`github.StatsParticipation.StatsParticipation` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/participation" + "GET", f"{self.url}/stats/participation" ) if not data: return None @@ -2751,7 +3036,7 @@ def get_stats_punch_card(self): :rtype: None or :class:`github.StatsPunchCard.StatsPunchCard` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/stats/punch_card" + "GET", f"{self.url}/stats/punch_card" ) if not data: return None @@ -2766,7 +3051,7 @@ def get_subscribers(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` """ return github.PaginatedList.PaginatedList( - github.NamedUser.NamedUser, self._requester, self.url + "/subscribers", None + github.NamedUser.NamedUser, self._requester, f"{self.url}/subscribers", None ) def get_tags(self): @@ -2775,7 +3060,7 @@ def get_tags(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Tag.Tag` """ return github.PaginatedList.PaginatedList( - github.Tag.Tag, self._requester, self.url + "/tags", None + github.Tag.Tag, self._requester, f"{self.url}/tags", None ) def get_releases(self): @@ -2784,7 +3069,7 @@ def get_releases(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.GitRelease.GitRelease` """ return github.PaginatedList.PaginatedList( - github.GitRelease.GitRelease, self._requester, self.url + "/releases", None + github.GitRelease.GitRelease, self._requester, f"{self.url}/releases", None ) def get_release(self, id): @@ -2795,14 +3080,14 @@ def get_release(self, id): """ if isinstance(id, int): headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/releases/" + str(id) + "GET", f"{self.url}/releases/{id}" ) return github.GitRelease.GitRelease( self._requester, headers, data, completed=True ) elif isinstance(id, str): headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/releases/tags/" + id + "GET", f"{self.url}/releases/tags/{id}" ) return github.GitRelease.GitRelease( self._requester, headers, data, completed=True @@ -2814,7 +3099,7 @@ def get_latest_release(self): :rtype: :class:`github.GitRelease.GitRelease` """ headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/releases/latest" + "GET", f"{self.url}/releases/latest" ) return github.GitRelease.GitRelease( self._requester, headers, data, completed=True @@ -2826,7 +3111,7 @@ def get_teams(self): :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team` """ return github.PaginatedList.PaginatedList( - github.Team.Team, self._requester, self.url + "/teams", None + github.Team.Team, self._requester, f"{self.url}/teams", None ) def get_topics(self): @@ -2836,7 +3121,7 @@ def get_topics(self): """ headers, data = self._requester.requestJsonAndCheck( "GET", - self.url + "/topics", + f"{self.url}/topics", headers={"Accept": Consts.mediaTypeTopicsPreview}, ) return data["names"] @@ -2958,7 +3243,7 @@ def has_in_assignees(self, assignee): assignee = assignee._identity status, headers, data = self._requester.requestJson( - "GET", self.url + "/assignees/" + assignee + "GET", f"{self.url}/assignees/{assignee}" ) return status == 204 @@ -2976,17 +3261,17 @@ def has_in_collaborators(self, collaborator): collaborator = collaborator._identity status, headers, data = self._requester.requestJson( - "GET", self.url + "/collaborators/" + collaborator + "GET", f"{self.url}/collaborators/{collaborator}" ) return status == 204 def _legacy_convert_issue(self, attributes): convertedAttributes = { "number": attributes["number"], - "url": "/repos" + urllib.parse.urlparse(attributes["html_url"]).path, + "url": f"/repos{urllib.parse.urlparse(attributes['html_url']).path}", "user": { "login": attributes["user"], - "url": "/users/" + attributes["user"], + "url": f"/users/{attributes['user']}", }, } if "labels" in attributes: # pragma no branch @@ -3003,20 +3288,13 @@ def legacy_search_issues(self, state, keyword): :calls: `GET /legacy/issues/search/{owner}/{repository}/{state}/{keyword} `_ :param state: "open" or "closed" :param keyword: string - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue` + :rtype: List of :class:`github.Issue.Issue` """ assert state in ["open", "closed"], state assert isinstance(keyword, str), keyword headers, data = self._requester.requestJsonAndCheck( "GET", - "/legacy/issues/search/" - + self.owner.login - + "/" - + self.name - + "/" - + state - + "/" - + urllib.parse.quote(keyword), + f"/legacy/issues/search/{self.owner.login}/{self.name}/{state}/{urllib.parse.quote(keyword)}", ) return [ github.Issue.Issue( @@ -3068,20 +3346,20 @@ def get_notifications( return github.PaginatedList.PaginatedList( github.Notification.Notification, self._requester, - self.url + "/notifications", + f"{self.url}/notifications", params, ) def mark_notifications_as_read(self, last_read_at=datetime.datetime.utcnow()): """ - :calls: `PUT /repos/:owner/:repo/notifications `_ + :calls: `PUT /repos/{owner}/{repo}/notifications `_ :param last_read_at: datetime """ assert isinstance(last_read_at, datetime.datetime) put_parameters = {"last_read_at": last_read_at.strftime("%Y-%m-%dT%H:%M:%SZ")} headers, data = self._requester.requestJsonAndCheck( - "PUT", self.url + "/notifications", input=put_parameters + "PUT", f"{self.url}/notifications", input=put_parameters ) def merge(self, base, head, commit_message=github.GithubObject.NotSet): @@ -3104,7 +3382,7 @@ def merge(self, base, head, commit_message=github.GithubObject.NotSet): if commit_message is not github.GithubObject.NotSet: post_parameters["commit_message"] = commit_message headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/merges", input=post_parameters + "POST", f"{self.url}/merges", input=post_parameters ) if data is None: return None @@ -3120,7 +3398,7 @@ def replace_topics(self, topics): post_parameters = {"names": topics} headers, data = self._requester.requestJsonAndCheck( "PUT", - self.url + "/topics", + f"{self.url}/topics", headers={"Accept": Consts.mediaTypeTopicsPreview}, input=post_parameters, ) @@ -3132,7 +3410,7 @@ def get_vulnerability_alert(self): """ status, _, _ = self._requester.requestJson( "GET", - self.url + "/vulnerability-alerts", + f"{self.url}/vulnerability-alerts", headers={"Accept": Consts.vulnerabilityAlertsPreview}, ) return status == 204 @@ -3144,7 +3422,7 @@ def enable_vulnerability_alert(self): """ status, _, _ = self._requester.requestJson( "PUT", - self.url + "/vulnerability-alerts", + f"{self.url}/vulnerability-alerts", headers={"Accept": Consts.vulnerabilityAlertsPreview}, ) return status == 204 @@ -3156,7 +3434,7 @@ def disable_vulnerability_alert(self): """ status, _, _ = self._requester.requestJson( "DELETE", - self.url + "/vulnerability-alerts", + f"{self.url}/vulnerability-alerts", headers={"Accept": Consts.vulnerabilityAlertsPreview}, ) return status == 204 @@ -3168,7 +3446,7 @@ def enable_automated_security_fixes(self): """ status, _, _ = self._requester.requestJson( "PUT", - self.url + "/automated-security-fixes", + f"{self.url}/automated-security-fixes", headers={"Accept": Consts.automatedSecurityFixes}, ) return status == 204 @@ -3180,7 +3458,7 @@ def disable_automated_security_fixes(self): """ status, _, _ = self._requester.requestJson( "DELETE", - self.url + "/automated-security-fixes", + f"{self.url}/automated-security-fixes", headers={"Accept": Consts.automatedSecurityFixes}, ) return status == 204 @@ -3199,12 +3477,30 @@ def remove_from_collaborators(self, collaborator): collaborator = collaborator._identity headers, data = self._requester.requestJsonAndCheck( - "DELETE", self.url + "/collaborators/" + collaborator + "DELETE", f"{self.url}/collaborators/{collaborator}" ) + def remove_self_hosted_runner(self, runner): + """ + :calls: `DELETE /repos/{owner}/{repo}/actions/runners/{runner_id} `_ + :param runner: int or :class:`github.SelfHostedActionsRunner.SelfHostedActionsRunner` + :rtype: bool + """ + assert isinstance( + runner, github.SelfHostedActionsRunner.SelfHostedActionsRunner + ) or isinstance(runner, int), runner + + if isinstance(runner, github.SelfHostedActionsRunner.SelfHostedActionsRunner): + runner = runner.id + + status, _, _ = self._requester.requestJson( + "DELETE", f"{self.url}/actions/runners/{runner}" + ) + return status == 204 + def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet): """ - :calls: `POST /hub `_ + :calls: `POST /hub `_ :param event: string :param callback: string :param secret: string @@ -3214,7 +3510,7 @@ def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet): def unsubscribe_from_hub(self, event, callback): """ - :calls: `POST /hub `_ + :calls: `POST /hub `_ :param event: string :param callback: string :param secret: string @@ -3222,6 +3518,57 @@ def unsubscribe_from_hub(self, event, callback): """ return self._hub("unsubscribe", event, callback, github.GithubObject.NotSet) + def create_check_suite(self, head_sha): + """ + :calls: `POST /repos/{owner}/{repo}/check-suites `_ + :param head_sha: string + :rtype: :class:`github.CheckSuite.CheckSuite` + """ + assert isinstance(head_sha, str), head_sha + headers, data = self._requester.requestJsonAndCheck( + "POST", + f"{self.url}/check-suites", + input={"head_sha": head_sha}, + ) + return github.CheckSuite.CheckSuite( + self._requester, headers, data, completed=True + ) + + def get_check_suite(self, check_suite_id): + """ + :calls: `GET /repos/{owner}/{repo}/check-suites/{check_suite_id} `_ + :param check_suite_id: int + :rtype: :class:`github.CheckSuite.CheckSuite` + """ + assert isinstance(check_suite_id, int), check_suite_id + requestHeaders = {"Accept": "application/vnd.github.v3+json"} + headers, data = self._requester.requestJsonAndCheck( + "GET", + f"{self.url}/check-suites/{check_suite_id}", + headers=requestHeaders, + ) + return github.CheckSuite.CheckSuite( + self._requester, headers, data, completed=True + ) + + def update_check_suites_preferences(self, auto_trigger_checks): + """ + :calls: `PATCH /repos/{owner}/{repo}/check-suites/preferences `_ + :param auto_trigger_checks: list of dict + :rtype: :class:`github.RepositoryPreferences.RepositoryPreferences` + """ + assert all( + isinstance(element, dict) for element in auto_trigger_checks + ), auto_trigger_checks + headers, data = self._requester.requestJsonAndCheck( + "PATCH", + f"{self.url}/check-suites/preferences", + input={"auto_trigger_checks": auto_trigger_checks}, + ) + return github.RepositoryPreferences.RepositoryPreferences( + self._requester, headers, data, completed=True + ) + def _hub(self, mode, event, callback, secret): assert isinstance(mode, str), mode assert isinstance(event, str), event @@ -3230,9 +3577,9 @@ def _hub(self, mode, event, callback, secret): post_parameters = collections.OrderedDict() post_parameters["hub.callback"] = callback - post_parameters["hub.topic"] = ( - "https://github.com/" + self.full_name + "/events/" + event - ) + post_parameters[ + "hub.topic" + ] = f"https://github.com/{self.full_name}/events/{event}" post_parameters["hub.mode"] = mode if secret is not github.GithubObject.NotSet: post_parameters["hub.secret"] = secret @@ -3243,18 +3590,110 @@ def _hub(self, mode, event, callback, secret): @property def _identity(self): - return self.owner.login + "/" + self.name + return f"{self.owner.login}/{self.name}" def get_release_asset(self, id): assert isinstance(id, (int)), id resp_headers, data = self._requester.requestJsonAndCheck( - "GET", self.url + "/releases/assets/" + str(id) + "GET", f"{self.url}/releases/assets/{id}" ) return github.GitReleaseAsset.GitReleaseAsset( self._requester, resp_headers, data, completed=True ) + def create_check_run( + self, + name, + head_sha, + details_url=github.GithubObject.NotSet, + external_id=github.GithubObject.NotSet, + status=github.GithubObject.NotSet, + started_at=github.GithubObject.NotSet, + conclusion=github.GithubObject.NotSet, + completed_at=github.GithubObject.NotSet, + output=github.GithubObject.NotSet, + actions=github.GithubObject.NotSet, + ): + """ + :calls: `POST /repos/{owner}/{repo}/check-runs `_ + :param name: string + :param head_sha: string + :param details_url: string + :param external_id: string + :param status: string + :param started_at: datetime.datetime + :param conclusion: string + :param completed_at: datetime.datetime + :param output: dict + :param actions: list of dict + :rtype: :class:`github.CheckRun.CheckRun` + """ + assert isinstance(name, str), name + assert isinstance(head_sha, str), head_sha + assert details_url is github.GithubObject.NotSet or isinstance( + details_url, str + ), details_url + assert external_id is github.GithubObject.NotSet or isinstance( + external_id, str + ), external_id + assert status is github.GithubObject.NotSet or isinstance(status, str), status + assert started_at is github.GithubObject.NotSet or isinstance( + started_at, datetime.datetime + ), started_at + assert conclusion is github.GithubObject.NotSet or isinstance( + conclusion, str + ), conclusion + assert completed_at is github.GithubObject.NotSet or isinstance( + completed_at, datetime.datetime + ), completed_at + assert output is github.GithubObject.NotSet or isinstance(output, dict), output + assert actions is github.GithubObject.NotSet or all( + isinstance(element, dict) for element in actions + ), actions + + post_parameters = { + "name": name, + "head_sha": head_sha, + } + if details_url is not github.GithubObject.NotSet: + post_parameters["details_url"] = details_url + if external_id is not github.GithubObject.NotSet: + post_parameters["external_id"] = external_id + if status is not github.GithubObject.NotSet: + post_parameters["status"] = status + if started_at is not github.GithubObject.NotSet: + post_parameters["started_at"] = started_at.strftime("%Y-%m-%dT%H:%M:%SZ") + if completed_at is not github.GithubObject.NotSet: + post_parameters["completed_at"] = completed_at.strftime( + "%Y-%m-%dT%H:%M:%SZ" + ) + if conclusion is not github.GithubObject.NotSet: + post_parameters["conclusion"] = conclusion + if output is not github.GithubObject.NotSet: + post_parameters["output"] = output + if actions is not github.GithubObject.NotSet: + post_parameters["actions"] = actions + + headers, data = self._requester.requestJsonAndCheck( + "POST", + f"{self.url}/check-runs", + input=post_parameters, + ) + return github.CheckRun.CheckRun(self._requester, headers, data, completed=True) + + def get_check_run(self, check_run_id): + """ + :calls: `GET /repos/{owner}/{repo}/check-runs/{check_run_id} `_ + :param check_run_id: int + :rtype: :class:`github.CheckRun.CheckRun` + """ + assert isinstance(check_run_id, int), check_run_id + headers, data = self._requester.requestJsonAndCheck( + "GET", f"{self.url}/check-runs/{check_run_id}" + ) + return github.CheckRun.CheckRun(self._requester, headers, data, completed=True) + def _initAttributes(self): self._allow_merge_commit = github.GithubObject.NotSet self._allow_rebase_merge = github.GithubObject.NotSet @@ -3274,6 +3713,7 @@ def _initAttributes(self): self._created_at = github.GithubObject.NotSet self._default_branch = github.GithubObject.NotSet self._delete_branch_on_merge = github.GithubObject.NotSet + self._deployments_url = github.GithubObject.NotSet self._description = github.GithubObject.NotSet self._downloads_url = github.GithubObject.NotSet self._events_url = github.GithubObject.NotSet @@ -3288,6 +3728,7 @@ def _initAttributes(self): self._git_url = github.GithubObject.NotSet self._has_downloads = github.GithubObject.NotSet self._has_issues = github.GithubObject.NotSet + self._has_pages = github.GithubObject.NotSet self._has_projects = github.GithubObject.NotSet self._has_wiki = github.GithubObject.NotSet self._homepage = github.GithubObject.NotSet @@ -3318,6 +3759,7 @@ def _initAttributes(self): self._private = github.GithubObject.NotSet self._pulls_url = github.GithubObject.NotSet self._pushed_at = github.GithubObject.NotSet + self._releases_url = github.GithubObject.NotSet self._size = github.GithubObject.NotSet self._source = github.GithubObject.NotSet self._ssh_url = github.GithubObject.NotSet @@ -3388,6 +3830,10 @@ def _useAttributes(self, attributes): self._delete_branch_on_merge = self._makeBoolAttribute( attributes["delete_branch_on_merge"] ) + if "deployments_url" in attributes: # pragma no branch + self._deployments_url = self._makeStringAttribute( + attributes["deployments_url"] + ) if "description" in attributes: # pragma no branch self._description = self._makeStringAttribute(attributes["description"]) if "downloads_url" in attributes: # pragma no branch @@ -3418,6 +3864,8 @@ def _useAttributes(self, attributes): self._has_downloads = self._makeBoolAttribute(attributes["has_downloads"]) if "has_issues" in attributes: # pragma no branch self._has_issues = self._makeBoolAttribute(attributes["has_issues"]) + if "has_pages" in attributes: # pragma no branch + self._has_pages = self._makeBoolAttribute(attributes["has_pages"]) if "has_projects" in attributes: # pragma no branch self._has_projects = self._makeBoolAttribute(attributes["has_projects"]) if "has_wiki" in attributes: # pragma no branch @@ -3494,6 +3942,8 @@ def _useAttributes(self, attributes): self._pulls_url = self._makeStringAttribute(attributes["pulls_url"]) if "pushed_at" in attributes: # pragma no branch self._pushed_at = self._makeDatetimeAttribute(attributes["pushed_at"]) + if "releases_url" in attributes: # pragma no branch + self._releases_url = self._makeStringAttribute(attributes["releases_url"]) if "size" in attributes: # pragma no branch self._size = self._makeIntAttribute(attributes["size"]) if "source" in attributes: # pragma no branch diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py index c4a378d12e..ca0b999fdf 100644 --- a/tests/AuthenticatedUser.py +++ b/tests/AuthenticatedUser.py @@ -667,7 +667,9 @@ def testCreateFork(self): def testCreateRepoFromTemplate(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") - repo = self.user.create_repo_from_template("hello-world-docker-action-new", template_repo) + repo = self.user.create_repo_from_template( + "hello-world-docker-action-new", template_repo + ) self.assertEqual( repo.url, "https://api.github.com/repos/jacquev6/hello-world-docker-action-new", diff --git a/tests/Organization.py b/tests/Organization.py index b24487a550..bed1b0e0d2 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -357,7 +357,6 @@ def testCreateFork(self): self.assertFalse(repo.has_wiki) self.assertFalse(repo.has_pages) - def testCreateRepoFromTemplate(self): template_repo = self.g.get_repo("actions/hello-world-docker-action") diff --git a/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt index 3ab48b9c2e..17d22aa222 100644 --- a/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt +++ b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplate.txt @@ -25,7 +25,7 @@ POST api.github.com None /repos/actions/hello-world-docker-action/generate -{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{'Accept': 'application/vnd.github.v3+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} {"name": "hello-world-docker-action-new", "owner": "jacquev6"} 201 [('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 16:56:49 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '11775'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4995'), ('X-RateLimit-Reset', '1581443568'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"eabd6fce61227c57848e030e45c468c3"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/jacquev6/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '8C7A:1AEB:84521:F940F:5E42DCCE')] diff --git a/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt index 13bbac4fb8..c150a5773a 100644 --- a/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt +++ b/tests/ReplayData/AuthenticatedUser.testCreateRepoFromTemplateWithAllArguments.txt @@ -25,7 +25,7 @@ POST api.github.com None /repos/actions/hello-world-docker-action/generate -{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{'Accept': 'application/vnd.github.v3+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} {"name": "hello-world-docker-action-new", "owner": "jacquev6", "description": "My repo from template", "private": true} 201 [('Server', 'GitHub.com'), ('Date', 'Tue, 11 Feb 2020 19:18:59 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '11794'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4994'), ('X-RateLimit-Reset', '1581452316'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"7fe9f51a711de4ffab9b930e33e3d875"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/jacquev6/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '3FB4:2492:632B7:FC388:5E42FE21')] diff --git a/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt b/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt index 9d97746918..95846f8a67 100644 --- a/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt +++ b/tests/ReplayData/Organization.testCreateRepoFromTemplate.txt @@ -14,7 +14,7 @@ POST api.github.com None /repos/actions/hello-world-docker-action/generate -{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{'Accept': 'application/vnd.github.v3+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} {"name": "hello-world-docker-action-new", "owner": "BeaverSoftware"} 201 [('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 13:54:29 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '12600'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4997'), ('X-RateLimit-Reset', '1581519266'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"36abdc4630fb044196d6efbfc0f644e0"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '8C3C:2BF7:ACD4:17C45:5E440393')] diff --git a/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt b/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt index 8e45505ef5..210ab41645 100644 --- a/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt +++ b/tests/ReplayData/Organization.testCreateRepoFromTemplateWithAllArguments.txt @@ -14,7 +14,7 @@ POST api.github.com None /repos/actions/hello-world-docker-action/generate -{'Accept': 'application/vnd.github.baptiste-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{'Accept': 'application/vnd.github.v3+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} {"name": "hello-world-docker-action-new", "owner": "BeaverSoftware", "description": "My repo from template", "private": true} 201 [('Server', 'GitHub.com'), ('Date', 'Wed, 12 Feb 2020 18:18:12 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '12619'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4991'), ('X-RateLimit-Reset', '1581534987'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept'), ('ETag', '"7ab10890a25b4661a4310dc8dbf4491f"'), ('X-OAuth-Scopes', 'public_repo, read:org, read:user, user:email'), ('X-Accepted-OAuth-Scopes', ''), ('Location', 'https://api.github.com/repos/BeaverSoftware/hello-world-docker-action-new'), ('X-GitHub-Media-Type', 'github.baptiste-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', 'C35C:1792:11E12C:2D04D2:5E444162')]