Git Changelog Lib
This is a library that can:
- Generate a changelog, or releasenotes, from a GIT repository.
- Determine next version, based on format of commits since last release.
It is fully configurable with a Mustache (Handlebars) template filled with a context of placeholders and helpers.
The changelog can:
- Be stored to file, like
CHANGELOG.md
. There are some templates used for testing available here. - Or, just rendered to a
String
.
It can integrate with Jira, Redmine, GitLab and/or GitHub to retrieve the title of issues.
Usage
This software can be used:
- With a Gradle plugin.
- With a Maven plugin.
- With a Jenkins plugin.
- From command line.
- From Docker.
- As a library Maven Central.
There are examples of different templates in the code that are used for testing.
Template - Simple
Here is an example template.
Template - Conventional
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.
Partials
You can use partials in your templates.
changelog.hbs
commit.partial
This is configured like:
gitChangelogApi
.withTemplateBaseDir("...")
.withTemplateSuffix(".partial"); //Optional, defaults to ".partial"
Helpers
Some helpers are implemented in this library. And users can also add more helpers as described in Handlebars.
ifReleaseTag <Tag>
Conditional, renders a block if given Tag
matches 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
.
ifContainsIssueTypeOtherThan <List<Issue>>
Conditional, renders a block if given List<Issue>
contains issues that don't match the given type
.
ifContainsIssueLabel <List<Issue>> label="<value>"
Conditional, renders a block if given List<Issue>
contains given label
.
ifContainsIssueLabelOtherThan <List<Issue>>
Conditional, renders a block if given List<Issue>
contains labels that don't match the given label
.
ifIssueLabel <label> label="<value>"
Conditional, renders a block if given label
matches the given value
.
ifContainsType <List<Commit>>
Conditional, renders a block if given List<Commits>
contains given type
.
ifContainsTypeOtherThan <List<Commit>>
Conditional, renders a block if given List<Commits>
contains commits that don't match the given type
.
ifContainsBreaking <List<Commit>>
Conditional, renders a block if given List<Commits>
contains breaking
changes.
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
.
ifIssueTypeOtherThan <Issue> type="<type>"
Conditional, renders a block if given Issue
is of type
.
ifCommitType <Commit> type="<type>"
Conditional, renders a block if given Commit
is of type
.
ifCommitTypeOtherThan <Commit> type="<type>"
Conditional, renders a block if given Commit
is of type
.
ifCommitBreaking <Commit>
Conditional, renders a block if given Commit
is breaking
.
ifCommitScope <Commit> scope="utils"
Conditional, renders a block if given Commit
has scope
.
ifCommitHasFooters <Commit>
Conditional, renders a block if given Commit
has footers
.
ifCommitHasParagraphs <Commit>
Conditional, renders a block if given Commit
has paragraphs
.
eachCommitScope <Commit>
Renders block for each scope
in Commit
.
eachCommitRefs <Commit>
Renders block for each refs
in Commit
.
eachCommitFixes <Commit>
Renders block for each fixes
in Commit
.
eachCommitParagraph <Commit>
Renders block for each paragraph
in Commit
.
eachCommitFooter <Commit>
Renders block for each footer
in Commit
.
ifFooterHasValue <Footer>
Conditional, renders a block if given Footer
has value
.
ifEquals <a> <b>
Conditional, renders a block if a
equals b
.
ifMatches <a> <b>
Conditional, renders a block if a
matches regexp b
.
subString <a> <b> <c>
Works just like Java substring.
Context
The template is supplied with this context of prepopulated mustache/handlebars variables:
Click here to show context
(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, [email protected]])
* 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)
Library
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).