Skip to content

Commit

Permalink
Adding issueTypes in context #19
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Mar 19, 2016
1 parent bf07d5b commit f1c1dd6
Show file tree
Hide file tree
Showing 28 changed files with 391 additions and 72 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jdk:
git:
depth: 9999999
before_script:
- git fetch origin master:master
- git fetch origin test:test
- git pull
- git log --graph --full-history --all --color --date=short --pretty=format:"%Cred%x09%h %Creset%ad%Cgreen%d %Creset %s %C(bold)(%an)%Creset"
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Changelog of Git Changelog.

## Next release
## 1.36
### Other changes

**Fixing infinite loop in GitRepo**
Expand All @@ -14,7 +14,7 @@ Changelog of Git Changelog.
* at se.bjurr.gitchangelog.internal.git.GitRepo.toString(GitRepo.java:208)
* at se.bjurr.gitchangelog.internal.git.GitRepo.getRef(GitRepo.java:174)

[f5b6360a4ad9416](https://github.com/tomasbjerre/git-changelog-lib/commit/f5b6360a4ad9416) Tomas Bjerre *2016-03-15 20:25:52*
[a4a15094f367c31](https://github.com/tomasbjerre/git-changelog-lib/commit/a4a15094f367c31) Tomas Bjerre *2016-03-15 20:27:41*


## 1.35
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,35 @@ The template is supplied with a datastructure like:
- messageTitle (Only the first line of the message)
- messageBody (Everything, except the title)
* messageBodyItems (List of strings, the lines after the title)
* issueTypes
- name (Like GitHub, Jira, ...)
* issues
- name
- hasIssue
- issue
- hasLink
- link
- hasTitle
- title
* commits
- authorName
- authorEmailAddress
- 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
- 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 Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.jayway.jsonpath:json-path:2.1.0'
compile 'com.google.guava:guava:11.0.1'
compile 'com.google.guava:guava:16.0.1'
compile 'org.eclipse.jgit:org.eclipse.jgit:3.6.2.201501210735-r'
compile 'com.github.spullara.mustache.java:compiler:0.8.18'
testCompile 'junit:junit:4.12'
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import org.eclipse.jgit.lib.ObjectId;

import se.bjurr.gitchangelog.api.exceptions.GitChangelogRepositoryException;
import se.bjurr.gitchangelog.api.exceptions.GitChangelogIntegrationException;
import se.bjurr.gitchangelog.api.exceptions.GitChangelogRepositoryException;
import se.bjurr.gitchangelog.api.model.Changelog;
import se.bjurr.gitchangelog.api.model.Issue;
import se.bjurr.gitchangelog.internal.git.GitRepo;
Expand Down Expand Up @@ -278,8 +278,8 @@ public GitChangelogApi withGitHubIssuePattern(String gitHubIssuePattern) {
* Custom issues are added to support any kind of issue management, perhaps
* something that is internal to your project. See {@link SettingsIssue}.
*/
public GitChangelogApi withCustomIssue(String name, String pattern, String link) {
settings.addCustomIssue(new SettingsIssue(name, pattern, link));
public GitChangelogApi withCustomIssue(String name, String pattern, String link, String title) {
settings.addCustomIssue(new SettingsIssue(name, pattern, link, title));
return this;
}

Expand Down Expand Up @@ -364,7 +364,8 @@ private Changelog getChangelog(GitRepo gitRepo) throws GitChangelogRepositoryExc
transformer.toCommits(diff), //
transformer.toTags(tags), //
transformer.toAuthors(diff), //
transformer.toIssues(issues));
transformer.toIssues(issues),//
transformer.toIssueTypes(issues));
}

private String getTemplateContent() {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/se/bjurr/gitchangelog/api/model/Changelog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ public class Changelog implements ICommits, IAuthors, IIssues {
private final List<Tag> tags;
private final List<Author> authors;
private final List<Issue> issues;
private final List<IssueType> issueTypes;

public Changelog(List<Commit> commits, List<Tag> tags, List<Author> authors, List<Issue> issues) {
public Changelog(List<Commit> commits, List<Tag> tags, List<Author> authors, List<Issue> issues,
List<IssueType> issueTypes) {
this.commits = checkNotNull(commits, "commits");
this.tags = checkNotNull(tags, "tags");
this.authors = checkNotNull(authors, "authors");
this.issues = checkNotNull(issues, "issues");
this.issueTypes = checkNotNull(issueTypes, "issueTypes");
}

@Override
Expand All @@ -39,4 +42,8 @@ public List<Commit> getCommits() {
public List<Tag> getTags() {
return tags;
}

public List<IssueType> getIssueTypes() {
return issueTypes;
}
}
18 changes: 15 additions & 3 deletions src/main/java/se/bjurr/gitchangelog/api/model/Issue.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@
public class Issue implements ICommits, IAuthors {
private final List<Commit> commits;
private final List<Author> authors;
/**
* Like JIRA, or GitHub.
*/
private final String name;
private final boolean hasIssue;
/**
* Like the title of a Jira.
*/
private final String title;
private final boolean hasTitle;
/**
* Like the actual Jira, JIR-ABC.
*/
private final String issue;
private final boolean hasLink;
private final boolean hasIssue;
/**
* A link to the issue, http://.....
*/
private final String link;
private final boolean hasLink;

public Issue(List<Commit> commits, List<Author> authors, String name, String title, String issue, String link) {
checkState(!commits.isEmpty(), "commits");
Expand Down Expand Up @@ -74,6 +86,6 @@ public List<Commit> getCommits() {

@Override
public String toString() {
return "Issue: " + issue;
return "Issue: " + issue + " Title: " + title;
}
}
28 changes: 28 additions & 0 deletions src/main/java/se/bjurr/gitchangelog/api/model/IssueType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package se.bjurr.gitchangelog.api.model;

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

import java.util.List;

public class IssueType {
private final String name;
private final List<Issue> issues;

public IssueType(List<Issue> issues, String name) {
this.name = checkNotNull(name, "name");
this.issues = checkNotNull(issues, "issues");
}

public String getName() {
return name;
}

public List<Issue> getIssues() {
return issues;
}

@Override
public String toString() {
return "IssueType: " + name;
}
}
8 changes: 7 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 @@ -10,13 +10,15 @@ public class Tag implements ICommits, IAuthors, IIssues {
private final List<Commit> commits;
private final List<Author> authors;
private final List<Issue> issues;
private final List<IssueType> issueTypes;
private final String name;

public Tag(String name, List<Commit> commits, List<Author> authors, List<Issue> issues) {
public Tag(String name, List<Commit> commits, List<Author> authors, List<Issue> issues, List<IssueType> issueTypes) {
this.commits = commits;
this.authors = authors;
this.issues = issues;
this.name = name;
this.issueTypes = issueTypes;
}

@Override
Expand Down Expand Up @@ -46,4 +48,8 @@ public List<Commit> getCommits() {
public String toString() {
return "name: " + name;
}

public List<IssueType> getIssueTypes() {
return issueTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,6 @@ private RevCommit firstCommit() {

@Override
public String toString() {
return "First commit at: " + firstCommit().name() + " Repo: " + repository;
return "Repo: " + repository;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,37 @@ private void putGitHubIssue(Map<String, ParsedIssue> foundIssues, GitHubHelper g
GitHubIssue gitHubIssue = gitHubHelper.getIssueFromAll(matched).get();
foundIssues.put(matched, new ParsedIssue(//
issuePattern.getName(),//
gitHubIssue.getTitle(), //
matched,//
gitHubIssue.getLink()));
gitHubIssue.getLink(), //
gitHubIssue.getTitle()));
}

private void putJiraIssue(Map<String, ParsedIssue> foundIssues, JiraClient jiraClient, SettingsIssue issuePattern,
String matched) throws GitChangelogIntegrationException {
JiraIssue jiraIssue = jiraClient.getIssue(matched).get();
foundIssues.put(matched, new ParsedIssue(//
issuePattern.getName(),//
jiraIssue.getTitle(), //
matched,//
jiraIssue.getLink()));
jiraIssue.getLink(), //
jiraIssue.getTitle()));
}

private void putCustomIssue(Map<String, ParsedIssue> foundIssues, SettingsIssue issuePattern, Matcher matcher,
String matched) {
String link = issuePattern.getLink().or("") //
.replaceAll("\\$\\{PATTERN_GROUP\\}", matched);
for (int i = 0; i <= matcher.groupCount(); i++) {
link = link.replaceAll("\\$\\{PATTERN_GROUP_" + i + "\\}", firstNonNull(matcher.group(i), ""));
}
String link = render(issuePattern.getLink().or(""), matcher, matched);
String title = render(issuePattern.getTitle().or(""), matcher, matched);
foundIssues.put(matched, new ParsedIssue(//
issuePattern.getName(),//
matched,//
link));
link,//
title));
}

private String render(String string, Matcher matcher, String matched) {
string = string.replaceAll("\\$\\{PATTERN_GROUP\\}", matched);
for (int i = 0; i <= matcher.groupCount(); i++) {
string = string.replaceAll("\\$\\{PATTERN_GROUP_" + i + "\\}", firstNonNull(matcher.group(i), ""));
}
return string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ParsedIssue(String name, String issue, String link) {
this.link = link;
}

public ParsedIssue(String name, String title, String issue, String link) {
public ParsedIssue(String name, String issue, String link, String title) {
this.name = checkNotNull(name, "name");
this.title = emptyToNull(title);
this.issue = issue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.google.common.collect.Maps.newTreeMap;
import static com.google.common.collect.Multimaps.index;
import static java.util.TimeZone.getTimeZone;
import static java.util.regex.Pattern.compile;
import static se.bjurr.gitchangelog.internal.common.GitPredicates.ignoreCommits;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

import se.bjurr.gitchangelog.api.model.Author;
import se.bjurr.gitchangelog.api.model.Commit;
import se.bjurr.gitchangelog.api.model.Issue;
import se.bjurr.gitchangelog.api.model.IssueType;
import se.bjurr.gitchangelog.api.model.Tag;
import se.bjurr.gitchangelog.internal.git.model.GitCommit;
import se.bjurr.gitchangelog.internal.git.model.GitTag;
Expand Down Expand Up @@ -47,10 +51,10 @@ public Tag apply(GitTag input) {
List<GitCommit> gitCommits = input.getGitCommits();
List<Commit> commits = toCommits(gitCommits);
List<Author> authors = toAuthors(gitCommits);
List<ParsedIssue> parsedIssues;
parsedIssues = new IssueParser(settings, gitCommits).parseForIssues();
List<ParsedIssue> parsedIssues = new IssueParser(settings, gitCommits).parseForIssues();
List<Issue> issues = toIssues(parsedIssues);
return new Tag(toReadableTagName(input.getName()), commits, authors, issues);
List<IssueType> issueTypes = toIssueTypes(parsedIssues);
return new Tag(toReadableTagName(input.getName()), commits, authors, issues, issueTypes);
}
});

Expand Down Expand Up @@ -87,14 +91,23 @@ public Commit apply(GitCommit c) {
}

public List<Issue> toIssues(List<ParsedIssue> issues) {
Iterable<ParsedIssue> issuesWithCommits = filterWithCommits(issues);

return newArrayList(transform(issuesWithCommits, parsedIssueToIssue()));
}

private Iterable<ParsedIssue> filterWithCommits(List<ParsedIssue> issues) {
Iterable<ParsedIssue> issuesWithCommits = filter(issues, new Predicate<ParsedIssue>() {
@Override
public boolean apply(ParsedIssue input) {
return !toCommits(input.getGitCommits()).isEmpty();
}
});
return issuesWithCommits;
}

return newArrayList(transform(issuesWithCommits, new Function<ParsedIssue, Issue>() {
private Function<ParsedIssue, Issue> parsedIssueToIssue() {
return new Function<ParsedIssue, Issue>() {
@Override
public Issue apply(ParsedIssue input) {
List<GitCommit> gitCommits = input.getGitCommits();
Expand All @@ -106,7 +119,7 @@ public Issue apply(ParsedIssue input) {
input.getIssue(), //
input.getLink());
}
}));
};
}

private Commit toCommit(GitCommit gitCommit) {
Expand Down Expand Up @@ -166,4 +179,23 @@ public Author apply(String input) {
}
}));
}

public List<IssueType> toIssueTypes(List<ParsedIssue> issues) {
Map<String, List<Issue>> issuesPerName = newTreeMap();

for (ParsedIssue parsedIssue : filterWithCommits(issues)) {
if (!issuesPerName.containsKey(parsedIssue.getName())) {
issuesPerName.put(parsedIssue.getName(), new ArrayList<Issue>());
}
Issue transformedIssues = parsedIssueToIssue().apply(parsedIssue);
issuesPerName.get(parsedIssue.getName())//
.add(transformedIssues);
}

List<IssueType> issueTypes = newArrayList();
for (String name : issuesPerName.keySet()) {
issueTypes.add(new IssueType(issuesPerName.get(name), name));
}
return issueTypes;
}
}
Loading

0 comments on commit f1c1dd6

Please sign in to comment.