Repository: PyGithub/PyGithub

Issue:
Support for repository dispatch event
Preview feature useful for triggering github actions.

POST /repos/:owner/:repo/dispatches
https://developer.github.com/v3/repos/#create-a-repository-dispatch-event



Discussion:

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -1373,6 +1373,27 @@ def __create_pull(self, **kwds):
             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,


Test patch:
diff --git a/tests/ReplayData/Repository.testCreateRepositoryDispatch.txt b/tests/ReplayData/Repository.testCreateRepositoryDispatch.txt
new file mode 100644
--- /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
--- a/tests/Repository.py
+++ b/tests/Repository.py
@@ -418,6 +418,12 @@ def testCreateSourceImport(self):
             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))