Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Nov 14, 2015
1 parent a1aa5ff commit 5aaeb90
Show file tree
Hide file tree
Showing 33 changed files with 1,046 additions and 497 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: java
jdk:
- oraclejdk8
- oraclejdk7
- openjdk6
script:
- ./gradlew build
notifications:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Git Release Notes [![Build Status](https://travis-ci.org/tomasbjerre/git-release-notes.svg?branch=master)](https://travis-ci.org/tomasbjerre/git-release-notes)
# Git Release Notes [![Build Status](https://travis-ci.org/tomasbjerre/git-changelog.svg?branch=master)](https://travis-ci.org/tomasbjerre/git-changelog)

...
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ apply plugin: 'net.researchgate.release'

group = 'se.bjurr.gitreleasenotes'

mainClassName = 'se.bjurr.gitreleasenotes.main.Main'
mainClassName = 'se.bjurr.gitchangelog.main.Main'

sourceCompatibility = 1.8
targetCompatibility = 1.6
sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
mavenLocal()
Expand Down
174 changes: 174 additions & 0 deletions src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java
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;
}
}
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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package se.bjurr.gitreleasenotes.api.model;
package se.bjurr.gitchangelog.api.model;

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

import java.util.List;

public class ReleaseNotes {
public class Changelog {
private final List<Commit> commits;
private final List<Tag> tags;
private final List<Author> authors;
private final List<Issue> issues;

public ReleaseNotes(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) {
this.commits = checkNotNull(commits, "commits");
this.tags = checkNotNull(tags, "tags");
this.authors = checkNotNull(authors, "authors");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package se.bjurr.gitreleasenotes.api.model;
package se.bjurr.gitchangelog.api.model;

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

import java.util.Date;

public class Commit {
private final String authorName;
private final String authorEmailAddress;
private final Date commitTime;
private final String commitTime;
private final String message;
private final String hash;

public Commit(String authorName, String authorEmailAddress, Date commitTime, String message, String hash) {
public Commit(String authorName, String authorEmailAddress, String commitTime, String message, String hash) {
this.authorName = checkNotNull(authorName, "authorName");
this.authorEmailAddress = checkNotNull(authorEmailAddress, "authorEmailAddress");
this.message = checkNotNull(message, "message");
this.message = checkNotNull(message, "message").trim();
this.commitTime = checkNotNull(commitTime, "commitTime");
this.hash = checkNotNull(hash, "hash");
}
Expand All @@ -31,7 +29,7 @@ public String getAuthorName() {
return authorName;
}

public Date getCommitTime() {
public String getCommitTime() {
return commitTime;
}

Expand Down
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 static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.nullToEmpty;
Expand All @@ -7,19 +7,19 @@

public class Issue {
private final String name;
private final String description;
private final String link;
private final List<Commit> commits;
private final List<Author> authors;

public Issue(List<Commit> commits, List<Author> authors, String name, String description) {
public Issue(List<Commit> commits, List<Author> authors, String name, String link) {
this.commits = checkNotNull(commits, "commits");
this.authors = checkNotNull(authors, "authors");
this.name = checkNotNull(name, "name");
this.description = nullToEmpty(description);
this.link = nullToEmpty(link);
}

public String getDescription() {
return description;
public String getLink() {
return link;
}

public String getName() {
Expand Down
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 static com.google.common.base.Preconditions.checkArgument;

Expand All @@ -13,7 +13,6 @@ public class Tag {
public Tag(String name, List<Commit> commits, List<Author> authors, List<Issue> issues) {
checkArgument(!commits.isEmpty(), "commits is empty!");
checkArgument(!authors.isEmpty(), "authors is empty!");
checkArgument(!issues.isEmpty(), "issues is empty!");
this.commits = commits;
this.authors = authors;
this.issues = issues;
Expand Down
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();
}
};
}

}
Loading

0 comments on commit 5aaeb90

Please # to comment.