public String getRevision() { final String revisionNumber = modification.getRevision(); if (revisionNumber.length() < 12) { return revisionNumber; } return revisionNumber.substring(0, 12) + "..."; }
public static List<Modification> filterOutRevision(List<Modification> modifications, Revision withoutThisRevision) { List<Modification> filtered = new ArrayList<>(); for (Modification modification : modifications) { if (!modification.getRevision().equals(withoutThisRevision.getRevision())) { filtered.add(modification); } } return filtered; }
public static Revision latestRevision(List<Modification> modifications) { if (modifications.isEmpty()) { throw new RuntimeException("Cannot find latest revision."); } else { return new StringRevision(modifications.get(0).getRevision()); } }
@Override public void emailContent(StringBuilder content, Modification modification) { String scmDetails = getTypeForDisplay() + " : " + getDisplayName(); String revisionDetails = format("revision: %s, completed on %s\n%s", modification.getRevision(), modification.getModifiedTime(), Optional.ofNullable(modification.getComment()).orElse("")); content.append(scmDetails).append('\n').append(revisionDetails); }
public String getRevisionAtLastAttempt(MaterialConfig material) { PartialConfigParseResult result = getLastParseResult(material); if (result == null) return null; return result.getLatestParsedModification().getRevision(); }
@Test public void shouldGetChangesSinceARevision() throws Exception { List<Modification> output = p4.changesSince(new StringRevision("1")); assertThat(output.size(), is(3)); assertThat(output.get(0).getRevision(), is("4")); assertThat(output.get(1).getRevision(), is("3")); assertThat(output.get(2).getRevision(), is("2")); }
public Revision oldestRevision(Modifications modifications) { if (modifications.size() > 1) { LOGGER.warn("Dependency material {} has multiple modifications", this.getDisplayName()); } Modification oldestModification = modifications.get(modifications.size() - 1); String revision = oldestModification.getRevision(); return DependencyMaterialRevision.create(revision, oldestModification.getPipelineLabel()); }
@Test public void shouldGetModifications() throws Exception { List<Modification> actual = hgCommand.modificationsSince(new StringRevision(REVISION_0)); assertThat(actual.size(), is(2)); assertThat(actual.get(0).getRevision(), is(REVISION_2)); assertThat(actual.get(1).getRevision(), is(REVISION_1)); }
@Test public void shouldGetModificationsBasedOnRevision() { List<Modification> modificationsSince = hgMaterial.modificationsSince(workingFolder, new StringRevision(REVISION_0), new TestSubprocessExecutionContext()); assertThat(modificationsSince.get(0).getRevision(), is(REVISION_2)); assertThat(modificationsSince.get(1).getRevision(), is(REVISION_1)); assertThat(modificationsSince.size(), is(2)); }
@Test public void shouldGetLatestChange() throws Exception { List<Modification> modificationList = p4.latestChange(); assertThat(modificationList.size(), is(1)); assertThat(modificationList.get(0).getRevision(), is("4")); }
@Test public void shouldIncludeChangesFromTheFutureInModificationCheck() throws Exception { String originalNode = git.latestModification().get(0).getRevision(); File testingFile = checkInNewRemoteFileInFuture(THREE_DAYS_FROM_NOW); Modification modification = git.latestModification().get(0); assertThat(modification.getRevision(), is(not(originalNode))); assertThat(modification.getComment(), is("New checkin of " + testingFile.getName())); assertThat(modification.getModifiedTime(), is(THREE_DAYS_FROM_NOW)); }
@Test public void shouldNotGetModificationsFromOtherBranches() throws Exception { makeACommitToSecondBranch(); hg(workingDirectory, "pull").runOrBomb(null); List<Modification> actual = hgCommand.modificationsSince(new StringRevision(REVISION_0)); assertThat(actual.size(), is(2)); assertThat(actual.get(0).getRevision(), is(REVISION_2)); assertThat(actual.get(1).getRevision(), is(REVISION_1)); }
@Test public void shouldGetModifications() { List<Modification> mods = hgMaterial.modificationsSince(workingFolder, new StringRevision(REVISION_0), new TestSubprocessExecutionContext()); assertThat(mods.size(), is(2)); Modification modification = mods.get(0); assertThat(modification.getRevision(), is(REVISION_2)); assertThat(modification.getModifiedFiles().size(), is(1)); }
public static void toJSON(OutputWriter jsonOutputWriter, Modification model, Material material) { jsonOutputWriter .addLinks(linksWriter -> { linksWriter.addLink("vsm", Routes.Materials.vsm(material.getFingerprint(), model.getRevision())); }) .addIfNotNull("user_name", model.getUserName()) .addIfNotNull("email_address", model.getEmailAddress()) .addIfNotNull("revision", model.getRevision()) .addIfNotNull("modified_time", model.getModifiedTime()) .addIfNotNull("comment", model.getComment()); } }
@Test public void shouldRetrieveLatestModification() throws Exception { Modification mod = git.latestModification().get(0); assertThat(mod.getUserName(), is("Chris Turner <cturner@thoughtworks.com>")); assertThat(mod.getComment(), is("Added 'run-till-file-exists' ant target")); assertThat(mod.getModifiedTime(), is(parseRFC822("Fri, 12 Feb 2010 16:12:04 -0800"))); assertThat(mod.getRevision(), is("5def073a425dfe239aabd4bf8039ffe3b0e8856b")); List<ModifiedFile> files = mod.getModifiedFiles(); assertThat(files.size(), is(1)); assertThat(files.get(0).getFileName(), is("build.xml")); assertThat(files.get(0).getAction(), Matchers.is(ModifiedAction.modified)); }
@Test public void shouldReturnNothingForModificationsSinceIfARebasedCommitSHAIsPassed() throws IOException { GitTestRepo remoteRepo = new GitTestRepo(temporaryFolder); executeOnGitRepo("git", "remote", "rm", "origin"); executeOnGitRepo("git", "remote", "add", "origin", remoteRepo.projectRepositoryUrl()); GitCommand command = new GitCommand(remoteRepo.createMaterial().getFingerprint(), gitLocalRepoDir, "master", false, new HashMap<>(), null); Modification modification = remoteRepo.addFileAndAmend("foo", "amendedCommit").get(0); assertThat(command.modificationsSince(new StringRevision(modification.getRevision())).isEmpty(), is(true)); }
@Test(expected = CommandLineException.class) public void shouldBombIfCheckedForModificationsSinceWithANonExistentRef() throws IOException { GitTestRepo remoteRepo = new GitTestRepo(temporaryFolder); executeOnGitRepo("git", "remote", "rm", "origin"); executeOnGitRepo("git", "remote", "add", "origin", remoteRepo.projectRepositoryUrl()); GitCommand command = new GitCommand(remoteRepo.createMaterial().getFingerprint(), gitLocalRepoDir, "non-existent-branch", false, new HashMap<>(), null); Modification modification = remoteRepo.checkInOneFile("foo", "Adding a commit").get(0); command.modificationsSince(new StringRevision(modification.getRevision())); }
@Test(expected = CommandLineException.class) public void shouldBombIfCheckedForModificationsSinceWithASHAThatNoLongerExists() throws IOException { GitTestRepo remoteRepo = new GitTestRepo(temporaryFolder); executeOnGitRepo("git", "remote", "rm", "origin"); executeOnGitRepo("git", "remote", "add", "origin", remoteRepo.projectRepositoryUrl()); GitCommand command = new GitCommand(remoteRepo.createMaterial().getFingerprint(), gitLocalRepoDir, "master", false, new HashMap<>(), null); Modification modification = remoteRepo.checkInOneFile("foo", "Adding a commit").get(0); remoteRepo.addFileAndAmend("bar", "amendedCommit"); command.modificationsSince(new StringRevision(modification.getRevision())); }
@Override void populateXmlForModifications(Modifications modifications, XmlWriterContext writerContext, Element modificationsTag) { Modification firstModification = modifications.first(); Element changeset = modificationsTag.addElement("changeset"); String revision = firstModification.getRevision(); changeset.addAttribute("changesetUri", StageXmlViewModel.httpUrlFor(writerContext.getBaseUrl(), writerContext.stageIdForLocator(revision))); changeset.addElement("checkinTime").addText(DateUtils.formatISO8601(firstModification.getModifiedTime())); changeset.addElement("revision").addText(revision); } }
@Test public void updateToANewRevisionShouldNotResultInUnshallowing() throws IOException { GitMaterial material = new GitMaterial(repo.projectRepositoryUrl(), true); material.updateTo(inMemoryConsumer(), workingDir, new RevisionContext(REVISION_4, REVISION_4, 1), context()); assertThat(localRepoFor(material).isShallow(), is(true)); List<Modification> modifications = repo.addFileAndPush("newfile", "add new file"); StringRevision newRevision = new StringRevision(modifications.get(0).getRevision()); material.updateTo(inMemoryConsumer(), workingDir, new RevisionContext(newRevision, newRevision, 1), context()); assertThat(new File(workingDir, "newfile").exists(), is(true)); assertThat(localRepoFor(material).isShallow(), is(true)); }