diff --git a/.gitignore b/.gitignore index bdcaeb4b..a0671681 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ temp .couscous couscous.phar .okhttpcache +.idea +classes diff --git a/README.md b/README.md index b10fa2a2..e640724c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Here is an example template. Changelog of Git Changelog. {{#tags}} -## {{name}} +## {{name}}{{#hasTagTime}} ({{tagTime}}){{/hasTagTime}} {{#issues}} {{#hasIssue}} {{#hasLink}} @@ -81,6 +81,8 @@ The template is supplied with a datastructure like: * tags - name - annotation + - tagTime + - hasTagTime * commits - authorName - authorEmailAddress diff --git a/src/main/java/se/bjurr/gitchangelog/api/model/Tag.java b/src/main/java/se/bjurr/gitchangelog/api/model/Tag.java index 825ea95d..0b8c188c 100644 --- a/src/main/java/se/bjurr/gitchangelog/api/model/Tag.java +++ b/src/main/java/se/bjurr/gitchangelog/api/model/Tag.java @@ -6,6 +6,8 @@ import se.bjurr.gitchangelog.api.model.interfaces.ICommits; import se.bjurr.gitchangelog.api.model.interfaces.IIssues; +import static com.google.common.base.Strings.isNullOrEmpty; + public class Tag implements ICommits, IAuthors, IIssues, Serializable { private static final long serialVersionUID = 2140208294219785889L; private final String annotation; @@ -14,6 +16,9 @@ public class Tag implements ICommits, IAuthors, IIssues, Serializable { private final List issues; private final List issueTypes; private final String name; + private final String tagTime; + private final Long tagTimeLong; + private final boolean hasTagTime; public Tag( String name, @@ -21,13 +26,18 @@ public Tag( List commits, List authors, List issues, - List issueTypes) { + List issueTypes, + String tagTime, + Long tagTimeLong) { this.commits = commits; this.authors = authors; this.issues = issues; this.name = name; this.annotation = annotation; this.issueTypes = issueTypes; + this.tagTime = tagTime; + this.tagTimeLong = tagTimeLong; + this.hasTagTime = !isNullOrEmpty(tagTime); } public String getAnnotation() { @@ -61,6 +71,18 @@ public String getName() { return this.name; } + public String getTagTime() { + return this.tagTime; + } + + public Long getTagTimeLong() { + return this.tagTimeLong; + } + + public boolean isHasTagTime() { + return this.hasTagTime; + } + @Override public String toString() { return "name: " + this.name; diff --git a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java index 4935be2a..22df6ac9 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java @@ -137,19 +137,23 @@ public String toString() { return "Repo: " + this.repository + "\n" + sb.toString(); } - private void addCommitToCurrentTag( + private boolean addCommitToCurrentTag( Map> commitsPerTagName, String currentTagName, RevCommit thisCommit) { GitCommit gitCommit = toGitCommit(thisCommit); + boolean newTagFound = false; if (!commitsPerTagName.containsKey(currentTagName)) { commitsPerTagName.put(currentTagName, new TreeSet()); + newTagFound = true; } Set gitCommitsInCurrentTag = commitsPerTagName.get(currentTagName); gitCommitsInCurrentTag.add(gitCommit); + return newTagFound; } private void addToTags( Map> commitsPerTag, String tagName, + Date tagTime, List addTo, Map annotatedTagPerTagName) { if (commitsPerTag.containsKey(tagName)) { @@ -160,7 +164,7 @@ private void addToTags( annotation = annotatedTagPerTagName.get(tagName).getFullMessage(); } - GitTag gitTag = new GitTag(tagName, annotation, newArrayList(gitCommits)); + GitTag gitTag = new GitTag(tagName, annotation, newArrayList(gitCommits), tagTime); addTo.add(gitTag); } } @@ -293,16 +297,17 @@ private List gitTags( * Why: Its what we are here for! =) */ Map> commitsPerTag = newHashMap(); + Map datePerTag = newHashMap(); - populateComitPerTag(from, to, tagPerCommitHash, tagPerCommitsHash, commitsPerTag, null); - populateComitPerTag(from, to, tagPerCommitHash, tagPerCommitsHash, commitsPerTag, untaggedName); + populateComitPerTag(from, to, tagPerCommitHash, tagPerCommitsHash, commitsPerTag, datePerTag, null); + populateComitPerTag(from, to, tagPerCommitHash, tagPerCommitsHash, commitsPerTag, datePerTag, untaggedName); List tags = newArrayList(); - addToTags(commitsPerTag, untaggedName, tags, annotatedTagPerTagName); + addToTags(commitsPerTag, untaggedName, null, tags, annotatedTagPerTagName); List tagCommitHashSortedByCommitTime = getTagCommitHashSortedByCommitTime(tagPerCommitHash.values()); for (Ref tag : tagCommitHashSortedByCommitTime) { - addToTags(commitsPerTag, tag.getName(), tags, annotatedTagPerTagName); + addToTags(commitsPerTag, tag.getName(), datePerTag.get(tag.getName()), tags, annotatedTagPerTagName); } return tags; } @@ -328,11 +333,12 @@ private void populateComitPerTag( Map tagPerCommitHash, Map tagPerCommitsHash, Map> commitsPerTag, + Map datePerTag, String startingTagName) throws Exception { Set moreWork = populateCommitPerTag( - from, to, commitsPerTag, tagPerCommitHash, tagPerCommitsHash, startingTagName); + from, to, commitsPerTag, tagPerCommitHash, tagPerCommitsHash, datePerTag, startingTagName); do { Set evenMoreWork = newTreeSet(); for (TraversalWork tw : newArrayList(moreWork)) { @@ -344,6 +350,7 @@ private void populateComitPerTag( commitsPerTag, tagPerCommitHash, tagPerCommitsHash, + datePerTag, tw.getCurrentTagName()); evenMoreWork.addAll(newWork); } @@ -358,6 +365,7 @@ private Set populateCommitPerTag( Map> commitsPerTagName, Map tagPerCommitHash, Map tagPerCommitsHash, + Map datePerTag, String currentTagName) throws Exception { String thisCommitHash = to.getName(); @@ -370,7 +378,9 @@ private Set populateCommitPerTag( currentTagName = getTagName(tagPerCommitHash, thisCommitHash); } if (currentTagName != null) { - addCommitToCurrentTag(commitsPerTagName, currentTagName, thisCommit); + if (addCommitToCurrentTag(commitsPerTagName, currentTagName, thisCommit)) { + datePerTag.put(currentTagName, new Date(thisCommit.getCommitTime() * 1000L)); + } noteThatTheCommitWasMapped(tagPerCommitsHash, currentTagName, thisCommitHash); } if (notFirstIncludedCommit(from, to)) { diff --git a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoDataHelper.java b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoDataHelper.java index 7221d798..e590287e 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoDataHelper.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoDataHelper.java @@ -32,7 +32,8 @@ public static GitRepoData removeCommitsWithoutIssue( new GitTag( gitTag.getName(), gitTag.findAnnotation().orNull(), - newArrayList(reducedCommitsInTag))); + newArrayList(reducedCommitsInTag), + gitTag.getTagTime())); } } diff --git a/src/main/java/se/bjurr/gitchangelog/internal/git/model/GitTag.java b/src/main/java/se/bjurr/gitchangelog/internal/git/model/GitTag.java index 2559da73..4afc0436 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/model/GitTag.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/model/GitTag.java @@ -5,6 +5,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; + +import java.util.Date; import java.util.List; import se.bjurr.gitchangelog.internal.model.interfaces.IGitCommitReferer; @@ -13,12 +15,14 @@ public class GitTag implements IGitCommitReferer { private final String annotation; private final List gitCommits; private final String name; + private final Date tagTime; - public GitTag(String name, String annotation, List gitCommits) { + public GitTag(String name, String annotation, List gitCommits, Date tagTime) { checkArgument(!gitCommits.isEmpty(), "No commits in " + name); this.name = checkNotNull(name, "name"); this.annotation = annotation; this.gitCommits = gitCommits; + this.tagTime = tagTime; } public Optional findAnnotation() { @@ -39,6 +43,10 @@ public String getName() { return this.name; } + public Date getTagTime() { + return this.tagTime; + } + @Override public String toString() { return "Tag: " + this.name + " Annotation: " + this.annotation + ", " + getGitCommit(); diff --git a/src/main/java/se/bjurr/gitchangelog/internal/model/Transformer.java b/src/main/java/se/bjurr/gitchangelog/internal/model/Transformer.java index 58a7fd4d..60b91e06 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/model/Transformer.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/model/Transformer.java @@ -139,7 +139,9 @@ public Tag apply(GitTag input) { commits, authors, issues, - issueTypes); + issueTypes, + input.getTagTime() != null ? format(input.getTagTime()) : "", + input.getTagTime() != null ? input.getTagTime().getTime() : -1); } private List reduceParsedIssuesToOnlyGitCommits( diff --git a/src/test/resources/assertions/testTagsCommits.md b/src/test/resources/assertions/testTagsCommits.md index 584821ec..9a36816c 100644 --- a/src/test/resources/assertions/testTagsCommits.md +++ b/src/test/resources/assertions/testTagsCommits.md @@ -40,14 +40,14 @@ Adding stuff with a jira Adding stuff with gh again -## test-lightweight-2 +## test-lightweight-2 (2016-02-15 16:30:35) ### Tomas Bjerre - 2016-02-15 16:30:35 [a9bd03b34b255ff](https://server/a9bd03b34b255ff) Adding cq stuff with CQ -## test-1.0 +## test-1.0 (2016-02-15 16:30:35) this is the tag for test-1.0 ### Tomas Bjerre - 2016-02-15 16:30:35 [d50a3e332f9fcba](https://server/d50a3e332f9fcba) diff --git a/src/test/resources/templates/testTagsCommits.mustache b/src/test/resources/templates/testTagsCommits.mustache index 4b44abee..5368b06d 100644 --- a/src/test/resources/templates/testTagsCommits.mustache +++ b/src/test/resources/templates/testTagsCommits.mustache @@ -3,7 +3,7 @@ Changelog of Git Changelog. {{#tags}} -## {{name}} +## {{name}}{{#hasTagTime}} ({{tagTime}}){{/hasTagTime}} {{annotation}} {{#commits}} ### {{authorName}} - {{commitTime}}