Add create_repository_dispatch (#1449)

This commit is contained in:
Chris de Graaf
2020-04-26 09:59:34 +08:00
committed by GitHub
parent 3ab97d6145
commit edcbdfdaf9
3 changed files with 47 additions and 0 deletions
+21
View File
@@ -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 <https://developer.github.com/v3/repos/#create-a-repository-dispatch-event>
: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,
@@ -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')]
+6
View File
@@ -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))