Changesets Format with Git Links
A changelog formatter for Changesets that adds commit and issue/PR links
What is this?
Atlassian Changesets is a changelog management tool. Its default changelog formatter only generates a plain list of changes.
This package adds links to the git commits, issues, and pull requests where your changesets were added.
The result is similar to the output of other common changelog managers, such as standard-version and Release Please.
Setup
If you have already set up Changesets, you only need to install the package and add it to your .changeset/config.json.
You do not need to enable the commit option in your config.
npm install --save-dev changesets-format-with-git-links
// .changeset/config.json
{
"changelog": [
"changesets-format-with-git-links",
{
"repoBaseUrl": "https://github.com/your-username/repo",
// This will inject issue and commit links to the end of the first line of your changeset message
"changesetTemplate": "- ${changesetTitle}${issue}${commit}${changesetBody}"
}
]
}
Options
repoBaseUrl (required)
A base url -- including https -- which can be used to build links in commitTemplate and issueTemplate.
Example: "https://github.com/spautz/changesets-changelog-format"
changesetTemplate (default: "- ${changesetTitle}${issue}${commit}${changesetBody}")
Content that will be added to your changelog.
With the deafult value, issue and commit links will be inserted at the end of the first line of your changeset message.
See commitTemplate for the $commit variable, issueTemplate for the $issue variable, and Template Variables
for other available values.
commitTemplate (default: " ([$abbrevHash]($repoBaseUrl/commit/$hash))")
Content for the $commit variable, based on the commit when the changeset was created.
See gitlogOptions below for information on the available fields from the commit.
commitMissingTemplate (default: "")
Content for the $commit variable when no commit could be found. This should generally be left blank.
issuePattern (default: "#(\\d+)\\)")
Regular expression (without the leading and trailing /) used to identify issues and pull requests in the subject line
of a commit message. The default will match a number immediately followed by a closing parentheses, like #4).
If the commit message matches this pattern, the Regex result will be available as $issueMatch and the text inside the
capturing group ((\d+) in the default) will be available as $issue in the issueTemplate, below.
issueTemplate (default: " ([#$issue]($repoBaseUrl/issues/$issue))")
Content for the $issue variable, based on the value matched by issuePattern.
issueMissingTemplate (default: "")
Content for the $issue variable when no issue or pull request could be found. This should generally be left blank.
gitlogOptions
Default:
{
"repo": ".",
"number": 1,
"fields": ["hash", "abbrevHash", "subject"],
"includeMergeCommitFiles": true
}
Options passed to gitlog (see docs here).
This can be used to add additional fields to the template, or to change the
behavior of the git log search.
How it works
This works by identifying the git commit when a changeset entry was added or updated, looking for an issue number, and then using templates to append the git links (commit and issue number, if present) to the changelog entry.
Template variables
Inside any of the templates (changesetTemplate, commitTemplate, commitMissingTemplate, issueTemplate, or issueMissingTemplate),
any token that starts with $ or which is wrapped within ${...} will be treated as a variable.
Use \\$ to escape the dollar sign character if you do not want it to be treated as a variable.
Available variables
Information from the changeset entry:
$changesetTitle$changesetBody$changesetRawBody$versionType$changesetInfocontains all of the above, and any other information from Changesets (e.g.,${changesetInfo.changesetTitle},${changesetInfo.versionType}).
Information from the git commit when the changeset was added or modified:
$hash$abbrevHash$summary- Anything you requested via
gitlogOptions.fields $commitis generated fromcommitTemplate(orcommitMissingTemplateif the commit was not found)$commitInfocontains all of the above (e.g.,${commitInfo.abbrevHash},${commitInfo.hash}).
Information from the matched issue pattern, if any:
$issueis generated fromissueTemplate(orissueMissingTemplateif no issue not found)$issueMatchcontains all of the results from the match againstissuePattern(e.g.,${issueMatch[1]}})
And also any additional values you added to the options in your .changeset/config.json (such as $repoBaseUrl)