From 95e3f4004074bfe5709b14fe633634872cec4922 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sat, 26 Apr 2025 14:14:30 -0400 Subject: [PATCH 1/3] [JENKINS-75544] fix(webhook): use `repo.html_url` instead of `repo.url` - Per https://github.blog/changelog/2025-04-07-changes-to-the-repository-object-in-push-webhook/, GitHub now gives an API URL in the push webhook's payload for `repo.url` - update the test payload to account for this - switch the code to instead use `repo.html_url` - previously https://github.com/jenkinsci/github-plugin/commit/c0c83fb7cf7dda5082959a274573b926413df849 added `repo.html_url` as a fallback; I'm not sure why the fallback wasn't working exactly, but it should now _always_ use `repo.html_url` --- .../DefaultPushGHEventSubscriber.java | 21 +++---------------- .../GitHubWebHookFullTest/payloads/push.json | 2 +- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java b/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java index 7568af0e9..b7bf04e5d 100644 --- a/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java +++ b/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java @@ -73,25 +73,10 @@ protected void onEvent(final GHSubscriberEvent event) { LOGGER.warn("Received malformed PushEvent: " + event.getPayload(), e); return; } - URL repoUrl = push.getRepository().getUrl(); + URL htmlUrl = push.getRepository().getHtmlUrl(); final String pusherName = push.getPusher().getName(); - LOGGER.info("Received PushEvent for {} from {}", repoUrl, event.getOrigin()); - GitHubRepositoryName fromEventRepository = GitHubRepositoryName.create(repoUrl.toExternalForm()); - - if (fromEventRepository == null) { - // On push event on github.com url === html_url - // this is not consistent with the API docs and with hosted repositories - // see https://goo.gl/c1qmY7 - // let's retry with 'html_url' - URL htmlUrl = push.getRepository().getHtmlUrl(); - fromEventRepository = GitHubRepositoryName.create(htmlUrl.toExternalForm()); - if (fromEventRepository != null) { - LOGGER.debug("PushEvent handling: 'html_url' field " - + "has been used to retrieve project information (instead of default 'url' field)"); - } - } - - final GitHubRepositoryName changedRepository = fromEventRepository; + LOGGER.info("Received PushEvent for {} from {}", htmlUrl, event.getOrigin()); + final GitHubRepositoryName changedRepository = GitHubRepositoryName.create(htmlUrl.toExternalForm()); if (changedRepository != null) { // run in high privilege to see all the projects anonymous users don't see. diff --git a/src/test/resources/com/cloudbees/jenkins/GitHubWebHookFullTest/payloads/push.json b/src/test/resources/com/cloudbees/jenkins/GitHubWebHookFullTest/payloads/push.json index 0d006823d..203839f23 100644 --- a/src/test/resources/com/cloudbees/jenkins/GitHubWebHookFullTest/payloads/push.json +++ b/src/test/resources/com/cloudbees/jenkins/GitHubWebHookFullTest/payloads/push.json @@ -65,7 +65,7 @@ "html_url": "https://github.com/lanwen/test", "description": "Personal blog", "fork": false, - "url": "https://github.com/lanwen/test", + "url": "https://api.github.com/lanwen/test", "forks_url": "https://api.github.com/repos/lanwen/test/forks", "keys_url": "https://api.github.com/repos/lanwen/test/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/lanwen/test/collaborators{/collaborator}", From d36e029a0dd5bafb41b7e069aa97dc7292c44b17 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sat, 26 Apr 2025 14:23:47 -0400 Subject: [PATCH 2/3] fix remaining `repoUrl` use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - saw this and wanted to change it, but I forgot 😅 --- .../github/webhook/subscriber/DefaultPushGHEventSubscriber.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java b/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java index b7bf04e5d..95180fddb 100644 --- a/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java +++ b/src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java @@ -113,7 +113,7 @@ public void run() { } } else { - LOGGER.warn("Malformed repo url {}", repoUrl); + LOGGER.warn("Malformed repo html url {}", htmlUrl); } } } From aa43848e8cbb54c1f83d81ae92d9f1c0a70310e2 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sat, 26 Apr 2025 14:39:53 -0400 Subject: [PATCH 3/3] [FIXES JENKINS-75544] - add a commit with the JIRA issue # since the PR name doesn't seem to auto link? - (last time I used JIRA, any mention of it the issue number in a GitHub PR would auto link; possibly different settings for this repo/the Jenkins org)