GitHubPRRepository extends GitHubRepository<GitHubPRRepository> { @Nonnull public Map<Integer, List<Run<?, ?>>> getAllPrBuilds() { Map<Integer, List<Run<?, ?>>> map = new HashMap<>(); final RunList<?> runs = job.getBuilds(); LOG.debug("Got builds for job {}", job.getFullName()); for (Run<?, ?> run : runs) { GitHubPRCause cause = ghPRCauseFromRun(run); if (cause != null) { int number = cause.getNumber(); List<Run<?, ?>> buildsByNumber = map.get(number); if (isNull(buildsByNumber)) { buildsByNumber = new ArrayList<>(); map.put(number, buildsByNumber); } buildsByNumber.add(run); } } return map; } GitHubPRRepository(@Nonnull GHRepository ghRepository);  GitHubPRRepository(String repoFullName, URL githubUrl); @Nonnull Map<Integer, GitHubPRPullRequest> getPulls(); @Nonnull Map<Integer, List<Run<?, ?>>> getAllPrBuilds(); @Override String getIconFileName(); @Override String getDisplayName(); @Override String getUrlName(); @Override void actualiseOnChange(@Nonnull GHRepository ghRepository, @Nonnull TaskListener listener); @RequirePOST FormValidation doClearRepo(); @RequirePOST FormValidation doRunTrigger(); @RequirePOST FormValidation doRebuildAllFailed(); @Override FormValidation doBuild(StaplerRequest req); @RequirePOST FormValidation doRebuild(StaplerRequest req); void setJob(Job<?, ?> job); void setConfigFile(XmlFile configFile); static final String FILE; }
@Test public void getAllPrBuildsWithCause() { GitHubPRRepositoryFactoryTest.createForCommonExpectations(job, trigger); getAllPrBuildsCommonExpectations(BUILD_MAP_SIZE); GitHubPRRepository repo = GitHubPRRepositoryFactoryTest.getRepo(factory.createFor(job)); Map<Integer, List<Run<?, ?>>> prBuilds = repo.getAllPrBuilds(); verify(iterator, times(BUILD_MAP_SIZE + 1)).hasNext(); verify(iterator, times(BUILD_MAP_SIZE)).next(); Assert.assertEquals(0, prBuilds.size()); }
@Test public void getAllPrBuildsNullCause() { GitHubPRRepositoryFactoryTest.createForCommonExpectations(job, trigger); getAllPrBuildsCommonExpectations(BUILD_MAP_SIZE); when(run.getCause(GitHubPRCause.class)).thenReturn(null); GitHubPRRepository repo = GitHubPRRepositoryFactoryTest.getRepo(factory.createFor(job)); Map<Integer, List<Run<?, ?>>> prBuilds = repo.getAllPrBuilds(); Assert.assertEquals(0, prBuilds.size()); }