auto-changelog

repository·master·Indexed 23 days ago

https://github.com/cookpete/auto-changelog

A command-line tool for generating changelogs from git tags and commit history. It supports high customization via CLI flags, configuration files (package.json or .auto-changelog), and Handlebars templates. The tool automatically detects Git providers like GitHub, GitLab, Bitbucket, and Azure DevOps to generate appropriate links, and provides options for custom URL overrides, regex-based commit filtering, and custom Handlebars helpers.

Tokens
3K
Snippets
9
Records
16
Agent score
80%

What's inside auto-changelog

  1. Use custom Handlebars templates

    master

    You can provide a custom .hbs template file via the --template flag. To see the data structure available to your template, generate a JSON version of the changelog using --template json.

    Example template usage:

    {{#each releases}}
      ### [{{title}}]({{href}})
      {{#each commits}}
        - {{subject}} [`{{shorthash}}`]({{href}})
      {{/each}}
    {{/each}}
    auto-changelog --template changelog-template.hbs
  2. Automate changelog updates with npm version

    master

    You can automate changelog generation by adding auto-changelog -p to your package.json version scripts. Using the -p (or --package) flag tells the tool to use the version from package.json as the latest release, ensuring that all commits since the last tag are included in the current version's section.

    {
      "name": "my-awesome-package",
      "version": "1.0.0",
      "devDependencies": {
        "auto-changelog": "*"
      },
      "scripts": {
        "version": "auto-changelog -p && git add CHANGELOG.md"
      }
    }
  3. Override URL formats for links

    master

    If you use a non-standard remote (like Redmine or a custom diff tool), you can override the automatically generated links using tokens {id} for single identifiers or {from} and {to} for version comparisons.

    • --commit-url [url]: Use {id} for commit IDs.
    • --issue-url [url]: Use {id} for issue IDs.
    • --merge-url [url]: Use {id} for merge IDs.
    • --compare-url [url]: Use {from} and {to} for tag comparisons.
    # Link all issues to redmine
    auto-changelog --issue-url https://www.redmine.org/issues/{id}
    
    # Link to custom diff page
    auto-changelog --compare-url https://example.com/repo/compare/{from}...{to}
  4. Supported Git remote providers and default link patterns

    master

    The tool automatically detects the Git provider from your remote URL and generates appropriate links. Supported providers include:

    • Bitbucket: Uses /commits/{id}, /issues/{id}, /pull-requests/{id}, and /compare/{to}..{from}.
    • GitLab: Uses /commit/{id}, /issues/{id}, /merge_requests/{id}, and /compare/{from}...{to}.
    • Azure DevOps / Visual Studio: Uses /commit/{id}, /_workitems/edit/{id}, /pullrequest/{id}, and a specific branch comparison URL.
    • GitHub (Default): For other providers (like GitHub), it defaults to /commit/{id}, /issues/{id}, /pull/{id}, and /compare/{from}...{to}.
  5. Configure auto-changelog via package.json or config file

    master

    You can define configuration options in two ways:

    1. package.json: Use the auto-changelog key with camelCase option names. This takes precedence over other config files.
    2. .auto-changelog file: A JSON file in your project root.

    Example package.json configuration:

    {
      "name": "my-awesome-package",
      "auto-changelog": {
        "output": "HISTORY.md",
        "template": "keepachangelog",
        "unreleased": true,
        "commitLimit": false
      }
    }
    {
      "name": "my-awesome-package",
      "auto-changelog": {
        "output": "HISTORY.md",
        "template": "keepachangelog",
        "unreleased": true",
        "commitLimit": false
      }
    }
  6. Replace text in changelog output

    master

    Use the replaceText option in your package.json to perform regex-based text replacement in the generated log. This is useful for turning issue IDs into clickable links.

    Each pattern is applied using string.replace(new RegExp(key, 'g'), value).

    {
      "name": "my-awesome-package",
      "auto-changelog": {
        "replaceText": {
          "(ABC-\\d+)": "[`$1`](https://issues.apache.org/jira/browse/$1)"
        }
      }
    }
  7. Use the `commit-list` Handlebars helper

    master

    The {{#commit-list}} helper allows you to filter and render specific lists of commits within a template based on regex patterns.

    Available options:

    • heading: A heading to render if at least one commit matches.
    • message: A regex pattern to match against the entire commit message.
    • subject: A regex pattern to match against the commit subject only.
    • exclude: A regex pattern to exclude commits (useful for preventing duplicates).
    {{#each releases}}
      ### [{{title}}]({{href}})
    
      {{! List commits with `Breaking change: ` somewhere in the message }}
      {{#commit-list commits heading='### Breaking Changes' message='Breaking change: '}}
        - {{subject}} [`{{shorthash}}`]({{href}})
      {{/commit-list}}
    
      {{! List commits that add new features, not already listed above }}
      {{#commit-list commits heading='### New Features' message='feat: ' exclude='Breaking change: '}}
        - {{subject}} [`{{shorthash}}`]({{href}})
      {{/commit-list}}
    {{/each}}
  8. Register custom Handlebars helpers

    master

    Use the --handlebars-setup flag to point to a JavaScript file that registers custom Handlebars helpers for your templates.

    auto-changelog --handlebars-setup setup.js --template custom-template.hbs
    
    // setup.js
    module.exports = function (Handlebars) {
      Handlebars.registerHelper('custom', function (context, options) {
        return 'custom helpers!'
      })
    }
  9. Customize link generation with URL overrides

    master

    You can override the default link generation for commits, issues, merge requests, and comparisons by providing custom URL templates in your configuration. Use the following placeholder tokens within your URL strings:

    • {id}: Replaced by the commit, issue, or merge request ID.
    • {from}: Replaced by the starting version/tag/branch.
    • {to}: Replaced by the ending version/tag/branch.

    Supported override keys are commitUrl, issueUrl, mergeUrl, and compareUrl.

  10. Reference: auto-changelog CLI options

    master

    The following options are available for the auto-changelog command line interface:

    OptionDescription
    -o, --output [file]Output file, default: CHANGELOG.md
    -c, --config [file]Config file location, default: .auto-changelog
    -t, --template [template]Specify template to use [compact, keepachangelog, json], default: compact
    -r, --remote [remote]Specify git remote to use for links, default: origin
    -p, --packageUse version from package.json as latest release
    -v, --latest-version [version]Use specified version as latest release
    -u, --unreleasedInclude section for unreleased changes
    -l, --commit-limit [count]Number of commits to display per release, default: 3
    -b, --backfill-limit [count]Number of commits to backfill empty releases with, default: 3
    --commit-url [url]Override url for commits, use {id} for commit id
    --issue-url [url]Override url for issues, use {id} for issue id
    --merge-url [url]Override url for merges, use {id} for merge id
    --compare-url [url]Override url for compares, use {from} and {to} for tags
    --issue-pattern [regex]Override regex pattern for issues in commit messages
    --breaking-pattern [regex]Regex pattern for breaking change commits
    --merge-pattern [regex]Add custom regex pattern for merge commits
    --commit-pattern [regex]Pattern to include when parsing commits
    --ignore-commit-pattern [regex]Pattern to ignore when parsing commits
    --tag-pattern [regex]Override regex pattern for version tags
    --tag-prefix [prefix]Prefix used in version tags, default: v
    --autodetect-monorepo-disabledDisable monorepo autodetection, default: true
    --starting-version [tag]Specify earliest version to include in changelog
    --starting-date [yyyy-mm-dd]Specify earliest date to include in changelog
    --ending-version [tag]Specify latest version to include in changelog
    --sort-commits [property]Sort commits by property [relevance, date, date-desc, subject, subject-desc], default: relevance
    --release-summaryDisplay tagged commit message body as release summary
    --unreleased-onlyOnly output unreleased changes
    --hide-empty-releasesHide empty releases
    --hide-creditHide auto-changelog credit
    --handlebars-setup [file]Handlebars setup file
    --append-git-log [string]String to append to git log command
    --append-git-tag [string]String to append to git tag command
    --prependPrepend changelog to output file
    --stdoutOutput changelog to stdout
    --plugins [...name]Use plugins to augment commit/merge/release information