From edcbdfdaf930d8556d3938fa5f5a881a24e32e95 Mon Sep 17 00:00:00 2001 From: Chris de Graaf Date: Sat, 25 Apr 2020 20:59:34 -0500 Subject: [PATCH] Add create_repository_dispatch (#1449) --- github/Repository.py | 21 +++++++++++++++++++ ...epository.testCreateRepositoryDispatch.txt | 20 ++++++++++++++++++ tests/Repository.py | 6 ++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/ReplayData/Repository.testCreateRepositoryDispatch.txt diff --git a/github/Repository.py b/github/Repository.py index 11fe3d32..0c740e07 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -1397,6 +1397,27 @@ class Repository(github.GithubObject.CompletableGithubObject): 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", self.url + "/dispatches", input=post_parameters + ) + return status == 204 + def create_source_import( self, vcs, diff --git a/tests/ReplayData/Repository.testCreateRepositoryDispatch.txt b/tests/ReplayData/Repository.testCreateRepositoryDispatch.txt new file mode 100644 index 00000000..066d3427 --- /dev/null +++ b/tests/ReplayData/Repository.testCreateRepositoryDispatch.txt @@ -0,0 +1,20 @@ +https +POST +api.github.com +None +/repos/jacquev6/PyGithub/dispatches +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"event_type": "type", "client_payload": {"foo": "bar"}} +204 +[('Server', 'GitHub.com'), ('Date', 'Fri, 17 Apr 2020 00:12:32 GMT'), ('Status', '204 No Content'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4985'), ('X-RateLimit-Reset', '1587085387'), ('X-OAuth-Scopes', 'read:org, repo, user'), ('X-Accepted-OAuth-Scopes', ''), ('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, 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', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Vary', 'Accept-Encoding, Accept, X-Requested-With'), ('X-GitHub-Request-Id', 'C28E:5F24:21A272:43ED41:5E98F470')] + + +https +POST +api.github.com +None +/repos/jacquev6/PyGithub/dispatches +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"event_type": "type"} +204 +[('Date', 'Fri, 17 Apr 2020 00:12:33 GMT'), ('Server', 'GitHub.com'), ('Status', '204 No Content'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4984'), ('X-RateLimit-Reset', '1587085388'), ('X-OAuth-Scopes', 'read:org, repo, user'), ('X-Accepted-OAuth-Scopes', ''), ('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, 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', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Vary', 'Accept-Encoding, Accept, X-Requested-With'), ('X-GitHub-Request-Id', 'C290:52DA:50234:B404B:5E98F470')] diff --git a/tests/Repository.py b/tests/Repository.py index c2d3f0c3..87b3bcee 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -427,6 +427,12 @@ class Repository(Framework.TestCase): source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test" ) + def testCreateRepositoryDispatch(self): + with_payload = self.repo.create_repository_dispatch("type", {"foo": "bar"}) + self.assertTrue(with_payload) + without_payload = self.repo.create_repository_dispatch("type") + self.assertTrue(without_payload) + def testCollaborators(self): lyloa = self.g.get_user("Lyloa") self.assertFalse(self.repo.has_in_collaborators(lyloa))