Skip to content

Commit

Permalink
Added variables: messageTitle, messageBody, messageItems
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Feb 9, 2016
1 parent 4e25e7e commit 80609aa
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 17 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ Changelog of Git Changelog.
## Next release
### Other changes

[a10bef4d61b05d3](https://github.com/tomasbjerre/git-changelog-lib/commit/a10bef4d61b05d3) Tomas Bjerre *2016-01-31 12:14:45*
[04f9efa398d3834](https://github.com/tomasbjerre/git-changelog-lib/commit/04f9efa398d3834) Tomas Bjerre *2016-02-09 19:09:13*

Added variables: messageTitle, messageBody, messageItems

[4e25e7e2cf5d5ec](https://github.com/tomasbjerre/git-changelog-lib/commit/4e25e7e2cf5d5ec) Tomas Bjerre *2016-01-31 21:12:35*

Maven Central version badge in README.md

[1e5cb6c76a681aa](https://github.com/tomasbjerre/git-changelog-lib/commit/1e5cb6c76a681aa) Tomas Bjerre *2016-01-31 12:15:00*

Better error message when commit not found

Expand Down
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,32 @@ The template is supplied with a datastructure like:
* commits
- authorName
- authorEmailAddress
- message
- commitTime
- message (The full message)
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
* tags
- name
* commits
- authorName
- authorEmailAddress
- message
- commitTime
- message (The full message)
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
* authors
- authorName
- authrorEmail
* commits
- authorName
- authorEmailAddress
- message
- commitTime
- message (The full message)
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
* issues
- name
- hasIssue
Expand All @@ -116,24 +125,33 @@ The template is supplied with a datastructure like:
* commits
- authorName
- authorEmailAddress
- message
- commitTime
- message (The full message)
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
* authors
- authorName
- authrorEmail
* commits
- authorName
- authorEmailAddress
- message
- commitTime
- message (The full message)
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
* authors
- authorName
- authrorEmail
* commits
- authorName
- authorEmailAddress
- message
- commitTime
- message (The full message)
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
* issues
- name
- hasIssue
Expand All @@ -145,16 +163,22 @@ The template is supplied with a datastructure like:
* commits
- authorName
- authorEmailAddress
- message
- commitTime
- message (The full message)
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
* authors
- authorName
- authrorEmail
* commits
- authorName
- authorEmailAddress
- message
- commitTime
- message (The full message)
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
```

## MediaWiki
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/se/bjurr/gitchangelog/api/model/Commit.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,48 @@

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.List;

public class Commit {
private final String authorName;
private final String authorEmailAddress;
private final String commitTime;
private final Long commitTimeLong;
private final String message;
private final String messageTitle;
private final String messageBody;
private final List<String> messageBodyItems;
private final String hash;

public Commit(String authorName, String authorEmailAddress, String commitTime, Long commitTimeLong, String message,
String hash) {
String hash, String messageTitle, String messageBody, List<String> messageBodyItems) {
this.authorName = checkNotNull(authorName, "authorName");
this.authorEmailAddress = checkNotNull(authorEmailAddress, "authorEmailAddress");
this.message = checkNotNull(message, "message").trim();
this.commitTime = checkNotNull(commitTime, "commitTime");
this.commitTimeLong = checkNotNull(commitTimeLong, "commitTimeLong");
this.hash = checkNotNull(hash, "hash");
this.messageTitle = checkNotNull(messageTitle, "messageTitle");
this.messageBody = checkNotNull(messageBody, "messageBody");
this.messageBodyItems = checkNotNull(messageBodyItems, "messageBodyItems");
}

public String getHash() {
return hash;
}

public String getMessageBody() {
return messageBody;
}

public List<String> getMessageBodyItems() {
return messageBodyItems;
}

public String getMessageTitle() {
return messageTitle;
}

public String getAuthorEmailAddress() {
return authorEmailAddress;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package se.bjurr.gitchangelog.internal.model;

import static com.google.common.base.Joiner.on;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
Expand Down Expand Up @@ -32,6 +33,7 @@
import se.bjurr.gitchangelog.internal.settings.Settings;
import se.bjurr.gitchangelog.internal.settings.SettingsIssue;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Multimap;
Expand Down Expand Up @@ -175,17 +177,78 @@ private Commit toCommit(GitCommit gitCommit) {
gitCommit.getAuthorEmailAddress(), //
format(gitCommit.getCommitTime()), //
gitCommit.getCommitTime().getTime(), //
toMessage(gitCommit.getMessage()), //
gitCommit.getHash());
toMessage(settings.removeIssueFromMessage(), new IssuesUtil(settings).getIssues(), gitCommit.getMessage()), //
gitCommit.getHash(),//
toMessageTitle(settings.removeIssueFromMessage(), new IssuesUtil(settings).getIssues(), gitCommit.getMessage()),//
toMessageBody(settings.removeIssueFromMessage(), new IssuesUtil(settings).getIssues(), gitCommit.getMessage()),//
toMessageItems(settings.removeIssueFromMessage(), new IssuesUtil(settings).getIssues(), gitCommit.getMessage()));
}

private String toMessage(String message) {
if (settings.removeIssueFromMessage()) {
for (SettingsIssue issue : new IssuesUtil(settings).getIssues()) {
message = message.replaceAll(issue.getPattern(), "");
@VisibleForTesting
List<String> toMessageItems(Boolean removeIssueFromMessage, List<SettingsIssue> issues, String message) {
List<String> toReturn = newArrayList();
List<String> stringList = toNoEmptyStringsList(removeIssuesFromString(removeIssueFromMessage, issues, message));
if (stringList.size() > 1) {
List<String> notFirst = notFirst(stringList);
for (String part : notFirst) {
String candidate = part.trim();
if (candidate.startsWith("*")) {
candidate = candidate.substring(1).trim();
}
if (!candidate.isEmpty()) {
toReturn.add(candidate);
}
}
}
return message;
return toReturn;
}

@VisibleForTesting
String toMessageBody(Boolean removeIssueFromMessage, List<SettingsIssue> issues, String message) {
List<String> stringList = toNoEmptyStringsList(removeIssuesFromString(removeIssueFromMessage, issues, message));
if (stringList.size() > 1) {
List<String> notFirst = notFirst(stringList);
return on("\n")//
.join(notFirst);
}
return "";
}

@VisibleForTesting
String toMessageTitle(Boolean removeIssueFromMessage, List<SettingsIssue> issues, String message) {
List<String> stringList = toNoEmptyStringsList(removeIssuesFromString(removeIssueFromMessage, issues, message));
if (stringList.size() > 0) {
return stringList.get(0);
}
return "";
}

@VisibleForTesting
String toMessage(boolean removeIssueFromMessage, List<SettingsIssue> issues, String message) {
return removeIssuesFromString(removeIssueFromMessage, issues, message);
}

private List<String> notFirst(List<String> stringList) {
return stringList.subList(1, stringList.size());
}

private List<String> toNoEmptyStringsList(String message) {
List<String> toReturn = newArrayList();
for (String part : message.split("\n")) {
if (!part.isEmpty()) {
toReturn.add(part);
}
}
return toReturn;
}

private String removeIssuesFromString(boolean removeIssueFromMessage, List<SettingsIssue> issues, String string) {
if (removeIssueFromMessage) {
for (SettingsIssue issue : issues) {
string = string.replaceAll(issue.getPattern(), "");
}
}
return string;
}

private String format(Date commitTime) {
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/se/bjurr/gitchangelog/api/TemplatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public void testCommits() throws Exception {
test("testCommits");
}

@Test
public void testCommitsVariables() throws Exception {
test("testCommitsVariables");
}

@Test
public void testIssuesCommits() throws Exception {
test("testIssuesCommits");
Expand Down
Loading

0 comments on commit 80609aa

Please # to comment.