Repository: hub4j/github-api
Pull request #1248 (2021-09-30 12:39:53)

Add repository dispatch event
# Description

The changes here will expose the "create dispatch event" on the repository object, as describe on the github api:

https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event

The main usage of the api is to trigger an action or webhook from outside github, github has no apis to retrieve dispatches from a repo, and the ack we get from the api in case of success is a `204` status response.

Covers the issue https://github.com/hub4j/github-api/issues/1246


Patch:
diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java
index 117cbf8d5..78fa5bb5d 100644
--- a/src/main/java/org/kohsuke/github/GHRepository.java
+++ b/src/main/java/org/kohsuke/github/GHRepository.java
@@ -57,6 +57,7 @@ import java.util.TreeMap;
 import java.util.WeakHashMap;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import static java.util.Arrays.asList;
 import static java.util.Objects.requireNonNull;
@@ -3211,6 +3212,26 @@ public class GHRepository extends GHObject {
         return downloadArchive("tar", ref, streamFunction);
     }
 
+    /**
+     * Create a repository dispatch event, which can be used to start a workflow/action from outside github, as
+     * described on https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event
+     *
+     * @param eventType
+     *            the eventType
+     * @param clientPayload
+     *            a custom payload , can be nullable
+     * @throws IOException
+     *             the io exception
+     */
+    public <T> void dispatch(String eventType, @Nullable T clientPayload) throws IOException {
+        root().createRequest()
+                .method("POST")
+                .withUrlPath(getApiTailUrl("dispatches"))
+                .with("event_type", eventType)
+                .with("client_payload", clientPayload)
+                .send();
+    }
+
     private <T> T downloadArchive(@Nonnull String type,
             @CheckForNull String ref,
             @Nonnull InputStreamFunction<T> streamFunction) throws IOException {


Test patch:
diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java
index c631138a9..784692fde 100644
--- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java
+++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java
@@ -13,6 +13,7 @@ import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -987,4 +988,19 @@ public class GHRepositoryTest extends AbstractGitHubWireMockTest {
         assertThat(mockGitHub.getRequestCount(), equalTo(startingCount + 4));
     }
 
+    @Test
+    public void createDispatchEventWithoutClientPayload() throws Exception {
+        GHRepository repository = getTempRepository();
+        repository.dispatch("test", null);
+    }
+
+    @Test
+    public void createDispatchEventWithClientPayload() throws Exception {
+        GHRepository repository = getTempRepository();
+        Map<String, Object> clientPayload = new HashMap<>();
+        clientPayload.put("name", "joe.doe");
+        clientPayload.put("list", new ArrayList<>());
+        repository.dispatch("test", clientPayload);
+    }
+
 }
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/__files/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload-2.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/__files/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload-2.json
new file mode 100644
index 000000000..71fe34fc8
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/__files/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload-2.json
@@ -0,0 +1,130 @@
+{
+  "id": 412057727,
+  "node_id": "R_kgDOGI-Afw",
+  "name": "temp-createDispatchEventWithClientPayload",
+  "full_name": "hub4j-test-org/temp-createDispatchEventWithClientPayload",
+  "private": false,
+  "owner": {
+    "login": "hub4j-test-org",
+    "id": 7544739,
+    "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
+    "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
+    "gravatar_id": "",
+    "url": "https://api.github.com/users/hub4j-test-org",
+    "html_url": "https://github.com/hub4j-test-org",
+    "followers_url": "https://api.github.com/users/hub4j-test-org/followers",
+    "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
+    "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
+    "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
+    "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
+    "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
+    "repos_url": "https://api.github.com/users/hub4j-test-org/repos",
+    "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
+    "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
+    "type": "Organization",
+    "site_admin": false
+  },
+  "html_url": "https://github.com/hub4j-test-org/temp-createDispatchEventWithClientPayload",
+  "description": "A test repository for testing the github-api project: temp-createDispatchEventWithClientPayload",
+  "fork": false,
+  "url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload",
+  "forks_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/forks",
+  "keys_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/keys{/key_id}",
+  "collaborators_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/collaborators{/collaborator}",
+  "teams_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/teams",
+  "hooks_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/hooks",
+  "issue_events_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/issues/events{/number}",
+  "events_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/events",
+  "assignees_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/assignees{/user}",
+  "branches_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/branches{/branch}",
+  "tags_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/tags",
+  "blobs_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/git/blobs{/sha}",
+  "git_tags_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/git/tags{/sha}",
+  "git_refs_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/git/refs{/sha}",
+  "trees_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/git/trees{/sha}",
+  "statuses_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/statuses/{sha}",
+  "languages_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/languages",
+  "stargazers_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/stargazers",
+  "contributors_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/contributors",
+  "subscribers_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/subscribers",
+  "subscription_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/subscription",
+  "commits_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/commits{/sha}",
+  "git_commits_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/git/commits{/sha}",
+  "comments_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/comments{/number}",
+  "issue_comment_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/issues/comments{/number}",
+  "contents_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/contents/{+path}",
+  "compare_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/compare/{base}...{head}",
+  "merges_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/merges",
+  "archive_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/{archive_format}{/ref}",
+  "downloads_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/downloads",
+  "issues_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/issues{/number}",
+  "pulls_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/pulls{/number}",
+  "milestones_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/milestones{/number}",
+  "notifications_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/notifications{?since,all,participating}",
+  "labels_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/labels{/name}",
+  "releases_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/releases{/id}",
+  "deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/deployments",
+  "created_at": "2021-09-30T12:34:44Z",
+  "updated_at": "2021-09-30T12:34:44Z",
+  "pushed_at": "2021-09-30T12:34:45Z",
+  "git_url": "git://github.com/hub4j-test-org/temp-createDispatchEventWithClientPayload.git",
+  "ssh_url": "git@github.com:hub4j-test-org/temp-createDispatchEventWithClientPayload.git",
+  "clone_url": "https://github.com/hub4j-test-org/temp-createDispatchEventWithClientPayload.git",
+  "svn_url": "https://github.com/hub4j-test-org/temp-createDispatchEventWithClientPayload",
+  "homepage": "http://github-api.kohsuke.org/",
+  "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,
+  "allow_forking": true,
+  "forks": 0,
+  "open_issues": 0,
+  "watchers": 0,
+  "default_branch": "main",
+  "permissions": {
+    "admin": true,
+    "maintain": true,
+    "push": true,
+    "triage": true,
+    "pull": true
+  },
+  "temp_clone_token": "",
+  "allow_squash_merge": true,
+  "allow_merge_commit": true,
+  "allow_rebase_merge": true,
+  "allow_auto_merge": false,
+  "delete_branch_on_merge": false,
+  "organization": {
+    "login": "hub4j-test-org",
+    "id": 7544739,
+    "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
+    "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
+    "gravatar_id": "",
+    "url": "https://api.github.com/users/hub4j-test-org",
+    "html_url": "https://github.com/hub4j-test-org",
+    "followers_url": "https://api.github.com/users/hub4j-test-org/followers",
+    "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
+    "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
+    "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
+    "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
+    "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
+    "repos_url": "https://api.github.com/users/hub4j-test-org/repos",
+    "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
+    "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
+    "type": "Organization",
+    "site_admin": false
+  },
+  "network_count": 0,
+  "subscribers_count": 15
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/__files/user-1.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/__files/user-1.json
new file mode 100644
index 000000000..fbe227661
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/__files/user-1.json
@@ -0,0 +1,46 @@
+{
+  "login": "mxandeco",
+  "id": 42962662,
+  "node_id": "MDQ6VXNlcjQyOTYyNjYy",
+  "avatar_url": "https://avatars.githubusercontent.com/u/42962662?v=4",
+  "gravatar_id": "",
+  "url": "https://api.github.com/users/mxandeco",
+  "html_url": "https://github.com/mxandeco",
+  "followers_url": "https://api.github.com/users/mxandeco/followers",
+  "following_url": "https://api.github.com/users/mxandeco/following{/other_user}",
+  "gists_url": "https://api.github.com/users/mxandeco/gists{/gist_id}",
+  "starred_url": "https://api.github.com/users/mxandeco/starred{/owner}{/repo}",
+  "subscriptions_url": "https://api.github.com/users/mxandeco/subscriptions",
+  "organizations_url": "https://api.github.com/users/mxandeco/orgs",
+  "repos_url": "https://api.github.com/users/mxandeco/repos",
+  "events_url": "https://api.github.com/users/mxandeco/events{/privacy}",
+  "received_events_url": "https://api.github.com/users/mxandeco/received_events",
+  "type": "User",
+  "site_admin": false,
+  "name": "Max Xandeco",
+  "company": null,
+  "blog": "",
+  "location": null,
+  "email": null,
+  "hireable": null,
+  "bio": null,
+  "twitter_username": null,
+  "public_repos": 18,
+  "public_gists": 1,
+  "followers": 0,
+  "following": 0,
+  "created_at": "2018-09-04T09:13:09Z",
+  "updated_at": "2021-09-06T20:36:46Z",
+  "private_gists": 0,
+  "total_private_repos": 8,
+  "owned_private_repos": 4,
+  "disk_usage": 90,
+  "collaborators": 1,
+  "two_factor_authentication": true,
+  "plan": {
+    "name": "free",
+    "space": 976562499,
+    "collaborators": 0,
+    "private_repos": 10000
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload-2.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload-2.json
new file mode 100644
index 000000000..b4e557fd8
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload-2.json
@@ -0,0 +1,47 @@
+{
+  "id": "2539d5de-f96e-431e-b31b-a537e52e0ef5",
+  "name": "repos_hub4j-test-org_temp-createdispatcheventwithclientpayload",
+  "request": {
+    "url": "/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload",
+    "method": "GET",
+    "headers": {
+      "Accept": {
+        "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
+      }
+    }
+  },
+  "response": {
+    "status": 200,
+    "bodyFileName": "repos_hub4j-test-org_temp-createdispatcheventwithclientpayload-2.json",
+    "headers": {
+      "Server": "GitHub.com",
+      "Date": "Thu, 30 Sep 2021 12:34:49 GMT",
+      "Content-Type": "application/json; charset=utf-8",
+      "Cache-Control": "private, max-age=60, s-maxage=60",
+      "Vary": [
+        "Accept, Authorization, Cookie, X-GitHub-OTP",
+        "Accept-Encoding, Accept, X-Requested-With"
+      ],
+      "ETag": "W/\"5ab7e1e833c6acac05ab9315823a4f6b6a662de9d5f2539189c24ce631404077\"",
+      "Last-Modified": "Thu, 30 Sep 2021 12:34:44 GMT",
+      "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": "repo",
+      "X-GitHub-Media-Type": "unknown, github.v3",
+      "X-RateLimit-Limit": "5000",
+      "X-RateLimit-Remaining": "4940",
+      "X-RateLimit-Reset": "1633006817",
+      "X-RateLimit-Used": "60",
+      "X-RateLimit-Resource": "core",
+      "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": "DEB6:4B95:4C9D23:4E7593:6155AEE8"
+    }
+  },
+  "uuid": "2539d5de-f96e-431e-b31b-a537e52e0ef5",
+  "persistent": true,
+  "insertionIndex": 2
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload_dispatches-3.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload_dispatches-3.json
new file mode 100644
index 000000000..46ced5319
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithclientpayload_dispatches-3.json
@@ -0,0 +1,46 @@
+{
+  "id": "bd959614-1104-415e-b9a1-8ac9533d82f7",
+  "name": "repos_hub4j-test-org_temp-createdispatcheventwithclientpayload_dispatches",
+  "request": {
+    "url": "/repos/hub4j-test-org/temp-createDispatchEventWithClientPayload/dispatches",
+    "method": "POST",
+    "headers": {
+      "Accept": {
+        "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
+      }
+    },
+    "bodyPatterns": [
+      {
+        "equalToJson": "{\"event_type\":\"test\",\"client_payload\":{\"name\":\"joe.doe\",\"list\":[]}}",
+        "ignoreArrayOrder": true,
+        "ignoreExtraElements": false
+      }
+    ]
+  },
+  "response": {
+    "status": 204,
+    "headers": {
+      "Server": "GitHub.com",
+      "Date": "Thu, 30 Sep 2021 12:34:49 GMT",
+      "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": "unknown, github.v3",
+      "X-RateLimit-Limit": "5000",
+      "X-RateLimit-Remaining": "4939",
+      "X-RateLimit-Reset": "1633006817",
+      "X-RateLimit-Used": "61",
+      "X-RateLimit-Resource": "core",
+      "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'",
+      "Vary": "Accept-Encoding, Accept, X-Requested-With",
+      "X-GitHub-Request-Id": "DEB7:0B4B:3073ED:320304:6155AEE9"
+    }
+  },
+  "uuid": "bd959614-1104-415e-b9a1-8ac9533d82f7",
+  "persistent": true,
+  "insertionIndex": 3
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/user-1.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/user-1.json
new file mode 100644
index 000000000..d0eaa41d0
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithClientPayload/mappings/user-1.json
@@ -0,0 +1,47 @@
+{
+  "id": "43c6892b-f0dc-45a7-97b9-f81a8e3f244e",
+  "name": "user",
+  "request": {
+    "url": "/user",
+    "method": "GET",
+    "headers": {
+      "Accept": {
+        "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
+      }
+    }
+  },
+  "response": {
+    "status": 200,
+    "bodyFileName": "user-1.json",
+    "headers": {
+      "Server": "GitHub.com",
+      "Date": "Thu, 30 Sep 2021 12:34:43 GMT",
+      "Content-Type": "application/json; charset=utf-8",
+      "Cache-Control": "private, max-age=60, s-maxage=60",
+      "Vary": [
+        "Accept, Authorization, Cookie, X-GitHub-OTP",
+        "Accept-Encoding, Accept, X-Requested-With"
+      ],
+      "ETag": "W/\"b8f235ad3cd7cc5e96a09241a22fa6048c7877f43ada37c29eb075107f7f3b1a\"",
+      "Last-Modified": "Mon, 06 Sep 2021 20:36:46 GMT",
+      "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": "unknown, github.v3",
+      "X-RateLimit-Limit": "5000",
+      "X-RateLimit-Remaining": "4945",
+      "X-RateLimit-Reset": "1633006817",
+      "X-RateLimit-Used": "55",
+      "X-RateLimit-Resource": "core",
+      "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": "DEB3:FDF5:134720:14986B:6155AEE2"
+    }
+  },
+  "uuid": "43c6892b-f0dc-45a7-97b9-f81a8e3f244e",
+  "persistent": true,
+  "insertionIndex": 1
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/__files/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload-2.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/__files/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload-2.json
new file mode 100644
index 000000000..5afb0cc7c
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/__files/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload-2.json
@@ -0,0 +1,130 @@
+{
+  "id": 412057090,
+  "node_id": "R_kgDOGI9-Ag",
+  "name": "temp-createDispatchEventWithoutClientPayload",
+  "full_name": "hub4j-test-org/temp-createDispatchEventWithoutClientPayload",
+  "private": false,
+  "owner": {
+    "login": "hub4j-test-org",
+    "id": 7544739,
+    "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
+    "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
+    "gravatar_id": "",
+    "url": "https://api.github.com/users/hub4j-test-org",
+    "html_url": "https://github.com/hub4j-test-org",
+    "followers_url": "https://api.github.com/users/hub4j-test-org/followers",
+    "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
+    "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
+    "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
+    "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
+    "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
+    "repos_url": "https://api.github.com/users/hub4j-test-org/repos",
+    "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
+    "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
+    "type": "Organization",
+    "site_admin": false
+  },
+  "html_url": "https://github.com/hub4j-test-org/temp-createDispatchEventWithoutClientPayload",
+  "description": "A test repository for testing the github-api project: temp-createDispatchEventWithoutClientPayload",
+  "fork": false,
+  "url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload",
+  "forks_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/forks",
+  "keys_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/keys{/key_id}",
+  "collaborators_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/collaborators{/collaborator}",
+  "teams_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/teams",
+  "hooks_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/hooks",
+  "issue_events_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/issues/events{/number}",
+  "events_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/events",
+  "assignees_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/assignees{/user}",
+  "branches_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/branches{/branch}",
+  "tags_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/tags",
+  "blobs_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/git/blobs{/sha}",
+  "git_tags_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/git/tags{/sha}",
+  "git_refs_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/git/refs{/sha}",
+  "trees_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/git/trees{/sha}",
+  "statuses_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/statuses/{sha}",
+  "languages_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/languages",
+  "stargazers_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/stargazers",
+  "contributors_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/contributors",
+  "subscribers_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/subscribers",
+  "subscription_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/subscription",
+  "commits_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/commits{/sha}",
+  "git_commits_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/git/commits{/sha}",
+  "comments_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/comments{/number}",
+  "issue_comment_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/issues/comments{/number}",
+  "contents_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/contents/{+path}",
+  "compare_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/compare/{base}...{head}",
+  "merges_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/merges",
+  "archive_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/{archive_format}{/ref}",
+  "downloads_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/downloads",
+  "issues_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/issues{/number}",
+  "pulls_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/pulls{/number}",
+  "milestones_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/milestones{/number}",
+  "notifications_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/notifications{?since,all,participating}",
+  "labels_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/labels{/name}",
+  "releases_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/releases{/id}",
+  "deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/deployments",
+  "created_at": "2021-09-30T12:32:43Z",
+  "updated_at": "2021-09-30T12:32:46Z",
+  "pushed_at": "2021-09-30T12:32:44Z",
+  "git_url": "git://github.com/hub4j-test-org/temp-createDispatchEventWithoutClientPayload.git",
+  "ssh_url": "git@github.com:hub4j-test-org/temp-createDispatchEventWithoutClientPayload.git",
+  "clone_url": "https://github.com/hub4j-test-org/temp-createDispatchEventWithoutClientPayload.git",
+  "svn_url": "https://github.com/hub4j-test-org/temp-createDispatchEventWithoutClientPayload",
+  "homepage": "http://github-api.kohsuke.org/",
+  "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,
+  "allow_forking": true,
+  "forks": 0,
+  "open_issues": 0,
+  "watchers": 0,
+  "default_branch": "main",
+  "permissions": {
+    "admin": true,
+    "maintain": true,
+    "push": true,
+    "triage": true,
+    "pull": true
+  },
+  "temp_clone_token": "",
+  "allow_squash_merge": true,
+  "allow_merge_commit": true,
+  "allow_rebase_merge": true,
+  "allow_auto_merge": false,
+  "delete_branch_on_merge": false,
+  "organization": {
+    "login": "hub4j-test-org",
+    "id": 7544739,
+    "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
+    "avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
+    "gravatar_id": "",
+    "url": "https://api.github.com/users/hub4j-test-org",
+    "html_url": "https://github.com/hub4j-test-org",
+    "followers_url": "https://api.github.com/users/hub4j-test-org/followers",
+    "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
+    "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
+    "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
+    "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
+    "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
+    "repos_url": "https://api.github.com/users/hub4j-test-org/repos",
+    "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
+    "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
+    "type": "Organization",
+    "site_admin": false
+  },
+  "network_count": 0,
+  "subscribers_count": 15
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/__files/user-1.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/__files/user-1.json
new file mode 100644
index 000000000..fbe227661
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/__files/user-1.json
@@ -0,0 +1,46 @@
+{
+  "login": "mxandeco",
+  "id": 42962662,
+  "node_id": "MDQ6VXNlcjQyOTYyNjYy",
+  "avatar_url": "https://avatars.githubusercontent.com/u/42962662?v=4",
+  "gravatar_id": "",
+  "url": "https://api.github.com/users/mxandeco",
+  "html_url": "https://github.com/mxandeco",
+  "followers_url": "https://api.github.com/users/mxandeco/followers",
+  "following_url": "https://api.github.com/users/mxandeco/following{/other_user}",
+  "gists_url": "https://api.github.com/users/mxandeco/gists{/gist_id}",
+  "starred_url": "https://api.github.com/users/mxandeco/starred{/owner}{/repo}",
+  "subscriptions_url": "https://api.github.com/users/mxandeco/subscriptions",
+  "organizations_url": "https://api.github.com/users/mxandeco/orgs",
+  "repos_url": "https://api.github.com/users/mxandeco/repos",
+  "events_url": "https://api.github.com/users/mxandeco/events{/privacy}",
+  "received_events_url": "https://api.github.com/users/mxandeco/received_events",
+  "type": "User",
+  "site_admin": false,
+  "name": "Max Xandeco",
+  "company": null,
+  "blog": "",
+  "location": null,
+  "email": null,
+  "hireable": null,
+  "bio": null,
+  "twitter_username": null,
+  "public_repos": 18,
+  "public_gists": 1,
+  "followers": 0,
+  "following": 0,
+  "created_at": "2018-09-04T09:13:09Z",
+  "updated_at": "2021-09-06T20:36:46Z",
+  "private_gists": 0,
+  "total_private_repos": 8,
+  "owned_private_repos": 4,
+  "disk_usage": 90,
+  "collaborators": 1,
+  "two_factor_authentication": true,
+  "plan": {
+    "name": "free",
+    "space": 976562499,
+    "collaborators": 0,
+    "private_repos": 10000
+  }
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload-2.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload-2.json
new file mode 100644
index 000000000..45a81545a
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload-2.json
@@ -0,0 +1,47 @@
+{
+  "id": "13b8f471-59d2-4782-be63-5632278bd85d",
+  "name": "repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload",
+  "request": {
+    "url": "/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload",
+    "method": "GET",
+    "headers": {
+      "Accept": {
+        "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
+      }
+    }
+  },
+  "response": {
+    "status": 200,
+    "bodyFileName": "repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload-2.json",
+    "headers": {
+      "Server": "GitHub.com",
+      "Date": "Thu, 30 Sep 2021 12:32:47 GMT",
+      "Content-Type": "application/json; charset=utf-8",
+      "Cache-Control": "private, max-age=60, s-maxage=60",
+      "Vary": [
+        "Accept, Authorization, Cookie, X-GitHub-OTP",
+        "Accept-Encoding, Accept, X-Requested-With"
+      ],
+      "ETag": "W/\"a741209a82e66560508e72d5fc0153a44e22a6e8d21eef9a6c51da00f825256c\"",
+      "Last-Modified": "Thu, 30 Sep 2021 12:32:46 GMT",
+      "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": "repo",
+      "X-GitHub-Media-Type": "unknown, github.v3",
+      "X-RateLimit-Limit": "5000",
+      "X-RateLimit-Remaining": "4949",
+      "X-RateLimit-Reset": "1633006817",
+      "X-RateLimit-Used": "51",
+      "X-RateLimit-Resource": "core",
+      "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": "DE9E:8483:4E8801:505B9D:6155AE6F"
+    }
+  },
+  "uuid": "13b8f471-59d2-4782-be63-5632278bd85d",
+  "persistent": true,
+  "insertionIndex": 2
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload_dispatches-3.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload_dispatches-3.json
new file mode 100644
index 000000000..190cea31a
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload_dispatches-3.json
@@ -0,0 +1,46 @@
+{
+  "id": "0c00012f-4497-4dbc-b724-46997464a81c",
+  "name": "repos_hub4j-test-org_temp-createdispatcheventwithoutclientpayload_dispatches",
+  "request": {
+    "url": "/repos/hub4j-test-org/temp-createDispatchEventWithoutClientPayload/dispatches",
+    "method": "POST",
+    "headers": {
+      "Accept": {
+        "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
+      }
+    },
+    "bodyPatterns": [
+      {
+        "equalToJson": "{\"event_type\":\"test\"}",
+        "ignoreArrayOrder": true,
+        "ignoreExtraElements": false
+      }
+    ]
+  },
+  "response": {
+    "status": 204,
+    "headers": {
+      "Server": "GitHub.com",
+      "Date": "Thu, 30 Sep 2021 12:32:48 GMT",
+      "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": "unknown, github.v3",
+      "X-RateLimit-Limit": "5000",
+      "X-RateLimit-Remaining": "4948",
+      "X-RateLimit-Reset": "1633006817",
+      "X-RateLimit-Used": "52",
+      "X-RateLimit-Resource": "core",
+      "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'",
+      "Vary": "Accept-Encoding, Accept, X-Requested-With",
+      "X-GitHub-Request-Id": "DE9F:0B4C:50D143:52A9B6:6155AE70"
+    }
+  },
+  "uuid": "0c00012f-4497-4dbc-b724-46997464a81c",
+  "persistent": true,
+  "insertionIndex": 3
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/user-1.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/user-1.json
new file mode 100644
index 000000000..a3945c4c2
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/createDispatchEventWithoutClientPayload/mappings/user-1.json
@@ -0,0 +1,47 @@
+{
+  "id": "3598700f-5fac-493c-96b5-2fe30a73a912",
+  "name": "user",
+  "request": {
+    "url": "/user",
+    "method": "GET",
+    "headers": {
+      "Accept": {
+        "equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
+      }
+    }
+  },
+  "response": {
+    "status": 200,
+    "bodyFileName": "user-1.json",
+    "headers": {
+      "Server": "GitHub.com",
+      "Date": "Thu, 30 Sep 2021 12:32:42 GMT",
+      "Content-Type": "application/json; charset=utf-8",
+      "Cache-Control": "private, max-age=60, s-maxage=60",
+      "Vary": [
+        "Accept, Authorization, Cookie, X-GitHub-OTP",
+        "Accept-Encoding, Accept, X-Requested-With"
+      ],
+      "ETag": "W/\"b8f235ad3cd7cc5e96a09241a22fa6048c7877f43ada37c29eb075107f7f3b1a\"",
+      "Last-Modified": "Mon, 06 Sep 2021 20:36:46 GMT",
+      "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": "unknown, github.v3",
+      "X-RateLimit-Limit": "5000",
+      "X-RateLimit-Remaining": "4954",
+      "X-RateLimit-Reset": "1633006817",
+      "X-RateLimit-Used": "46",
+      "X-RateLimit-Resource": "core",
+      "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": "DE9A:D43A:275403:28D284:6155AE69"
+    }
+  },
+  "uuid": "3598700f-5fac-493c-96b5-2fe30a73a912",
+  "persistent": true,
+  "insertionIndex": 1
+}
\ No newline at end of file