diff --git a/.travis.yml b/.travis.yml index 707e67a9..b18c52b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,8 @@ env: - secure: "f78upMWhPViLh2W9jLjkjikZgSJCd9LuJVZF227JFSLGV8+DC0YbHQi6pYmpejhTT9H1OTqXyQ5c16QEQzutx6O63iyWdvWtIHtuct66jWPUp1NL3EAlK9F4NdG/9sbdEcElgrQxEArjYB5w+UZ+1uJucc1oMqIWbWQ089tvdx1VYZYRdP3pdLOoqgAqi4/GOxj8vRO9lIY7kc9IhEDDAfzNrGV8/LKao9f1pEOI+XcVDMOovRcstkMJZ5kqAep7xZTURGScKE6dMm58IEPDQAfbbGxAaJTO1HiNhFt6u2n+Z/oXZS8zlD/mcTA2acE6Ip7AMplSrac3bkzhwULwVu1PeDhteS9cwhpwJ/B3dR5sDAA+U/4WkfDV5VyyWVn8Z7Jy5nzDyUrtZBiPCzUyKDEaKc0mlLjWJjGiboq3ACnn62CE+VWQz9J0vnjxrwwqLcZbAtPzbFn3myYNbrf2qHt7n9eL3l9c9mkzYCfC6hz1oqsa35cimL6NXzjbRPu8ruyZdDcOdPBlVcdQ/g8ZhTslo5SCi4yukGQ0NbdPF0bJ4JXmBT49KUGbPOrCqdzoe+or04uJ6KkbLsO+bSGtVcidMuUeeylhfUBMtZs8XBKB2o3WWpZKjCUlKDl/vfDmlP7G+1Bd6lR11F1Z5jmtPLBzKlURrAMPVSk4EwFLNeQ=" jdk: - oraclejdk8 - - oraclejdk7 - - openjdk7 +# - oraclejdk7 +# - openjdk7 git: depth: 9999999 before_script: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2baa3354..383ab7b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,27 @@ -# Git Changelog changelog +# Changelog -Changelog of Git Changelog. +Changelog for tomasbjerre git-changelog-lib. ## Next release +### GitHub [#49](https://github.com/tomasbjerre/git-changelog-lib/issues/49) Ability to grab the url from the git config. *enhancement* + +**Gathering repo provider information** + + * Getting ownerName and repoName from clone URL. + * Setting GitLab server and GitHub API from clone URL. + +[a78e4cdcbe3ae07](https://github.com/tomasbjerre/git-changelog-lib/commit/a78e4cdcbe3ae07) Tomas Bjerre *2017-07-23 18:42:04* + + +### Other changes + +**Cleaning** + + +[3c0bf2f7885bff3](https://github.com/tomasbjerre/git-changelog-lib/commit/3c0bf2f7885bff3) Tomas Bjerre *2017-07-16 05:55:55* + + +## 1.69 ### GitHub [#47](https://github.com/tomasbjerre/git-changelog-lib/pull/47) Add ignoreCommitsOlderThan date limiting *enhancement* **Adjustments after merge of** @@ -11,7 +30,7 @@ Changelog of Git Changelog. * Making ignoreCommits more effective. * Also cleaning up unrelated parts of the API. Use File instead of String to supply changelog file. Enabling write changelog to Writer. -[94ab68796f7d271](https://github.com/tomasbjerre/git-changelog-lib/commit/94ab68796f7d271) Tomas Bjerre *2017-07-07 20:03:46* +[121e65493ec764b](https://github.com/tomasbjerre/git-changelog-lib/commit/121e65493ec764b) Tomas Bjerre *2017-07-07 20:04:00* ### Other changes diff --git a/README.md b/README.md index e640724c..c2a9eebe 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,12 @@ This software can be used: Here is an example template. ``` -# Git Changelog changelog +# Changelog -Changelog of Git Changelog. +Changelog for {{ownerName}} {{repoName}}. {{#tags}} -## {{name}}{{#hasTagTime}} ({{tagTime}}){{/hasTagTime}} +## {{name}} {{#issues}} {{#hasIssue}} {{#hasLink}} @@ -51,7 +51,7 @@ Changelog of Git Changelog. * {{.}} {{/messageBodyItems}} -[{{hash}}](https://github.com/tomasbjerre/git-changelog-lib/commit/{{hash}}) {{authorName}} *{{commitTime}}* +[{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}} *{{commitTime}}* {{/commits}} @@ -65,8 +65,10 @@ There are also different variations [here](https://github.com/tomasbjerre/git-ch ## Supplied information -The template is supplied with a datastructure like: +The template is supplied with this context: ``` +- ownerName (Derived from the clone URL, for this repo it would be "tomasbjerre") +- repoName (Derived from the clone URL, for this repo it would be "git-changelog-lib") * commits - authorName - authorEmailAddress diff --git a/build.sh b/build.sh index 07794247..6fe2fad7 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,3 @@ #!/bin/bash +cp src/main/resources/git-changelog-template.mustache changelog.mustache ./gradlew clean build -i diff --git a/changelog.mustache b/changelog.mustache index 1b828067..3ec8c8fa 100644 --- a/changelog.mustache +++ b/changelog.mustache @@ -1,6 +1,6 @@ -# Git Changelog changelog +# Changelog -Changelog of Git Changelog. +Changelog for {{ownerName}} {{repoName}}. {{#tags}} ## {{name}} @@ -24,7 +24,7 @@ Changelog of Git Changelog. * {{.}} {{/messageBodyItems}} -[{{hash}}](https://github.com/tomasbjerre/git-changelog-lib/commit/{{hash}}) {{authorName}} *{{commitTime}}* +[{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}} *{{commitTime}}* {{/commits}} diff --git a/src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java b/src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java index f28252a0..e2b0b5f4 100644 --- a/src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java +++ b/src/main/java/se/bjurr/gitchangelog/api/GitChangelogApi.java @@ -425,6 +425,15 @@ private Changelog getChangelog(GitRepo gitRepo) throws GitChangelogRepositoryExc toId, this.settings.getUntaggedName(), this.settings.getIgnoreTagsIfNameMatches()); + + if (!settings.getGitHubApi().isPresent()) { + settings.setGitHubApi(gitRepoData.findGitHubApi().orNull()); + } + if (!settings.getGitLabServer().isPresent()) { + settings.setGitLabServer(gitRepoData.findGitLabServer().orNull()); + settings.setGitLabProjectName(gitRepoData.findOwnerName().orNull()); + } + List diff = gitRepoData.getGitCommits(); List issues = new IssueParser(this.settings, diff).parseForIssues(); if (this.settings.ignoreCommitsWithoutIssue()) { @@ -438,7 +447,9 @@ private Changelog getChangelog(GitRepo gitRepo) throws GitChangelogRepositoryExc transformer.toTags(tags, issues), // transformer.toAuthors(diff), // transformer.toIssues(issues), // - transformer.toIssueTypes(issues)); + transformer.toIssueTypes(issues), // + gitRepoData.findOwnerName().orNull(), // + gitRepoData.findRepoName().orNull()); } private Optional getId(GitRepo gitRepo, Optional ref, Optional commit) diff --git a/src/main/java/se/bjurr/gitchangelog/api/model/Changelog.java b/src/main/java/se/bjurr/gitchangelog/api/model/Changelog.java index 0452d333..e82f801b 100644 --- a/src/main/java/se/bjurr/gitchangelog/api/model/Changelog.java +++ b/src/main/java/se/bjurr/gitchangelog/api/model/Changelog.java @@ -15,18 +15,24 @@ public class Changelog implements ICommits, IAuthors, IIssues, Serializable { private final List authors; private final List issues; private final List issueTypes; + private final String ownerName; + private final String repoName; public Changelog( List commits, List tags, List authors, List issues, - List issueTypes) { + List issueTypes, + String ownerName, + String repoName) { 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"); + this.ownerName = ownerName; + this.repoName = repoName; } @Override @@ -44,6 +50,14 @@ public List getCommits() { return commits; } + public String getOwnerName() { + return ownerName; + } + + public String getRepoName() { + return repoName; + } + public List getTags() { return tags; } 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 2f944423..75b27c58 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepo.java @@ -103,7 +103,9 @@ public GitRepoData getGitRepoData( ObjectId from, ObjectId to, String untaggedName, Optional ignoreTagsIfNameMatches) throws GitChangelogRepositoryException { try { - return new GitRepoData(gitTags(from, to, untaggedName, ignoreTagsIfNameMatches)); + String originUrl = this.git.getRepository().getConfig().getString("remote", "origin", "url"); + List gitTags = gitTags(from, to, untaggedName, ignoreTagsIfNameMatches); + return new GitRepoData(originUrl, gitTags); } catch (Exception e) { throw new GitChangelogRepositoryException(toString(), e); } diff --git a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoData.java b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoData.java index 272bbac0..5ba2abc3 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoData.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoData.java @@ -1,8 +1,10 @@ package se.bjurr.gitchangelog.internal.git; +import static com.google.common.base.Optional.absent; import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Sets.newTreeSet; +import com.google.common.base.Optional; import java.util.List; import java.util.Set; import se.bjurr.gitchangelog.internal.git.model.GitCommit; @@ -11,16 +13,22 @@ public class GitRepoData { private final List gitCommits; private final List gitTags; + private final String originCloneUrl; - public GitRepoData(List gitTags) { + public GitRepoData(String originCloneUrl, List gitTags) { Set gitCommitsSorted = newTreeSet(); for (GitTag gitTag : gitTags) { gitCommitsSorted.addAll(gitTag.getGitCommits()); } + this.originCloneUrl = originCloneUrl; this.gitCommits = newArrayList(gitCommitsSorted); this.gitTags = gitTags; } + public String getOriginCloneUrl() { + return originCloneUrl; + } + public List getGitCommits() { return gitCommits; } @@ -28,4 +36,44 @@ public List getGitCommits() { public List getGitTags() { return gitTags; } + + public Optional findGitHubApi() { + if (originCloneUrl == null) { + return absent(); + } + if (!originCloneUrl.contains("github.com")) { + return absent(); + } + return Optional.of( + "https://api.github.com/repos/" + findOwnerName().orNull() + "/" + findRepoName().orNull()); + } + + public Optional findGitLabServer() { + if (originCloneUrl == null) { + return absent(); + } + if (!originCloneUrl.contains("gitlab.com")) { + return absent(); + } + return Optional.of("https://gitlab.com/"); + } + + public Optional findOwnerName() { + return repoUrlPartFromEnd(2); + } + + public Optional findRepoName() { + return repoUrlPartFromEnd(1); + } + + private Optional repoUrlPartFromEnd(int i) { + if (originCloneUrl == null) { + return absent(); + } + String[] parts = this.originCloneUrl.split("[/:\\.]"); + if (parts.length > i) { + return Optional.of(parts[parts.length - i - 1]); + } + return absent(); + } } 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 e590287e..e370b161 100644 --- a/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoDataHelper.java +++ b/src/main/java/se/bjurr/gitchangelog/internal/git/GitRepoDataHelper.java @@ -37,7 +37,8 @@ public static GitRepoData removeCommitsWithoutIssue( } } - return new GitRepoData(reducedGitTags); + String originCloneUrl = gitRepoData.getOriginCloneUrl(); + return new GitRepoData(originCloneUrl, reducedGitTags); } private GitRepoDataHelper() {} diff --git a/src/main/resources/git-changelog-template.mustache b/src/main/resources/git-changelog-template.mustache index c7986581..3ec8c8fa 100644 --- a/src/main/resources/git-changelog-template.mustache +++ b/src/main/resources/git-changelog-template.mustache @@ -1,19 +1,32 @@ -# Git Changelog changelog +# Changelog -Changelog of Git Changelog. +Changelog for {{ownerName}} {{repoName}}. {{#tags}} ## {{name}} {{#issues}} -### {{name}} {{issue}} - {{#authors}} -* {{authorName}} - {{#commits}} -{{commitTime}} -{{{message}}} + {{#hasIssue}} + {{#hasLink}} +### {{name}} [{{issue}}]({{link}}) {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}} + {{/hasLink}} + {{^hasLink}} +### {{name}} {{issue}} {{title}} {{#hasIssueType}} *{{issueType}}* {{/hasIssueType}} {{#hasLabels}} {{#labels}} *{{.}}* {{/labels}} {{/hasLabels}} + {{/hasLink}} + {{/hasIssue}} + {{^hasIssue}} +### {{name}} + {{/hasIssue}} - {{/commits}} + {{#commits}} +**{{{messageTitle}}}** + +{{#messageBodyItems}} + * {{.}} +{{/messageBodyItems}} + +[{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}) {{authorName}} *{{commitTime}}* + + {{/commits}} - {{/authors}} {{/issues}} -{{/tags}} \ No newline at end of file +{{/tags}} diff --git a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java index e08ee506..10859fca 100644 --- a/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java +++ b/src/test/java/se/bjurr/gitchangelog/api/GitChangelogApiTest.java @@ -148,6 +148,8 @@ public void testThatCommitsWithoutIssueCanBeIgnoredTagsIssuesCommits() throws Ex gitChangelogApiBuilder() // .withFromCommit(ZERO_COMMIT) // .withToRef("test") // + .withGitHubIssuePattern("nooo") // + .withGitLabIssuePattern("nooo") // .withCustomIssue("JIRA", "JIR-[0-9]*", "http://${PATTERN_GROUP}", "${PATTERN_GROUP}") // .withIgnoreCommitsWithoutIssue(true) // .withTemplatePath(templatePath); diff --git a/src/test/java/se/bjurr/gitchangelog/internal/git/GitRepoDataTest.java b/src/test/java/se/bjurr/gitchangelog/internal/git/GitRepoDataTest.java new file mode 100644 index 00000000..b8846175 --- /dev/null +++ b/src/test/java/se/bjurr/gitchangelog/internal/git/GitRepoDataTest.java @@ -0,0 +1,62 @@ +package se.bjurr.gitchangelog.internal.git; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import se.bjurr.gitchangelog.internal.git.model.GitTag; + +public class GitRepoDataTest { + + public GitRepoData newGitRepoData(String originUrl) { + List gitTags = new ArrayList<>(); + return new GitRepoData(originUrl, gitTags); + } + + @Test + public void testGitHubRepo() { + GitRepoData sut = newGitRepoData("git@github.com:tomasbjerre/git-changelog-lib.git"); + + assertThat(sut.findOwnerName().orNull()) // + .isEqualTo("tomasbjerre"); + assertThat(sut.findRepoName().orNull()) // + .isEqualTo("git-changelog-lib"); + + assertThat(sut.findGitHubApi().orNull()) // + .isEqualTo("https://api.github.com/repos/tomasbjerre/git-changelog-lib"); + assertThat(sut.findGitLabServer().orNull()) // + .isEqualTo(null); + } + + @Test + public void testGitBitbucketRepo() { + GitRepoData sut = + newGitRepoData("https://tomasbjerre@bitbucket.org/ljohansson/grunt-connect-apimock.git"); + + assertThat(sut.findOwnerName().orNull()) // + .isEqualTo("ljohansson"); + assertThat(sut.findRepoName().orNull()) // + .isEqualTo("grunt-connect-apimock"); + + assertThat(sut.findGitHubApi().orNull()) // + .isEqualTo(null); + assertThat(sut.findGitLabServer().orNull()) // + .isEqualTo(null); + } + + @Test + public void testGitLabRepo() { + GitRepoData sut = newGitRepoData("http://root@gitlab.com/root/violations-test.git"); + + assertThat(sut.findOwnerName().orNull()) // + .isEqualTo("root"); + assertThat(sut.findRepoName().orNull()) // + .isEqualTo("violations-test"); + + assertThat(sut.findGitHubApi().orNull()) // + .isEqualTo(null); + assertThat(sut.findGitLabServer().orNull()) // + .isEqualTo("https://gitlab.com/"); + } +}