Skip to content

Commit c0c83fb

Browse files
committed
[JENKINS-56830] alternative use of 'html_url' in payload of event
As documented in github API docs (https://developer.github.com/v3/repos/#response) the url field of the event should/could point to the API endpoint. In the github-plugin it is expected to work on the public html url which is handled by the 'html_url' field of the event. This commit thus try as before to build a GitHubRepositoryName from the 'url' field ; if that fails, as a fallback it also tries the 'html_url' field. See also https://github.community/t5/GitHub-API-Development-and/consistency-of-repository-url-between-event-types/td-p/21209 for some explanations.
1 parent 14b056a commit c0c83fb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/org/jenkinsci/plugins/github/webhook/subscriber/DefaultPushGHEventSubscriber.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,22 @@ protected void onEvent(final GHSubscriberEvent event) {
7676
URL repoUrl = push.getRepository().getUrl();
7777
final String pusherName = push.getPusher().getName();
7878
LOGGER.info("Received PushEvent for {} from {}", repoUrl, event.getOrigin());
79-
final GitHubRepositoryName changedRepository = GitHubRepositoryName.create(repoUrl.toExternalForm());
79+
GitHubRepositoryName fromEventRepository = GitHubRepositoryName.create(repoUrl.toExternalForm());
80+
81+
if (fromEventRepository == null) {
82+
// On push event on github.com url === html_url
83+
// this is not consistent with the API docs and with hosted repositories
84+
// see https://goo.gl/c1qmY7
85+
// let's retry with 'html_url'
86+
URL htmlUrl = push.getRepository().getHtmlUrl();
87+
fromEventRepository = GitHubRepositoryName.create(htmlUrl.toExternalForm());
88+
if (fromEventRepository != null) {
89+
LOGGER.debug("PushEvent handling: 'html_url' field "
90+
+ "has been used to retrieve project information (instead of default 'url' field)");
91+
}
92+
}
93+
94+
final GitHubRepositoryName changedRepository = fromEventRepository;
8095

8196
if (changedRepository != null) {
8297
// run in high privilege to see all the projects anonymous users don't see.

0 commit comments

Comments
 (0)