GHPullRequestSubscriber extends AbstractGHPullRequestSubsriber { static Set<Job> getPRTriggerJobs(final String repo) { final Set<Job> ret = new HashSet<>(); ACL.impersonate(ACL.SYSTEM, () -> { List<Job> jobs = Jenkins.getActiveInstance().getAllItems(Job.class); ret.addAll(FluentIterableWrapper.from(jobs) .filter(isBuildable()) .filter(withPRTrigger()) .filter(withRepo(repo)) .toSet() ); }); return ret; }    }
@Test public void dontFailOnBadJob() throws IOException, ANTLRException { String goodRepo = "https: final FreeStyleProject job1 = jenkins.createProject(FreeStyleProject.class, "bad job"); job1.addProperty(new GithubProjectProperty("http: job1.addTrigger(new GitHubPRTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList())); Set<Job> jobs = getPRTriggerJobs(goodRepo); MatcherAssert.assertThat(jobs, hasSize(0)); final FreeStyleProject job2 = jenkins.createProject(FreeStyleProject.class, "good job"); job2.addProperty(new GithubProjectProperty(goodRepo)); job2.addTrigger(new GitHubPRTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList())); jobs = getPRTriggerJobs("KostyaSha-auto/test-repo"); MatcherAssert.assertThat(jobs, hasSize(1)); MatcherAssert.assertThat(jobs, hasItems(job2)); }