Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Generate changelog, and/or next version, with, or without, conventional commits from a GIT repository

License

NotificationsYou must be signed in to change notification settings

tomasbjerre/git-changelog-lib

Repository files navigation

Maven Central

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, likeCHANGELOG.md. There are some templates used for testing availablehere.
  • Or, just rendered to aString.

It can integrate with Jira, Redmine, GitLab and/or GitHub to retrieve the title of issues.

VersionJava Version
version < 2.0.08
2.0.0 <= version < 2.2.011
2.2.0 <= version17

Usage

This software can be used with:

There are examples of different templatesin the code that are used for testing.

Template - Simple

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}}

Template - Conventional

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}}

Partials

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"

Helpers

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.

eachUrlPart <Changelog>

Loop each part of the URL.

https://gitlab.com/{{#eachUrlPart.}}{{#if@first}}{{else}}{{.}}/{{/if}}{{/eachUrlPart}}

ifReleaseTag <Tag>

Conditional, renders a block if givenTag matches release-tag.

{{#tags}}{{#ifReleaseTag.}}  "{{.}}" is a release tag{{/ifReleaseTag}}{{/tags}}

tagDate <Tag>

Renders date ofTag on formatYYYY-MM-DD.

{{#tags}}{{tagDate .}}{{/tags}}

ifContainsIssueType <List<Issue>>

Conditional, renders a block if givenList<Issue> contains giventype.

{{#ifContainsIssueTypeissuestype="Bug"}}  issues contains bugs{{/ifContainsIssueType}}

ifContainsIssueTypeOtherThan <List<Issue>>

Conditional, renders a block if givenList<Issue> contains issues that don't match the giventype.

{{#ifContainsIssueTypeOtherThanissuestype="fix"}}  commits contains other types than fix{{/ifContainsIssueTypeOtherThan}}

ifContainsIssueLabel <List<Issue>> label="<value>"

Conditional, renders a block if givenList<Issue> contains givenlabel.

{{#ifContainsIssueLabelissueslabel='enhancement'}}  content here{{/ifContainsIssueLabel}}

ifContainsIssueLabelOtherThan <List<Issue>>

Conditional, renders a block if givenList<Issue> contains labels that don't match the givenlabel.

{{#ifContainsIssueLabelOtherThanissueslabel='enhancement'}}  content here{{/ifContainsIssueLabel}}

ifIssueLabel <label> label="<value>"

Conditional, renders a block if givenlabel matches the givenvalue.

{{#ifIssueLabel.label='enhancement'}}  Found a enhancement{{/ifIssueLabel}}

ifContainsType <List<Commit>>

Conditional, renders a block if givenList<Commits> contains giventype.

{{#ifContainsTypecommitstype="fix"}}  commits contains fixes{{/ifContainsType}}

ifContainsScope <List<Commit>>

Conditional, renders a block if givenList<Commits> contains givenscope.

{{#ifContainsScopecommitsscope="deps"}}  commits contains deps{{/ifContainsScope}}

ifContainsTypeAndScope <List<Commit>>

Conditional, renders a block if givenList<Commits> contains giventype andscope.

{{#ifContainsTypeAndScopecommitstype="chore"scope="deps"}}  commits contains chore with deps{{/ifContainsScope}}

ifContainsTypeOtherThan <List<Commit>>

Conditional, renders a block if givenList<Commits> contains commits that don't match the giventype.

{{#ifContainsTypeOtherThancommitstype="fix"}}  commits contains other types than fix{{/ifContainsTypeOtherThan}}

ifContainsBreaking <List<Commit>>

Conditional, renders a block if givenList<Commits> containsbreaking changes.

{{#ifContainsBreakingcommits}}  commits contains fixes{{/ifContainsBreaking}}

commitDate <Commit>

Renders date ofCommit on formatYYYY-MM-DD.

{{#commits}}{{commitDate .}}{{/commits}}

commitDescription <Commit>

Renders description ofCommit.

{{#commits}}{{commitDescription .}}{{/commits}}

revertedCommit <Commit>

Renders reverted commit refered to byCommit.

{{#commits}}{{revertedCommit .}}{{/commits}}

ifIssueType <Issue> type="<type>"

Conditional, renders a block if givenIssue is oftype.

{{#issues}}{{#ifIssueType.type="fix"}} is type fix{{/ifIssueType}}{{/issues}}

ifIssueTypeOtherThan <Issue> type="<type>"

Conditional, renders a block if givenIssue is oftype.

{{#issues}}{{#ifIssueTypeOtherThan.type="fix"}} is not type fix{{/ifIssueTypeOtherThan}}{{/issues}}

ifCommitType <Commit> type="<type>"

Conditional, renders a block if givenCommit is oftype.

{{#commits}}{{#ifCommitType.type="fix"}} is type fix{{/ifCommitType}}{{/commits}}

ifCommitTypeOtherThan <Commit> type="<type>"

Conditional, renders a block if givenCommit is oftype.

{{#commits}}{{#ifCommitTypeOtherThan.type="fix"}} is not type fix{{/ifCommitTypeOtherThan}}{{/commits}}

ifCommitBreaking <Commit>

Conditional, renders a block if givenCommit isbreaking.

{{#commits}}{{#ifCommitBreaking.}} is breaking{{/ifCommitBreaking}}{{/commits}}

ifCommitScope <Commit> scope="utils"

Conditional, renders a block if givenCommit hasscope.

{{#commits}}{{#ifCommitScope.scope="utils"}} is scope utils{{/ifCommitScope}}{{/commits}}

ifCommitHasFooters <Commit>

Conditional, renders a block if givenCommit hasfooters.

{{#commits}}{{#ifCommitHasFooters.}} has footers{{/ifCommitHasFooters}}{{/commits}}

ifCommitHasParagraphs <Commit>

Conditional, renders a block if givenCommit hasparagraphs.

{{#commits}}{{#ifCommitHasParagraphs.}} has paragraphs{{/ifCommitHasParagraphs}}{{/commits}}

eachCommitScope <Commit>

Renders block for eachscope inCommit.

{{#commits}}{{#eachCommitScope.}}  scope:{{.}}{{/eachCommitScope}}{{/commits}}

eachCommitRefs <Commit>

Renders block for eachrefs inCommit.

{{#commits}}{{#eachCommitRefs.}}  references issue:{{.}}{{/eachCommitRefs}}{{/commits}}

eachCommitFixes <Commit>

Renders block for eachfixes inCommit.

{{#commits}}{{#eachCommitFixes.}}  fixes issue:{{.}}{{/eachCommitFixes}}{{/commits}}

eachCommitParagraph <Commit>

Renders block for eachparagraph inCommit.

{{#commits}}{{#eachCommitParagraph.}}{{.}}{{/eachCommitParagraph}}{{/commits}}

eachCommitFooter <Commit>

Renders block for eachfooter inCommit.

{{#commits}}{{#eachCommitFooter.}}{{token}}{{/eachCommitFooter}}{{/commits}}

OptionaltokenMatching regex parameter filters footer tokens.

ifFooterHasValue <Footer>

Conditional, renders a block if givenFooter hasvalue.

{{#commits}}{{#eachCommitFooter.}}{{#ifFooterHasValue.}}{{{value}}}{{/ifFooterHasValue}}{{/eachCommitFooter}}{{/commits}}

ifEquals <a> <b>

Conditional, renders a block ifa equalsb.

{{#tags}}{{name}} Unreleased ?{{#ifEqualsname"Unreleased"}} ja{{else}} nej{{/ifEquals}}{{/tags}}

ifMatches <a> <b>

Conditional, renders a block ifa matches regexpb.

{{#eachCommitFixes.}}{{#ifMatches."^[A-Z]+-[0-9]+"}}  fixes : "{{subString .03}}" and number{{subString .4}}{{/ifMatches}}{{/eachCommitFixes}}

subString <a> <b> <c>

Works just likeJava substring.

{{#eachCommitFixes.}}{{#ifMatches."^[A-Z]+-[0-9]+"}}  fixes : "{{subString .03}}" and number{{subString .4}}{{/ifMatches}}{{/eachCommitFixes}}

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, 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)

Library

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

Stars

Watchers

Forks

Packages

No packages published

Contributors23


[8]ページ先頭

©2009-2025 Movatter.jp