private boolean isPassed(Build build, ValidationStamp validationStamp) { List<ValidationRun> runs = structureService.getValidationRunsForBuildAndValidationStamp( build.getId(), validationStamp.getId(), 0, 1 ); if (runs.isEmpty()) { return false; } else { ValidationRun run = runs.get(0); return Objects.equals( run.getLastStatus().getStatusID(), ValidationRunStatusID.STATUS_PASSED ); } }
private Optional<Build> createBuild(String tagsPath, SVNSyncProperty syncProperty, Branch branch, TCopyEvent copy, ConfiguredBuildSvnRevisionLink<?> revisionLink, SVNRepository repository) { // Extracts the build name from the copyTo path return getBuildNameFromPath(tagsPath, revisionLink, copy.copyToLocation()) .flatMap(buildName -> { // Gets an existing build if any Optional<Build> build = structureService.findBuildByName(branch.getProject().getName(), branch.getName(), buildName); // If none exists, just creates it if (!build.isPresent()) { logger.debug("[svn-sync] Build {} does not exist - creating.", buildName); return Optional.of(doCreateBuild(branch, copy, buildName, repository)); } // If Ok to override, deletes it and creates it else if (syncProperty.isOverride()) { logger.debug("[svn-sync] Build {} already exists - overriding.", buildName); // Deletes the build structureService.deleteBuild(build.get().getId()); // Creates the build return Optional.of(doCreateBuild(branch, copy, buildName, repository)); } // Else, just puts some log entry else { logger.debug("[svn-sync] Build {} already exists - not overriding.", buildName); return Optional.empty(); } }); }
@Override public List<LinkDefinition<Build>> getLinkDefinitions() { return Arrays.asList( LinkDefinitions.link( "_changeLog", build -> { BuildDiffRequest request = new BuildDiffRequest(); request.setFrom(build.getId()); return MvcUriComponentsBuilder.on(SVNController.class).changeLog(request); }, (build, rc) -> rc.isProjectFunctionGranted(build, ProjectView.class) && svnService.getSVNRepository(build.getBranch()).isPresent() ), LinkDefinitions.page( "_changeLogPage", (build, resourceContext) -> resourceContext.isProjectFunctionGranted(build, ProjectView.class) && svnService.getSVNRepository(build.getBranch()).isPresent(), "extension/svn/changelog" ) ); }
@Override public Event deleteBuild(Build build) { return Event.of(DELETE_BUILD) .withBranch(build.getBranch()) .with("build", build.getName()) .with("build_id", build.getId().toString()) .get(); }
@Override @Transactional public SVNChangeLog changeLog(BuildDiffRequest request) { try (Transaction ignored = transactionService.start()) { // Gets the two builds Build buildFrom = structureService.getBuild(request.getFrom()); Build buildTo = structureService.getBuild(request.getTo()); // Ordering of builds if (buildFrom.id() > buildTo.id()) { Build t = buildFrom; buildFrom = buildTo; buildTo = t; } // Gets the two branches, for each build Branch branchFrom = buildFrom.getBranch(); Branch branchTo = buildTo.getBranch(); // Checks the branch is the same if (branchFrom.id() != branchTo.id()) { throw new SVNChangeLogDifferentBranchException(); } SVNRepository svnRepository = getSVNRepository(branchFrom); return new SVNChangeLog( UUID.randomUUID().toString(), branchFrom.getProject(), svnRepository, getSCMBuildView(svnRepository, buildFrom.getId()), getSCMBuildView(svnRepository, buildTo.getId()) ); } }