Skip to content

Commit

Permalink
Merge pull request #39 from jonyto123/feature/breaking-change
Browse files Browse the repository at this point in the history
  • Loading branch information
garethjevans authored Jun 21, 2021
2 parents 7ca340f + 3afeb78 commit 27206a9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private List<String> filterMergeCommits(List<String> commits) {

public Version nextVersion(Version in, List<String> commits) {
List<String> filtered = filterMergeCommits(commits);
List<String> breaking = filtered.stream().filter(s -> s.startsWith("BREAKING CHANGE")).collect(Collectors.toList());
List<String> breaking = filtered.stream().filter(s -> s.contains("!:") || breakingChangeFooter(s) ).collect(Collectors.toList());
List<String> features = filtered.stream().filter(s -> s.startsWith("feat")).collect(Collectors.toList());

if (!breaking.isEmpty()) {
Expand All @@ -25,4 +25,15 @@ public Version nextVersion(Version in, List<String> commits) {

return in.incrementPatchVersion();
}

private boolean breakingChangeFooter(String commit){
int startIndex = commit.lastIndexOf("\n");

String result = commit;

if(startIndex!=-1 && startIndex!= commit.length()){
result = commit.substring(startIndex+1);
}
return result.startsWith("BREAKING CHANGE");
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.jenkins.plugins.conventionalcommits;

import com.github.zafarkhaja.semver.Version;
import java.util.Arrays;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.CoreMatchers.*;
import java.util.Arrays;
import java.util.Collections;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

public class ConventionalCommitsTest {

Expand Down Expand Up @@ -79,4 +82,60 @@ public void willBumpMajorVersion_MultipleCommits() {
assertThat(out, is(notNullValue()));
assertThat(out.toString(), is("1.0.0"));
}

@Test
public void willBumpMajorVersion_ExclamationCommit() {
ConventionalCommits cc = new ConventionalCommits();

Version out = cc.nextVersion(Version.valueOf("0.0.1"), Collections.singletonList(
"feat!: new major version"));
assertThat(out, is(notNullValue()));
assertThat(out.toString(), is("1.0.0"));
}

@Test
public void willBumpMajorVersion_FooterMultipleLineCommit() {
ConventionalCommits cc = new ConventionalCommits();

Version out = cc.nextVersion(Version.valueOf("0.0.1"), Collections.singletonList(
"feat: new major version \nBREAKING CHANGE: new breaking change"
));
assertThat(out, is(notNullValue()));
assertThat(out.toString(), is("1.0.0"));
}

@Test
public void willNotBumpMajorVersion_ExclamationMultipleLineCommitNotFooter() {
ConventionalCommits cc = new ConventionalCommits();

Version out = cc.nextVersion(Version.valueOf("0.0.1"), Collections.singletonList(
"chore: new major version \nBREAKING CHANGE: new breaking change \nstupid footer"
));
assertThat(out, is(notNullValue()));
assertThat(out.toString(), is("0.0.2"));
}

@Test
public void willBumpMajorVersion_MultipleCommitsMultipleLineExclamation() {
ConventionalCommits cc = new ConventionalCommits();

Version out = cc.nextVersion(Version.valueOf("0.0.1"), Arrays.asList(
"feat!: add new feature",
"fix: bug fix",
"fix: another fix"));
assertThat(out, is(notNullValue()));
assertThat(out.toString(), is("1.0.0"));
}

@Test
public void willBumpMajorVersion_MultipleCommitsMultipleLineFooter() {
ConventionalCommits cc = new ConventionalCommits();

Version out = cc.nextVersion(Version.valueOf("0.0.1"), Arrays.asList(
"feat: add new feature",
"fix: bug fix \nBREAKING CHANGE: breaking change",
"fix: another fix"));
assertThat(out, is(notNullValue()));
assertThat(out.toString(), is("1.0.0"));
}
}

0 comments on commit 27206a9

Please sign in to comment.