-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1aa5ff
commit 5aaeb90
Showing
33 changed files
with
1,046 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ language: java | |
jdk: | ||
- oraclejdk8 | ||
- oraclejdk7 | ||
- openjdk6 | ||
script: | ||
- ./gradlew build | ||
notifications: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Git Changelog changelog | ||
|
||
Changelog of Git Changelog. | ||
|
||
## 1.0 | ||
|
||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Git Release Notes [](https://travis-ci.org/tomasbjerre/git-release-notes) | ||
# Git Release Notes [](https://travis-ci.org/tomasbjerre/git-changelog) | ||
|
||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package se.bjurr.gitchangelog.api; | ||
|
||
import static com.google.common.base.Strings.isNullOrEmpty; | ||
import static com.google.common.base.Throwables.propagate; | ||
import static com.google.common.collect.Lists.newArrayList; | ||
import static com.google.common.io.Files.createParentDirs; | ||
import static com.google.common.io.Resources.getResource; | ||
import static se.bjurr.gitchangelog.internal.settings.Settings.fromFile; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
import org.eclipse.jgit.lib.ObjectId; | ||
|
||
import se.bjurr.gitchangelog.api.model.Changelog; | ||
import se.bjurr.gitchangelog.internal.git.GitRepo; | ||
import se.bjurr.gitchangelog.internal.git.model.GitCommit; | ||
import se.bjurr.gitchangelog.internal.git.model.GitTag; | ||
import se.bjurr.gitchangelog.internal.issues.IssueParser; | ||
import se.bjurr.gitchangelog.internal.model.ParsedIssue; | ||
import se.bjurr.gitchangelog.internal.model.Transformer; | ||
import se.bjurr.gitchangelog.internal.settings.CustomIssue; | ||
import se.bjurr.gitchangelog.internal.settings.Settings; | ||
|
||
import com.github.mustachejava.DefaultMustacheFactory; | ||
import com.github.mustachejava.Mustache; | ||
import com.github.mustachejava.MustacheFactory; | ||
import com.google.common.io.Files; | ||
|
||
public class GitChangelogApi { | ||
public static final String ZERO_COMMIT = "0000000000000000000000000000000000000000"; | ||
|
||
private Settings settings; | ||
|
||
private GitChangelogApi() { | ||
URL resource = null; | ||
try { | ||
resource = getResource("git-changelog-settings.json"); | ||
settings = fromFile(resource.toURI()); | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException("Cannot find default config in " + resource, e); | ||
} | ||
} | ||
|
||
public GitChangelogApi withSettings(String filePath) { | ||
settings = fromFile(new File(filePath).toURI()); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi fromRepo(String fromRepo) { | ||
settings.setFromRepo(fromRepo); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi fromRef(String fromBranch) { | ||
settings.setFromRef(fromBranch); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi toRef(String toBranch) { | ||
settings.setToRef(toBranch); | ||
return this; | ||
} | ||
|
||
public Changelog getChangelog() { | ||
GitRepo gitRepo = new GitRepo(new File(settings.getFromRepo())); | ||
ObjectId fromId = getId(gitRepo, settings.getFromRef(), settings.getFromCommit()); | ||
ObjectId toId = getId(gitRepo, settings.getToRef(), settings.getToCommit()); | ||
List<GitCommit> diff = gitRepo.getDiff(fromId, toId); | ||
List<GitTag> tags = gitRepo.getTags(); | ||
List<ParsedIssue> issues = new IssueParser(settings, diff).parseForIssues(); | ||
Transformer transformer = new Transformer(settings); | ||
return new Changelog(// | ||
transformer.toCommits(diff), // | ||
transformer.toTags(diff, tags, issues), // | ||
transformer.toAuthors(diff), // | ||
transformer.toIssues(diff, issues)); | ||
} | ||
|
||
private ObjectId getId(GitRepo gitRepo, String ref, String commit) { | ||
if (!isNullOrEmpty(ref)) { | ||
return gitRepo.getRef(ref); | ||
} | ||
if (!isNullOrEmpty(commit)) { | ||
return gitRepo.getCommit(commit); | ||
} | ||
throw new RuntimeException("Reference or commit must be defined!"); | ||
} | ||
|
||
public static GitChangelogApi gitChangelogApiBuilder() { | ||
return new GitChangelogApi(); | ||
} | ||
|
||
public GitChangelogApi fromCommit(String fromCommit) { | ||
settings.setFromCommit(fromCommit); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi toCommit(String toCommit) { | ||
settings.setToCommit(toCommit); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi untaggedName(String untaggedName) { | ||
settings.setUntaggedName(untaggedName); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi jiraIssuePattern(String jiraIssuePattern) { | ||
settings.setJiraIssuePattern(jiraIssuePattern); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi jiraServer(String jiraServer) { | ||
settings.setJiraServer(jiraServer); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi ignoreCommitsWithMesssage(String ignoreCommitsIfMessageMatches) { | ||
settings.setIgnoreCommitsIfMessageMatches(ignoreCommitsIfMessageMatches); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi githubIssuePattern(String githubIssuePattern) { | ||
settings.setGithubIssuePattern(githubIssuePattern); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi githubServer(String githubServer) { | ||
settings.setGithubServer(githubServer); | ||
return this; | ||
} | ||
|
||
public GitChangelogApi customIssues(String name, String pattern, String link) { | ||
settings.setCustomIssues(newArrayList(new CustomIssue(name, pattern, link))); | ||
return this; | ||
} | ||
|
||
public void toStdout() { | ||
String rendered = render(); | ||
System.out.println(rendered); | ||
} | ||
|
||
private String render() { | ||
MustacheFactory mf = new DefaultMustacheFactory(); | ||
Mustache mustache = mf.compile("git-changelog-template.mustache"); | ||
StringWriter writer = new StringWriter(); | ||
try { | ||
mustache.execute(writer, this.getChangelog()).flush(); | ||
} catch (IOException e) { | ||
propagate(e); | ||
} | ||
return writer.toString(); | ||
} | ||
|
||
public void toFile(String filePath) { | ||
try { | ||
File file = new File(filePath); | ||
createParentDirs(file); | ||
Files.write(render().getBytes(), file); | ||
} catch (IOException e) { | ||
propagate(e); | ||
} | ||
} | ||
|
||
public GitChangelogApi templatePath(String templatePath) { | ||
settings.setTemplatePath(templatePath); | ||
return this; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...urr/gitreleasenotes/api/model/Author.java → .../bjurr/gitchangelog/api/model/Author.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package se.bjurr.gitreleasenotes.api.model; | ||
package se.bjurr.gitchangelog.api.model; | ||
|
||
import java.util.List; | ||
|
||
|
6 changes: 3 additions & 3 deletions
6
...treleasenotes/api/model/ReleaseNotes.java → ...urr/gitchangelog/api/model/Changelog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/se/bjurr/gitchangelog/internal/common/GitPredicates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package se.bjurr.gitchangelog.internal.common; | ||
|
||
import static java.util.regex.Pattern.DOTALL; | ||
import static java.util.regex.Pattern.compile; | ||
import se.bjurr.gitchangelog.internal.git.model.GitCommit; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
public class GitPredicates { | ||
|
||
public static Predicate<GitCommit> ignoreCommits(final String ignoreCommitsIfMessageMatches) { | ||
return new Predicate<GitCommit>() { | ||
@Override | ||
public boolean apply(GitCommit gitCommit) { | ||
return !compile(ignoreCommitsIfMessageMatches, DOTALL).matcher(gitCommit.getMessage()).matches(); | ||
} | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.