Skip to content

Commit edcbdfd

Browse files
Add create_repository_dispatch (#1449)
1 parent 3ab97d6 commit edcbdfd

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

github/Repository.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,27 @@ def __create_pull(self, **kwds):
13971397
self._requester, headers, data, completed=True
13981398
)
13991399

1400+
def create_repository_dispatch(
1401+
self, event_type, client_payload=github.GithubObject.NotSet
1402+
):
1403+
"""
1404+
:calls: POST /repos/:owner/:repo/dispatches <https://developer.github.com/v3/repos/#create-a-repository-dispatch-event>
1405+
:param event_type: string
1406+
:param client_payload: dict
1407+
:rtype: bool
1408+
"""
1409+
assert isinstance(event_type, str), event_type
1410+
assert client_payload is github.GithubObject.NotSet or isinstance(
1411+
client_payload, dict
1412+
), client_payload
1413+
post_parameters = {"event_type": event_type}
1414+
if client_payload is not github.GithubObject.NotSet:
1415+
post_parameters["client_payload"] = client_payload
1416+
status, headers, data = self._requester.requestJson(
1417+
"POST", self.url + "/dispatches", input=post_parameters
1418+
)
1419+
return status == 204
1420+
14001421
def create_source_import(
14011422
self,
14021423
vcs,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
https
2+
POST
3+
api.github.com
4+
None
5+
/repos/jacquev6/PyGithub/dispatches
6+
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'}
7+
{"event_type": "type", "client_payload": {"foo": "bar"}}
8+
204
9+
[('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')]
10+
11+
12+
https
13+
POST
14+
api.github.com
15+
None
16+
/repos/jacquev6/PyGithub/dispatches
17+
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'}
18+
{"event_type": "type"}
19+
204
20+
[('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')]

tests/Repository.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ def testCreateSourceImport(self):
427427
source_import.vcs_url, "https://bitbucket.org/hfuss/source-import-test"
428428
)
429429

430+
def testCreateRepositoryDispatch(self):
431+
with_payload = self.repo.create_repository_dispatch("type", {"foo": "bar"})
432+
self.assertTrue(with_payload)
433+
without_payload = self.repo.create_repository_dispatch("type")
434+
self.assertTrue(without_payload)
435+
430436
def testCollaborators(self):
431437
lyloa = self.g.get_user("Lyloa")
432438
self.assertFalse(self.repo.has_in_collaborators(lyloa))

0 commit comments

Comments
 (0)