Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
Only validate new commits #73
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jul 31, 2017
1 parent 80d7a08 commit c6adf16
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/main/java/se/bjurr/sbcc/RefChangeValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public void validateRefChange(
+ refChangeType);
if (compile(settings.getBranches().or(".*")).matcher(refId).find()) {
if (refChangeType != DELETE) {
List<SbccChangeSet> refChangeSets =
final List<SbccChangeSet> refChangeSets =
changesetsService.getNewChangeSets(
settings, fromRepository, refId, refChangeType, fromHash, toHash);
settings, fromRepository, refId, refChangeType, toHash);
validateRefChange(refChangeVerificationResult, refId, fromHash, toHash, refChangeSets);
}
}
Expand All @@ -93,7 +93,7 @@ private void validateRefChange(
String toHash,
List<SbccChangeSet> refChangeSets)
throws IOException, CredentialsRequiredException, ResponseException, ExecutionException {
SbccRefChangeVerificationResult refChangeVerificationResults =
final SbccRefChangeVerificationResult refChangeVerificationResults =
validateRefChange(refChangeSets, settings, refId, fromHash, toHash);
if (refChangeVerificationResults.hasReportables()) {
refChangeVerificationResult.add(refChangeVerificationResults);
Expand Down
18 changes: 4 additions & 14 deletions src/main/java/se/bjurr/sbcc/commits/ChangeSetsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.google.common.base.Optional;

public class ChangeSetsService {
private static final String FIRST_COMMIT = "0000000000000000000000000000000000000000";
private static Logger logger = getLogger(ChangeSetsService.class.getName());

private final ScmService scmService;
Expand All @@ -40,10 +39,9 @@ public List<SbccChangeSet> getNewChangeSets(
Repository repository,
String refId,
RefChangeType type,
String fromHash,
String toHash)
throws IOException {
return getNewChangesets(settings, repository, refId, type, fromHash, toHash);
return getNewChangesets(settings, repository, refId, type, toHash);
}

private Optional<GitScmCommandBuilder> findGitScmCommandBuilder(Repository repository) {
Expand All @@ -59,7 +57,6 @@ private List<SbccChangeSet> getNewChangesets(
Repository repository,
String refId,
RefChangeType type,
String fromHash,
String toHash) {

final Optional<GitScmCommandBuilder> gitScmCommandBuilder =
Expand All @@ -71,27 +68,20 @@ private List<SbccChangeSet> getNewChangesets(
if (refId.startsWith(TAGS.getPath())) {
return getTag(type, toHash, gitScmCommandBuilder);
} else {
return getCommits(fromHash, toHash, gitScmCommandBuilder, settings);
return getCommits( toHash, gitScmCommandBuilder, settings);
}
}

private List<SbccChangeSet> getCommits(
String fromHash,
String toHash,
Optional<GitScmCommandBuilder> gitScmCommandBuilder,
SbccSettings settings) {
final GitRevListBuilder revListBuilder =
gitScmCommandBuilder
.get() //
.revList() //
.format(FORMAT);
if (fromHash.equals(FIRST_COMMIT)) {
revListBuilder //
.revs(toHash, "--not", "--all");
} else {
revListBuilder //
.revs("^" + fromHash, toHash);
}
.format(FORMAT) //
.revs(toHash, "--not", "--all");

final List<SbccChangeSet> found =
revListBuilder //
Expand Down
14 changes: 6 additions & 8 deletions src/test/java/se/bjurr/sbcc/util/RefChangeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public RefChangeBuilder build() throws IOException {
ArgumentMatchers.any(Repository.class),
ArgumentMatchers.eq(this.refId),
ArgumentMatchers.eq(this.type),
ArgumentMatchers.eq(this.fromHash),
ArgumentMatchers.eq(this.toHash)))
.thenReturn(this.newChangesets);
return this;
Expand Down Expand Up @@ -213,20 +212,20 @@ public RefChangeBuilder hasTrimmedFlatOutput(final String output) {
public RefChangeBuilder run() throws IOException {
checkNotNull(this.refChange, "do 'throwing' or 'build' before.");
this.hook.setChangesetsService(this.changeSetService);
StringWriter stringWriter = new StringWriter();
PrintWriter scmHookDetailsOut = new PrintWriter(stringWriter);
ScmHookDetails scmHookDetails = mock(ScmHookDetails.class);
final StringWriter stringWriter = new StringWriter();
final PrintWriter scmHookDetailsOut = new PrintWriter(stringWriter);
final ScmHookDetails scmHookDetails = mock(ScmHookDetails.class);
when(scmHookDetails.out()).thenReturn(scmHookDetailsOut);
Repository repository = mock(Repository.class);
final Repository repository = mock(Repository.class);

repoHookResponse =
this.hook.performChecks(newArrayList(this.refChange), scmHookDetails, repository);
this.wasAccepted = repoHookResponse.isAccepted();
this.outputAll = stringWriter.toString();
if (!repoHookResponse.getVetoes().isEmpty()) {
String vetoSummary = repoHookResponse.getVetoes().get(0).getSummaryMessage();
final String vetoSummary = repoHookResponse.getVetoes().get(0).getSummaryMessage();
assertEquals(PR_REJECT_DEFAULT_MSG, vetoSummary);
String vetoDetail = repoHookResponse.getVetoes().get(0).getDetailedMessage();
final String vetoDetail = repoHookResponse.getVetoes().get(0).getDetailedMessage();
assertEquals("", this.outputAll);
this.outputAll = vetoDetail;
}
Expand All @@ -240,7 +239,6 @@ public RefChangeBuilder throwing(final IOException ioException) throws IOExcepti
ArgumentMatchers.any(Repository.class),
ArgumentMatchers.any(String.class),
ArgumentMatchers.any(RefChangeType.class),
ArgumentMatchers.any(String.class),
ArgumentMatchers.any(String.class)))
.thenThrow(ioException);
return this;
Expand Down

0 comments on commit c6adf16

Please sign in to comment.