Skip to content

Commit

Permalink
Add support for skipping commits in changelog that contain a string
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkreska committed Mar 18, 2016
1 parent 0fb060e commit 6931f73
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ public class GitChangelogMojo extends AbstractGitOutputMojo {
defaultValue = "\nVersion %s – %s\n")
protected String tagFormat;

/**
* Whether to skip commits' containing a string
* <br>
* This is useful when using jgitflow and removing commits like "[maven-jgitflow]....[maven-jgitflow]"
*/
@Parameter(property = "mavanagaiata.changelog.skipCommits",
defaultValue = "false")
protected boolean skipCommits;

/**
* The format for a tag line
*
* @since 0.7.0
*/
@Parameter(property = "mavanagaiata.changelog.skipCommitFormat",
defaultValue = "[maven-jgitflow]")
protected String skipCommitFormat;

/**
* Walks through the history of the currently checked out branch of the
* Git repository and builds a changelog from the commits contained in that
Expand Down Expand Up @@ -269,6 +287,9 @@ public GitTag getCurrentTag() {
}

protected void run() throws GitRepositoryException {
if ( skipCommits && this.currentCommit.getMessageSubject().contains( skipCommitFormat )) {
return ;
}
if (repository.getTags().containsKey(this.currentCommit.getId())) {
this.lastTag = this.currentTag;
this.currentTag = repository.getTags().get(this.currentCommit.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public void setup() throws Exception {
this.mojo.header = "Changelog\\n=========\\n";
this.mojo.skipTagged = false;
this.mojo.tagFormat = "\\nVersion %s – %s\\n";
this.mojo.skipCommits = false;
this.mojo.skipCommitFormat = "[maven-jgitflow]";

this.mockCommits = new ArrayList<GitCommit>();
this.mockCommits.add(mockCommit("598a75596868dec45f8e6a808a07d533bc0184f0", "8th commit"));
Expand All @@ -63,6 +65,7 @@ public void setup() throws Exception {
this.mockCommits.add(mockCommit("5979a86e9bb091fc792529bee68ed222000ebc7e", "3rd commit"));
this.mockCommits.add(mockCommit("b3b28176c1a05b76fb9231abe2f2cbbf15a86118", "2nd commit"));
this.mockCommits.add(mockCommit("e82314841e1d990eeb33878cae55dadc8a11bf68", "1st commit"));
this.mockCommits.add(mockCommit("f82314841e1d990eeb33878cae55dadc8a11bf61", "[maven-jgitflow]"));

HashMap<String, GitTag> tags = new HashMap<String, GitTag>();
GitTag tag1 = mock(GitTag.class);
Expand Down Expand Up @@ -159,6 +162,7 @@ public void testCustomization() throws Exception {
this.assertOutputLine("- 3rd commit");
this.assertOutputLine("- 2nd commit");
this.assertOutputLine("- 1st commit");
this.assertOutputLine("- [maven-jgitflow]");
this.assertOutputLine("");
this.assertOutputLine("Git history for 1.0.0: https://github.com/koraktor/mavanagaiata/commits/1.0.0");
this.assertOutputLine("");
Expand All @@ -183,6 +187,36 @@ public void testResult() throws Exception {
this.mojo.initConfiguration();
this.mojo.run();

this.assertOutputLine("Changelog");
this.assertOutputLine("=========");
this.assertOutputLine("");
this.assertOutputLine("Commits on branch \"master\"");
this.assertOutputLine("");
this.assertOutputLine(" * 8th commit");
this.assertOutputLine(" * 7th commit");
this.assertOutputLine("");
this.assertOutputLine("Version 2.0.0 – 05/29/2010 01:18 PM +0200");
this.assertOutputLine("");
this.assertOutputLine(" * 6th commit");
this.assertOutputLine(" * 5th commit");
this.assertOutputLine(" * 4th commit");
this.assertOutputLine("");
this.assertOutputLine("Version 1.0.0 – 11/03/2006 07:08 PM +0000");
this.assertOutputLine("");
this.assertOutputLine(" * 3rd commit");
this.assertOutputLine(" * 2nd commit");
this.assertOutputLine(" * 1st commit");
this.assertOutputLine(" * [maven-jgitflow]");
this.assertOutputLine("Footer");
this.assertOutputLine(null);
}

@Test
public void testSkipCommits() throws Exception {
this.mojo.skipCommits = true;
this.mojo.initConfiguration();
this.mojo.run();

this.assertOutputLine("Changelog");
this.assertOutputLine("=========");
this.assertOutputLine("");
Expand Down Expand Up @@ -227,6 +261,7 @@ public void testStartTagged() throws Exception {
this.assertOutputLine(" * 3rd commit");
this.assertOutputLine(" * 2nd commit");
this.assertOutputLine(" * 1st commit");
this.assertOutputLine(" * [maven-jgitflow]");
this.assertOutputLine("Footer");
this.assertOutputLine(null);
}
Expand Down Expand Up @@ -254,6 +289,7 @@ public void testSkipTagged() throws Exception {
this.assertOutputLine("");
this.assertOutputLine(" * 2nd commit");
this.assertOutputLine(" * 1st commit");
this.assertOutputLine(" * [maven-jgitflow]");
this.assertOutputLine("Footer");
this.assertOutputLine(null);
}
Expand All @@ -279,6 +315,7 @@ public void testUntaggedProject() throws Exception {
this.assertOutputLine(" * 3rd commit");
this.assertOutputLine(" * 2nd commit");
this.assertOutputLine(" * 1st commit");
this.assertOutputLine(" * [maven-jgitflow]");
this.assertOutputLine("Footer");
this.assertOutputLine(null);
}
Expand Down

0 comments on commit 6931f73

Please sign in to comment.