Skip to content

Commit

Permalink
tag time added to tag model
Browse files Browse the repository at this point in the history
  • Loading branch information
Alik Kurdyukov committed Apr 11, 2017
1 parent 4f8d3e3 commit 8c58374
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ temp
.couscous
couscous.phar
.okhttpcache
.idea
classes
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Here is an example template.
Changelog of Git Changelog.
{{#tags}}
## {{name}}
## {{name}}{{#hasTagTime}} ({{tagTime}}){{/hasTagTime}}
{{#issues}}
{{#hasIssue}}
{{#hasLink}}
Expand Down Expand Up @@ -81,6 +81,8 @@ The template is supplied with a datastructure like:
* tags
- name
- annotation
- tagTime
- hasTagTime
* commits
- authorName
- authorEmailAddress
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/se/bjurr/gitchangelog/api/model/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,20 +16,28 @@ public class Tag implements ICommits, IAuthors, IIssues, Serializable {
private final List<Issue> issues;
private final List<IssueType> issueTypes;
private final String name;
private final String tagTime;
private final Long tagTimeLong;
private final boolean hasTagTime;

public Tag(
String name,
String annotation,
List<Commit> commits,
List<Author> authors,
List<Issue> issues,
List<IssueType> issueTypes) {
List<IssueType> 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() {
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 18 additions & 8 deletions src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,23 @@ public String toString() {
return "Repo: " + this.repository + "\n" + sb.toString();
}

private void addCommitToCurrentTag(
private boolean addCommitToCurrentTag(
Map<String, Set<GitCommit>> commitsPerTagName, String currentTagName, RevCommit thisCommit) {
GitCommit gitCommit = toGitCommit(thisCommit);
boolean newTagFound = false;
if (!commitsPerTagName.containsKey(currentTagName)) {
commitsPerTagName.put(currentTagName, new TreeSet<GitCommit>());
newTagFound = true;
}
Set<GitCommit> gitCommitsInCurrentTag = commitsPerTagName.get(currentTagName);
gitCommitsInCurrentTag.add(gitCommit);
return newTagFound;
}

private void addToTags(
Map<String, Set<GitCommit>> commitsPerTag,
String tagName,
Date tagTime,
List<GitTag> addTo,
Map<String, RevTag> annotatedTagPerTagName) {
if (commitsPerTag.containsKey(tagName)) {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -293,16 +297,17 @@ private List<GitTag> gitTags(
* Why: Its what we are here for! =)
*/
Map<String, Set<GitCommit>> commitsPerTag = newHashMap();
Map<String, Date> 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<GitTag> tags = newArrayList();
addToTags(commitsPerTag, untaggedName, tags, annotatedTagPerTagName);
addToTags(commitsPerTag, untaggedName, null, tags, annotatedTagPerTagName);
List<Ref> 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;
}
Expand All @@ -328,11 +333,12 @@ private void populateComitPerTag(
Map<String, Ref> tagPerCommitHash,
Map<String, String> tagPerCommitsHash,
Map<String, Set<GitCommit>> commitsPerTag,
Map<String, Date> datePerTag,
String startingTagName)
throws Exception {
Set<TraversalWork> moreWork =
populateCommitPerTag(
from, to, commitsPerTag, tagPerCommitHash, tagPerCommitsHash, startingTagName);
from, to, commitsPerTag, tagPerCommitHash, tagPerCommitsHash, datePerTag, startingTagName);
do {
Set<TraversalWork> evenMoreWork = newTreeSet();
for (TraversalWork tw : newArrayList(moreWork)) {
Expand All @@ -344,6 +350,7 @@ private void populateComitPerTag(
commitsPerTag,
tagPerCommitHash,
tagPerCommitsHash,
datePerTag,
tw.getCurrentTagName());
evenMoreWork.addAll(newWork);
}
Expand All @@ -358,6 +365,7 @@ private Set<TraversalWork> populateCommitPerTag(
Map<String, Set<GitCommit>> commitsPerTagName,
Map<String, Ref> tagPerCommitHash,
Map<String, String> tagPerCommitsHash,
Map<String, Date> datePerTag,
String currentTagName)
throws Exception {
String thisCommitHash = to.getName();
Expand All @@ -370,7 +378,9 @@ private Set<TraversalWork> 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static GitRepoData removeCommitsWithoutIssue(
new GitTag(
gitTag.getName(),
gitTag.findAnnotation().orNull(),
newArrayList(reducedCommitsInTag)));
newArrayList(reducedCommitsInTag),
gitTag.getTagTime()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -13,12 +15,14 @@ public class GitTag implements IGitCommitReferer {
private final String annotation;
private final List<GitCommit> gitCommits;
private final String name;
private final Date tagTime;

public GitTag(String name, String annotation, List<GitCommit> gitCommits) {
public GitTag(String name, String annotation, List<GitCommit> 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<String> findAnnotation() {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParsedIssue> reduceParsedIssuesToOnlyGitCommits(
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/assertions/testTagsCommits.md
Original file line number Diff line number Diff line change
Expand Up @@ -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&#10;
### Tomas Bjerre - 2016-02-15 16:30:35
[d50a3e332f9fcba](https://server/d50a3e332f9fcba)
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/templates/testTagsCommits.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Changelog of Git Changelog.

{{#tags}}
## {{name}}
## {{name}}{{#hasTagTime}} ({{tagTime}}){{/hasTagTime}}
{{annotation}}
{{#commits}}
### {{authorName}} - {{commitTime}}
Expand Down

0 comments on commit 8c58374

Please sign in to comment.