This is a library that can:
It is fully configurable with a Mustache (Handlebars) template filled with a context of placeholders and helpers.
The changelog can:
CHANGELOG.md
. There are some templates used for testing available here.String
.It can integrate with Jira, Redmine, GitLab and/or GitHub to retrieve the title of issues.
Version | Java Version |
---|---|
version < 2.0.0 | 8 |
2.0.0 <= version < 2.2.0 | 11 |
2.2.0 <= version | 17 |
This software can be used with:
There are examples of different templates in the code that are used for testing.
Here is an example template.
# Changelog
Changelog for .
##
### []() ** **
### ** **
###
**}**
*
[](https://github.com///commit/) **
If you are using conventional commits:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
You can use built in helpers to produce a nice changelog. You can add your own helpers (using Javascript or Java) as described here.
## [](https://gitlab.com/html-validate/html-validate/compare/) ()
### Breaking changes
- **** } ([](https://github.com///commit/))
### Features
- **** } ([](https://github.com///commit/))
### Bug Fixes
- **** } ([](https://github.com///commit/))
You can use partials in your templates.
changelog.hbs
commit.partial
## -
[](https://server/)
}
This is configured like:
gitChangelogApi
.withTemplateBaseDir("...")
.withTemplateSuffix(".partial"); //Optional, defaults to ".partial"
Some helpers are implemented in this library. And users can also add more helpers as described in Handlebars. If you add your own helpers, using Javascript, you will need to add a scriptengine like Nashorn to your classpath.
eachUrlPart <Changelog>
Loop each part of the URL.
:
ifReleaseTag <Tag>
Conditional, renders a block if given Tag
matches release-tag.
"" is a release tag
tagDate <Tag>
Renders date of Tag
on format YYYY-MM-DD
.
ifContainsIssueType <List<Issue>>
Conditional, renders a block if given List<Issue>
contains given type
.
issues contains bugs
ifContainsIssueTypeOtherThan <List<Issue>>
Conditional, renders a block if given List<Issue>
contains issues that don’t match the given type
.
commits contains other types than fix
ifContainsIssueLabel <List<Issue>> label="<value>"
Conditional, renders a block if given List<Issue>
contains given label
.
content here
ifContainsIssueLabelOtherThan <List<Issue>>
Conditional, renders a block if given List<Issue>
contains labels that don’t match the given label
.
content here
ifIssueLabel <label> label="<value>"
Conditional, renders a block if given label
matches the given value
.
Found a enhancement
ifContainsType <List<Commit>>
Conditional, renders a block if given List<Commits>
contains given type
.
commits contains fixes
ifContainsScope <List<Commit>>
Conditional, renders a block if given List<Commits>
contains given scope
.
commits contains deps
ifContainsTypeAndScope <List<Commit>>
Conditional, renders a block if given List<Commits>
contains given type
and scope
.
commits contains chore with deps
ifContainsTypeOtherThan <List<Commit>>
Conditional, renders a block if given List<Commits>
contains commits that don’t match the given type
.
commits contains other types than fix
ifContainsBreaking <List<Commit>>
Conditional, renders a block if given List<Commits>
contains breaking
changes.
commits contains fixes
commitDate <Commit>
Renders date of Commit
on format YYYY-MM-DD
.
commitDescription <Commit>
Renders description of Commit
.
revertedCommit <Commit>
Renders reverted commit refered to by Commit
.
ifIssueType <Issue> type="<type>"
Conditional, renders a block if given Issue
is of type
.
is type fix
ifIssueTypeOtherThan <Issue> type="<type>"
Conditional, renders a block if given Issue
is of type
.
is not type fix
ifCommitType <Commit> type="<type>"
Conditional, renders a block if given Commit
is of type
.
is type fix
ifCommitTypeOtherThan <Commit> type="<type>"
Conditional, renders a block if given Commit
is of type
.
is not type fix
ifCommitBreaking <Commit>
Conditional, renders a block if given Commit
is breaking
.
is breaking
ifCommitScope <Commit> scope="utils"
Conditional, renders a block if given Commit
has scope
.
is scope utils
ifCommitHasFooters <Commit>
Conditional, renders a block if given Commit
has footers
.
has footers
ifCommitHasParagraphs <Commit>
Conditional, renders a block if given Commit
has paragraphs
.
has paragraphs
eachCommitScope <Commit>
Renders block for each scope
in Commit
.
scope:
eachCommitRefs <Commit>
Renders block for each refs
in Commit
.
references issue:
eachCommitFixes <Commit>
Renders block for each fixes
in Commit
.
fixes issue:
eachCommitParagraph <Commit>
Renders block for each paragraph
in Commit
.
eachCommitFooter <Commit>
Renders block for each footer
in Commit
.
Optional tokenMatching
regex parameter filters footer tokens.
ifFooterHasValue <Footer>
Conditional, renders a block if given Footer
has value
.
}
ifEquals <a> <b>
Conditional, renders a block if a
equals b
.
Unreleased ? ja nej
ifMatches <a> <b>
Conditional, renders a block if a
matches regexp b
.
fixes : "" and number
subString <a> <b> <c>
Works just like Java substring.
fixes : "" and number
The template is supplied with this context of prepopulated mustache/handlebars variables:
``` (ownerName, repoName, urlParts - derived from the clone URL, git remote origin MUST BE SET) - ownerName (for this repo it would be "tomasbjerre") - repoName (for this repo it would be "git-changelog-lib") - urlParts (for this repo it would be [git-changelog-lib, tomasbjerre, git@github.com]) * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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) * tags - name - annotation - tagTime - hasTagTime * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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 - authorEmail * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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) * issueTypes - name (Like GitHub, GitLab, Jira, ...) * issues - name - hasIssue - issue - hasLink - link - hasTitle - title - hasDescription - description - hasType - type - isJira - isGitHub - isGitLab - isCustom - isNoIssue - hasLabels - labels - hasLinkedIssues - linkedIssues - hasAdditionalFields - additionalFields * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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 - authorEmail * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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 - issue - hasLink - link - hasTitle - title - hasDescription - description - hasType - type - isJira - isGitHub - isGitLab - isCustom - isNoIssue - hasLabels - labels - hasLinkedIssues - linkedIssues - hasAdditionalFields - additionalFields * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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 - authorEmail * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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 - authorEmail * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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 - issue - hasLink - link - hasTitle - title - hasDescription - description - hasType - type - isJira - isGitHub - isGitLab - isCustom - isNoIssue - hasLabels - labels - hasLinkedIssues - linkedIssues - hasAdditionalFields - additionalFields * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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 - authorEmail * commits - authorName - authorEmailAddress - commitTime - hash - hashFull - merge (True if this is a merge-commit) - 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) ```
It has a builder for creating the changelog.
gitChangelogApiBuilder()
.withFromCommit(ZERO_COMMIT)
.withToRef("refs/heads/master")
.withTemplatePath("changelog.mustache")
.render();
It can be used to calculate next version number, based on commits:
def nextVersion = gitChangelogApiBuilder()
.withSemanticMajorVersionPattern("^[Bb]reaking")
.withSemanticMinorVersionPattern("[Ff]eature")
.getNextSemanticVersion();
println "Next version:" + nextVersion.toString();
println " Major:" + nextVersion.getMajor();
println " Minor:" + nextVersion.getMinor();
println " Patch:" + nextVersion.getPatch();
Settings can be supplied with the build or from a JSON config (documented here).