- Notifications
You must be signed in to change notification settings - Fork95
Generate changelog, and/or next version, with, or without, conventional commits from a GIT repository
License
tomasbjerre/git-changelog-lib
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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 aMustache (Handlebars) template filled with acontext of placeholders andhelpers.
The changelog can:
- Be stored to file, like
CHANGELOG.md. There are some templates used for testing availablehere. - Or, just rendered to a
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:
- AGradle plugin.
- AMaven plugin.
- AJenkins plugin.
- Acommand line tool.
- ADocker image.
- AGitHub Action
- Alibrary.
There are examples of different templatesin the code that are used for testing.
Here is an example template.
# ChangelogChangelog for{{ownerName}}{{repoName}}.{{#tags}}##{{name}}{{#issues}}{{#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}}**{{{messageTitle}}}**{{#messageBodyItems}} *{{.}}{{/messageBodyItems}}[{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}}){{authorName}} *{{commitTime}}*{{/commits}}{{/issues}}{{/tags}}
If you are usingconventional commits:
<type>[optional scope]:<description>[optional body][optional footer(s)]
You can use built inhelpers to produce a nice changelog. You can add your own helpers (using Javascript or Java) as describedhere.
{{#tags}}{{#ifReleaseTag.}}## [{{name}}](https://gitlab.com/html-validate/html-validate/compare/{{name}}) ({{tagDate .}}){{#ifContainsBreakingcommits}} ### Breaking changes{{#commits}}{{#ifCommitBreaking.}} -{{#eachCommitScope.}} **{{.}}**{{/eachCommitScope}}{{{commitDescription .}}} ([{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}})){{/ifCommitBreaking}}{{/commits}}{{/ifContainsBreaking}}{{#ifContainsTypecommitstype='feat'}} ### Features{{#commits}}{{#ifCommitType.type='feat'}} -{{#eachCommitScope.}} **{{.}}**{{/eachCommitScope}}{{{commitDescription .}}} ([{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}})){{/ifCommitType}}{{/commits}}{{/ifContainsType}}{{#ifContainsTypecommitstype='fix'}} ### Bug Fixes{{#commits}}{{#ifCommitType.type='fix'}} -{{#eachCommitScope.}} **{{.}}**{{/eachCommitScope}}{{{commitDescription .}}} ([{{hash}}](https://github.com/{{ownerName}}/{{repoName}}/commit/{{hash}})){{/ifCommitType}}{{/commits}}{{/ifContainsType}}{{/ifReleaseTag}}{{/tags}}
You can usepartials in your templates.
changelog.hbs
{{#commits}}{{>commit}}{{/commits}}
commit.partial
##{{authorName}} -{{commitTime}}[{{hashFull}}](https://server/{{hash}}){{{message}}}
This is configured like:
gitChangelogApi .withTemplateBaseDir("...") .withTemplateSuffix(".partial");//Optional, defaults to ".partial"
Somehelpers are implemented in this library. And users can also add more helpers as described inHandlebars. If you add your own helpers, using Javascript, you will need to add a scriptengine likeNashorn to your classpath.
Loop each part of the URL.
https://gitlab.com/{{#eachUrlPart.}}{{#if@first}}{{else}}{{.}}/{{/if}}{{/eachUrlPart}}
Conditional, renders a block if givenTag matches release-tag.
{{#tags}}{{#ifReleaseTag.}} "{{.}}" is a release tag{{/ifReleaseTag}}{{/tags}}
Renders date ofTag on formatYYYY-MM-DD.
{{#tags}}{{tagDate .}}{{/tags}}
Conditional, renders a block if givenList<Issue> contains giventype.
{{#ifContainsIssueTypeissuestype="Bug"}} issues contains bugs{{/ifContainsIssueType}}
Conditional, renders a block if givenList<Issue> contains issues that don't match the giventype.
{{#ifContainsIssueTypeOtherThanissuestype="fix"}} commits contains other types than fix{{/ifContainsIssueTypeOtherThan}}
Conditional, renders a block if givenList<Issue> contains givenlabel.
{{#ifContainsIssueLabelissueslabel='enhancement'}} content here{{/ifContainsIssueLabel}}
Conditional, renders a block if givenList<Issue> contains labels that don't match the givenlabel.
{{#ifContainsIssueLabelOtherThanissueslabel='enhancement'}} content here{{/ifContainsIssueLabel}}
Conditional, renders a block if givenlabel matches the givenvalue.
{{#ifIssueLabel.label='enhancement'}} Found a enhancement{{/ifIssueLabel}}
Conditional, renders a block if givenList<Commits> contains giventype.
{{#ifContainsTypecommitstype="fix"}} commits contains fixes{{/ifContainsType}}
Conditional, renders a block if givenList<Commits> contains givenscope.
{{#ifContainsScopecommitsscope="deps"}} commits contains deps{{/ifContainsScope}}
Conditional, renders a block if givenList<Commits> contains giventype andscope.
{{#ifContainsTypeAndScopecommitstype="chore"scope="deps"}} commits contains chore with deps{{/ifContainsScope}}
Conditional, renders a block if givenList<Commits> contains commits that don't match the giventype.
{{#ifContainsTypeOtherThancommitstype="fix"}} commits contains other types than fix{{/ifContainsTypeOtherThan}}
Conditional, renders a block if givenList<Commits> containsbreaking changes.
{{#ifContainsBreakingcommits}} commits contains fixes{{/ifContainsBreaking}}
Renders date ofCommit on formatYYYY-MM-DD.
{{#commits}}{{commitDate .}}{{/commits}}
Renders description ofCommit.
{{#commits}}{{commitDescription .}}{{/commits}}
Renders reverted commit refered to byCommit.
{{#commits}}{{revertedCommit .}}{{/commits}}
Conditional, renders a block if givenIssue is oftype.
{{#issues}}{{#ifIssueType.type="fix"}} is type fix{{/ifIssueType}}{{/issues}}
Conditional, renders a block if givenIssue is oftype.
{{#issues}}{{#ifIssueTypeOtherThan.type="fix"}} is not type fix{{/ifIssueTypeOtherThan}}{{/issues}}
Conditional, renders a block if givenCommit is oftype.
{{#commits}}{{#ifCommitType.type="fix"}} is type fix{{/ifCommitType}}{{/commits}}
Conditional, renders a block if givenCommit is oftype.
{{#commits}}{{#ifCommitTypeOtherThan.type="fix"}} is not type fix{{/ifCommitTypeOtherThan}}{{/commits}}
Conditional, renders a block if givenCommit isbreaking.
{{#commits}}{{#ifCommitBreaking.}} is breaking{{/ifCommitBreaking}}{{/commits}}
Conditional, renders a block if givenCommit hasscope.
{{#commits}}{{#ifCommitScope.scope="utils"}} is scope utils{{/ifCommitScope}}{{/commits}}
Conditional, renders a block if givenCommit hasfooters.
{{#commits}}{{#ifCommitHasFooters.}} has footers{{/ifCommitHasFooters}}{{/commits}}
Conditional, renders a block if givenCommit hasparagraphs.
{{#commits}}{{#ifCommitHasParagraphs.}} has paragraphs{{/ifCommitHasParagraphs}}{{/commits}}
Renders block for eachscope inCommit.
{{#commits}}{{#eachCommitScope.}} scope:{{.}}{{/eachCommitScope}}{{/commits}}
Renders block for eachrefs inCommit.
{{#commits}}{{#eachCommitRefs.}} references issue:{{.}}{{/eachCommitRefs}}{{/commits}}
Renders block for eachfixes inCommit.
{{#commits}}{{#eachCommitFixes.}} fixes issue:{{.}}{{/eachCommitFixes}}{{/commits}}
Renders block for eachparagraph inCommit.
{{#commits}}{{#eachCommitParagraph.}}{{.}}{{/eachCommitParagraph}}{{/commits}}
Renders block for eachfooter inCommit.
{{#commits}}{{#eachCommitFooter.}}{{token}}{{/eachCommitFooter}}{{/commits}}
OptionaltokenMatching regex parameter filters footer tokens.
Conditional, renders a block if givenFooter hasvalue.
{{#commits}}{{#eachCommitFooter.}}{{#ifFooterHasValue.}}{{{value}}}{{/ifFooterHasValue}}{{/eachCommitFooter}}{{/commits}}
Conditional, renders a block ifa equalsb.
{{#tags}}{{name}} Unreleased ?{{#ifEqualsname"Unreleased"}} ja{{else}} nej{{/ifEquals}}{{/tags}}
Conditional, renders a block ifa matches regexpb.
{{#eachCommitFixes.}}{{#ifMatches."^[A-Z]+-[0-9]+"}} fixes : "{{subString .03}}" and number{{subString .4}}{{/ifMatches}}{{/eachCommitFixes}}
Works just likeJava substring.
{{#eachCommitFixes.}}{{#ifMatches."^[A-Z]+-[0-9]+"}} fixes : "{{subString .03}}" and number{{subString .4}}{{/ifMatches}}{{/eachCommitFixes}}
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, 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 abuilder 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:
defnextVersion =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).
About
Generate changelog, and/or next version, with, or without, conventional commits from a GIT repository
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.