Skip to content

Commit

Permalink
Removing commits without issue, from tags #19
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Mar 20, 2016
1 parent 700bdfd commit 22a2c55
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 5 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Changelog of Git Changelog.
## Next release
### GitHub [#19](https://github.com/tomasbjerre/git-changelog-lib/issues/19) Feature-request (or question): Issues by category

**Removing commits without issue, from tags**


[43d69441f467ae2](https://github.com/tomasbjerre/git-changelog-lib/commit/43d69441f467ae2) Tomas Bjerre *2016-03-20 08:37:54*


## 1.37
### GitHub [#19](https://github.com/tomasbjerre/git-changelog-lib/issues/19) Feature-request (or question): Issues by category

**Ignore commits without issue**


Expand All @@ -29,7 +38,7 @@ Changelog of Git Changelog.
**Avoiding parsing commits twice**


[8d25dfd11b7d63c](https://github.com/tomasbjerre/git-changelog-lib/commit/8d25dfd11b7d63c) Tomas Bjerre *2016-03-19 23:22:31*
[cb23e700107d5c1](https://github.com/tomasbjerre/git-changelog-lib/commit/cb23e700107d5c1) Tomas Bjerre *2016-03-20 06:52:21*

**Updating test cases after changing test-branch**

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static com.google.common.io.Resources.getResource;
import static se.bjurr.gitchangelog.api.GitChangelogApiConstants.REF_MASTER;
import static se.bjurr.gitchangelog.api.GitChangelogApiConstants.ZERO_COMMIT;
import static se.bjurr.gitchangelog.internal.git.GitRepoDataHelper.removeCommitsWithoutIssue;
import static se.bjurr.gitchangelog.internal.settings.Settings.fromFile;

import java.io.File;
Expand Down Expand Up @@ -371,8 +372,12 @@ private Changelog getChangelog(GitRepo gitRepo) throws GitChangelogRepositoryExc
.or(gitRepo.getRef(REF_MASTER));
GitRepoData gitRepoData = gitRepo.getGitRepoData(fromId, toId, settings.getUntaggedName());
List<GitCommit> diff = gitRepoData.getGitCommits();
List<GitTag> tags = gitRepoData.getGitTags();
List<ParsedIssue> issues = new IssueParser(settings, diff).parseForIssues();
if (settings.ignoreCommitsWithoutIssue()) {
gitRepoData = removeCommitsWithoutIssue(issues, gitRepoData);
diff = gitRepoData.getGitCommits();
}
List<GitTag> tags = gitRepoData.getGitTags();
Transformer transformer = new Transformer(settings);
return new Changelog(//
transformer.toCommits(diff), //
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package se.bjurr.gitchangelog.internal.git;

import static com.google.common.base.Predicates.in;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.isEmpty;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;

import java.util.List;
import java.util.Set;

import se.bjurr.gitchangelog.internal.git.model.GitCommit;
import se.bjurr.gitchangelog.internal.git.model.GitTag;
import se.bjurr.gitchangelog.internal.model.ParsedIssue;

public class GitRepoDataHelper {
private GitRepoDataHelper() {
}

public static GitRepoData removeCommitsWithoutIssue(List<ParsedIssue> allParsedIssues, GitRepoData gitRepoData) {
Set<GitCommit> commitsWithIssues = newHashSet();
for (ParsedIssue parsedIssue : allParsedIssues) {
for (GitCommit gitCommit : parsedIssue.getGitCommits()) {
commitsWithIssues.add(gitCommit);
}
}
List<GitCommit> reducedGitCommits = newArrayList(commitsWithIssues);

List<GitTag> reducedGitTags = newArrayList();
for (GitTag gitTag : gitRepoData.getGitTags()) {
Iterable<GitCommit> reducedCommitsInTag = filter(gitTag.getGitCommits(), in(reducedGitCommits));
if (!isEmpty(reducedCommitsInTag)) {
reducedGitTags.add(new GitTag(gitTag.getName(), newArrayList(reducedCommitsInTag)));
}
}

return new GitRepoData(reducedGitCommits, reducedGitTags);
}

}
31 changes: 28 additions & 3 deletions src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public void testThatIssuesCanBeRemoved() throws Exception {
}

@Test
public void testThatCommitsWithoutIssueCanBeIgnored() throws Exception {
public void testThatCommitsWithoutIssueCanBeIgnoredIssuesCommits() throws Exception {

String expected = Resources.toString(getResource("assertions/testThatCommitsWithoutIssueCanBeIgnored.md"), UTF_8)
.trim();
String expected = Resources.toString(
getResource("assertions/testThatCommitsWithoutIssueCanBeIgnoredIssuesCommits.md"), UTF_8).trim();

URL settingsFile = getResource("settings/git-changelog-test-settings.json").toURI().toURL();
String templatePath = "templates/testIssuesCommits.mustache";
Expand All @@ -108,6 +108,31 @@ public void testThatCommitsWithoutIssueCanBeIgnored() throws Exception {
expected, changelogApiBuilder.render().trim());
}

/**
* The test-lightweight-2 should be ignored here.
*/
@Test
public void testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits() throws Exception {

String expected = Resources.toString(
getResource("assertions/testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits.md"), UTF_8).trim();

getResource("settings/git-changelog-test-settings.json").toURI().toURL();
String templatePath = "templates/testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits.mustache";

String templateContent = Resources.toString(getResource(templatePath), UTF_8);

GitChangelogApi changelogApiBuilder = gitChangelogApiBuilder()//
.withFromCommit(ZERO_COMMIT)//
.withToRef("test")//
.withCustomIssue("JIRA", "JIR-[0-9]*", "http://${PATTERN_GROUP}", "${PATTERN_GROUP}")//
.withIgnoreCommitsWithoutIssue(true) //
.withTemplatePath(templatePath);

assertEquals("templateContent:\n" + templateContent + "\nContext:\n" + toJson(changelogApiBuilder.getChangelog()),
expected, changelogApiBuilder.render().trim());
}

@Test
public void testThatReadableGroupMustExist() throws Exception {
URL settingsFile = getResource("settings/git-changelog-test-settings.json").toURI().toURL();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Git Changelog changelog

Changelog of Git Changelog.

## JIRA [JIR-1234](http://JIR-1234) JIR-1234

### Tomas Bjerre - 2016-02-15 16:30:35
[cc0fbbd8bc63955](https://server/cc0fbbd8bc63955)

Adding stuff with a jira JIR-1234

## JIRA [JIR-5262](http://JIR-5262) JIR-5262

### Tomas Bjerre - 2016-02-15 16:12:02
[071a14f29020758](https://server/071a14f29020758)

Adding stuff with a jira
JIR-5262



------


### Tomas Bjerre - 2016-02-15 16:30:35
[cc0fbbd8bc63955](https://server/cc0fbbd8bc63955)

Adding stuff with a jira JIR-1234

### Tomas Bjerre - 2016-02-15 16:12:02
[071a14f29020758](https://server/071a14f29020758)

Adding stuff with a jira
JIR-5262
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Git Changelog changelog

Changelog of Git Changelog.

{{#issues}}
{{#hasLink}}
## {{name}} [{{issue}}]({{link}}) {{title}}
{{/hasLink}}
{{^hasLink}}
## {{name}} {{title}}
{{/hasLink}}

{{#commits}}
### {{authorName}} - {{commitTime}}
[{{hash}}](https://server/{{hash}})

{{{message}}}

{{/commits}}
{{/issues}}


------


{{#commits}}
### {{authorName}} - {{commitTime}}
[{{hash}}](https://server/{{hash}})

{{{message}}}

{{/commits}}

0 comments on commit 22a2c55

Please sign in to comment.