Repository: hub4j/github-api
Pull request #1726 (2023-10-13 16:01:12)

feat: Support `merge_group` events

# Description

> [!IMPORTANT]  
> **DISCLAIMER:** I'm not a Java developer - This PR is based on the changes implemented in **[#1316](https://github.com/hub4j/github-api/pull/1316)**,  which seemed quite simple to do, so I'm proposing these changes for review.

---


This PR adds support for  merge_group events fired by merge queues, please see the official documentation for details:
- **[Github Blog post](https://github.blog/changelog/2022-08-18-merge-group-webhook-event-and-github-actions-workflow-trigger/)**
- **[`merge_group` event definition in workflow docs](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#merge_group)**

I'm submitting this PR since I'm using `jenkinsci/github-plugin`, which is failing to accept these valid events fired by Github. It does an event-check **[here](https://github.com/jenkinsci/github-plugin/blob/309cf75c74ba1f254b9fe09fc43b5d9e08956813/src/main/java/org/jenkinsci/plugins/github/webhook/RequirePostWithGHHookPayload.java#L127-L130)** based on  `org.kohsuke.github.GHEvent` _(defined by this project)_  and, since `merge_group` is not a supported  event, it fails with "Hook should contain event type".

Here's an example of what I see on Github Settings > Webhook on my end when Jenkins receives that payload:


![image](https://github.com/hub4j/github-api/assets/2165248/1ac55677-8234-4f99-9e4d-667fc9183fa8)

# Before submitting a PR:

- [ ] Changes must not break binary backwards compatibility. If you are unclear on how to make the change you think is needed while maintaining backward compatibility, [CONTRIBUTING.md](CONTRIBUTING.md) for details.
- [ ] Add JavaDocs and other comments explaining the behavior. 
- [ ] When adding or updating methods that fetch entities, add `@link` JavaDoc entries to the relevant documentation on https://docs.github.com/en/rest . 
- [ ] Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
- [ ] Run `mvn -D enable-ci clean install site` locally. If this command doesn't succeed, your change will not pass CI.
- [ ] Push your changes to a branch other than `main`. You will create your PR from that branch.

# When creating a PR: 

- [ ] Fill in the "Description" above with clear summary of the changes. This includes:
  - [ ] If this PR fixes one or more issues, include "Fixes #<issue number>" lines for each issue. 
  - [ ] Provide links to relevant documentation on https://docs.github.com/en/rest where possible. If not including links, explain why not.
- [ ] All lines of new code should be covered by tests as reported by code coverage. Any lines that are not covered must have PR comments explaining why they cannot be covered. For example, "Reaching this particular exception is hard and is not a particular common scenario."
- [ ] Enable "Allow edits from maintainers".



Patch:
diff --git a/src/main/java/org/kohsuke/github/GHEvent.java b/src/main/java/org/kohsuke/github/GHEvent.java
index d93411bed..1170743ac 100644
--- a/src/main/java/org/kohsuke/github/GHEvent.java
+++ b/src/main/java/org/kohsuke/github/GHEvent.java
@@ -102,6 +102,9 @@ public enum GHEvent {
     /** The merge queue entry. */
     MERGE_QUEUE_ENTRY,
 
+    /** The merge group entry. */
+    MERGE_GROUP,
+
     /** The meta. */
     META,
 


Test patch:
diff --git a/src/test/java/org/kohsuke/github/EnumTest.java b/src/test/java/org/kohsuke/github/EnumTest.java
index 59cf1f4d4..939c6360e 100644
--- a/src/test/java/org/kohsuke/github/EnumTest.java
+++ b/src/test/java/org/kohsuke/github/EnumTest.java
@@ -32,7 +32,7 @@ public class EnumTest extends AbstractGitHubWireMockTest {
 
         assertThat(GHDirection.values().length, equalTo(2));
 
-        assertThat(GHEvent.values().length, equalTo(64));
+        assertThat(GHEvent.values().length, equalTo(65));
         assertThat(GHEvent.ALL.symbol(), equalTo("*"));
         assertThat(GHEvent.PULL_REQUEST.symbol(), equalTo(GHEvent.PULL_REQUEST.toString().toLowerCase()));