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 203744bbb..7568af0e9 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 @@ -76,7 +76,22 @@ protected void onEvent(final GHSubscriberEvent event) { URL repoUrl = push.getRepository().getUrl(); final String pusherName = push.getPusher().getName(); LOGGER.info("Received PushEvent for {} from {}", repoUrl, event.getOrigin()); - final GitHubRepositoryName changedRepository = GitHubRepositoryName.create(repoUrl.toExternalForm()); + 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; if (changedRepository != null) { // run in high privilege to see all the projects anonymous users don't see.