GHPullRequestSubscriber extends AbstractGHPullRequestSubsriber { @Override protected void onEvent(GHSubscriberEvent event) { try { GitHub gh = GitHub.offline(); PullRequestInfo info = extractPullRequestInfo(event.getGHEvent(), event.getPayload(), gh); for (Job job : getPRTriggerJobs(info.getRepo())) { GitHubPRTrigger trigger = ghPRTriggerFromJob(job); GitHubPRTriggerMode triggerMode = trigger.getTriggerMode(); switch (triggerMode) { case HEAVY_HOOKS_CRON: case HEAVY_HOOKS: { LOGGER.debug("Queued check for {} (PR #{}) after heavy hook", job.getName(), info.getNum()); trigger.queueRun(job, info.getNum()); break; } case LIGHT_HOOKS: { LOGGER.warn("Unsupported LIGHT_HOOKS trigger mode"); break; } default: break; } } } catch (Exception e) { LOGGER.error("Can't process {} hook", event, e); } }    }
@Test public void shouldTriggerJobOnPullRequestOpen() throws Exception { when(trigger.getRepoFullName(any(AbstractProject.class))).thenReturn(create(REPO_URL_FROM_PAYLOAD)); when(trigger.getTriggerMode()).thenReturn(GitHubPRTriggerMode.HEAVY_HOOKS); FreeStyleProject job = jenkins.createFreeStyleProject(); job.addProperty(new GithubProjectProperty(REPO_URL_FROM_PAYLOAD)); job.addTrigger(trigger); new GHPullRequestSubscriber().onEvent(new GHSubscriberEvent( "", GHEvent.PULL_REQUEST, classpath("payload/pull_request.json")) ); verify(trigger).queueRun(eq(job), eq(1)); }
@Test public void shouldTriggerFreestyleProjectOnIssueComment() throws Exception { when(trigger.getRepoFullName(any(Job.class))).thenReturn(create(REPO_URL_FROM_PAYLOAD)); when(trigger.getTriggerMode()).thenReturn(GitHubPRTriggerMode.HEAVY_HOOKS); FreeStyleProject job = jenkins.createFreeStyleProject(); job.addProperty(new GithubProjectProperty(REPO_URL_FROM_PAYLOAD)); job.addTrigger(trigger); new GHPullRequestSubscriber().onEvent(new GHSubscriberEvent( "", GHEvent.ISSUE_COMMENT, classpath("payload/issue_comment.json")) ); verify(trigger).queueRun(eq(job), eq(1)); }
@Test public void shouldTriggerWorkflowJobOnIssueComment() throws Exception { when(trigger.getRepoFullName(any(Job.class))).thenReturn(create(REPO_URL_FROM_PAYLOAD)); when(trigger.getTriggerMode()).thenReturn(GitHubPRTriggerMode.HEAVY_HOOKS); WorkflowJob job = jenkins.getInstance().createProject(WorkflowJob.class, "workflow-job"); job.addProperty(new GithubProjectProperty(REPO_URL_FROM_PAYLOAD)); job.addTrigger(trigger); new GHPullRequestSubscriber().onEvent(new GHSubscriberEvent( "", GHEvent.ISSUE_COMMENT, classpath("payload/issue_comment.json")) ); verify(trigger).queueRun(eq(job), eq(1)); }