Skip to content

Commit

Permalink
Merge pull request #611 from Happypig375/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed Aug 27, 2020
2 parents d996293 + c5cec30 commit d472269
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 25 deletions.
50 changes: 26 additions & 24 deletions README.md
Expand Up @@ -71,6 +71,7 @@ categories:
- title: '🧰 Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
Expand All @@ -92,23 +93,24 @@ template: |

You can configure Release Drafter using the following key in your `.github/release-drafter.yml` file:

| Key | Required | Description |
| --------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `template` | Required | The template for the body of the draft release. Use [template variables](#template-variables) to insert values. |
| `name-template` | Optional | The template for the name of the draft release. For example: `"v$NEXT_PATCH_VERSION"`. |
| `tag-template` | Optional | The template for the tag of the draft release. For example: `"v$NEXT_PATCH_VERSION"`. |
| `version-template` | Optional | The template to use when calculating the next version number for the release. Useful for projects that don't use semantic versioning. Default: `"$MAJOR.$MINOR.$PATCH"` |
| `change-template` | Optional | The template to use for each merged pull request. Use [change template variables](#change-template-variables) to insert values. Default: `"* $TITLE (#$NUMBER) @$AUTHOR"`. |
| `no-changes-template` | Optional | The template to use for when there’s no changes. Default: `"* No changes"`. |
| `references` | Optional | The references to listen for configuration updates to `.github/release-drafter.yml`. Refer to [References](#references) to learn more about this |
| `categories` | Optional | Categorize pull requests using labels. Refer to [Categorize Pull Requests](#categorize-pull-requests) to learn more about this option. |
| `exclude-labels` | Optional | Exclude pull requests using labels. Refer to [Exclude Pull Requests](#exclude-pull-requests) to learn more about this option. |
| `include-labels` | Optional | Include only the specified pull requests using labels. Refer to [Include Pull Requests](#include-pull-requests) to learn more about this option. |
| `replacers` | Optional | Search and replace content in the generated changelog body. Refer to [Replacers](#replacers) to learn more about this option. |
| `sort-by` | Optional | Sort changelog by merged_at or title. Can be one of: `merged_at`, `title`. Default: `merged_at`. |
| `sort-direction` | Optional | Sort changelog in ascending or descending order. Can be one of: `ascending`, `descending`. Default: `descending`. |
| `prerelease` | Optional | Mark the draft release as pre-release. Default `false`. |
| `version-resolver` | Optional | Adjust the `$RESOLVED_VERSION` variable using labels. Refer to [Version Resolver](#version-resolver) to learn more about this |
| Key | Required | Description |
| ---------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `template` | Required | The template for the body of the draft release. Use [template variables](#template-variables) to insert values. |
| `name-template` | Optional | The template for the name of the draft release. For example: `"v$NEXT_PATCH_VERSION"`. |
| `tag-template` | Optional | The template for the tag of the draft release. For example: `"v$NEXT_PATCH_VERSION"`. |
| `version-template` | Optional | The template to use when calculating the next version number for the release. Useful for projects that don't use semantic versioning. Default: `"$MAJOR.$MINOR.$PATCH"` |
| `change-template` | Optional | The template to use for each merged pull request. Use [change template variables](#change-template-variables) to insert values. Default: `"* $TITLE (#$NUMBER) @$AUTHOR"`. |
| `change-title-escapes` | Optional | Characters to escape in `$TITLE` when inserting into `change-template` so that they are not interpreted as Markdown format characters. Default: `""` |
| `no-changes-template` | Optional | The template to use for when there’s no changes. Default: `"* No changes"`. |
| `references` | Optional | The references to listen for configuration updates to `.github/release-drafter.yml`. Refer to [References](#references) to learn more about this |
| `categories` | Optional | Categorize pull requests using labels. Refer to [Categorize Pull Requests](#categorize-pull-requests) to learn more about this option. |
| `exclude-labels` | Optional | Exclude pull requests using labels. Refer to [Exclude Pull Requests](#exclude-pull-requests) to learn more about this option. |
| `include-labels` | Optional | Include only the specified pull requests using labels. Refer to [Include Pull Requests](#include-pull-requests) to learn more about this option. |
| `replacers` | Optional | Search and replace content in the generated changelog body. Refer to [Replacers](#replacers) to learn more about this option. |
| `sort-by` | Optional | Sort changelog by merged_at or title. Can be one of: `merged_at`, `title`. Default: `merged_at`. |
| `sort-direction` | Optional | Sort changelog in ascending or descending order. Can be one of: `ascending`, `descending`. Default: `descending`. |
| `prerelease` | Optional | Mark the draft release as pre-release. Default `false`. |
| `version-resolver` | Optional | Adjust the `$RESOLVED_VERSION` variable using labels. Refer to [Version Resolver](#version-resolver) to learn more about this |

Release Drafter also supports [Probot Config](https://github.com/probot/probot-config), if you want to store your configuration files in a central repository. This allows you to share configurations between projects, and create a organization-wide configuration file by creating a repository named `.github` with the file `.github/release-drafter.yml`.

Expand Down Expand Up @@ -169,13 +171,13 @@ If a pull requests is found with the label `major`/`minor`/`patch`, the correspo

You can use any of the following variables in `change-template`:

| Variable | Description |
| --------- | --------------------------------------------------------------------------- |
| `$NUMBER` | The number of the pull request, e.g. `42`. |
| `$TITLE` | The title of the pull request, e.g. `Add alien technology`. |
| `$AUTHOR` | The pull request author’s username, e.g. `gracehopper`. |
| `$BODY` | The body of the pull request e.g. `Fixed spelling mistake`. |
| `$URL` | The URL of the pull request e.g. `https://github.com/octocat/repo/pull/42`. |
| Variable | Description |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$NUMBER` | The number of the pull request, e.g. `42`. |
| `$TITLE` | The title of the pull request, e.g. `Add alien technology`. Any characters excluding @ and # matching `change-title-escapes` will be prepended with a backslash so that they will appear verbatim instead of being interpreted as markdown format characters. @s and #s if present in `change-title-escapes` will be appended with an HTML comment so that they don't become mentions. |
| `$AUTHOR` | The pull request author’s username, e.g. `gracehopper`. |
| `$BODY` | The body of the pull request e.g. `Fixed spelling mistake`. |
| `$URL` | The URL of the pull request e.g. `https://github.com/octocat/repo/pull/42`. |

## References

Expand Down
1 change: 1 addition & 0 deletions lib/default-config.js
Expand Up @@ -4,6 +4,7 @@ const DEFAULT_CONFIG = Object.freeze({
'name-template': '',
'tag-template': '',
'change-template': `* $TITLE (#$NUMBER) @$AUTHOR`,
'change-title-escapes': '',
'no-changes-template': `* No changes`,
'version-template': `$MAJOR.$MINOR.$PATCH`,
'version-resolver': {
Expand Down
20 changes: 19 additions & 1 deletion lib/releases.js
@@ -1,4 +1,5 @@
const compareVersions = require('compare-versions')
const regexEscape = require('escape-string-regexp')

const { getVersionInfo } = require('./versions')
const { template } = require('./template')
Expand Down Expand Up @@ -155,11 +156,26 @@ const generateChangeLog = (mergedPullRequests, config) => {
categorizedPullRequests,
] = categorizePullRequests(mergedPullRequests, config)

const escapeTitle = (title) =>
// If config['change-title-escapes'] contains backticks, then they will be escaped along with content contained inside backticks
// If not, the entire backtick block is matched so that it will become a markdown code block without escaping any of its content
title.replace(
new RegExp(
`[${regexEscape(config['change-title-escapes'])}]|\`.*?\``,
'g'
),
(match) => {
if (match.length > 1) return match
if (match == '@' || match == '#') return `${match}<!---->`
return `\\${match}`
}
)

const pullRequestToString = (pullRequests) =>
pullRequests
.map((pullRequest) =>
template(config['change-template'], {
$TITLE: pullRequest.title,
$TITLE: escapeTitle(pullRequest.title),
$NUMBER: pullRequest.number,
$AUTHOR: pullRequest.author ? pullRequest.author.login : 'ghost',
$BODY: pullRequest.body,
Expand Down Expand Up @@ -214,6 +230,8 @@ const resolveVersionKeyIncrement = (mergedPullRequests, config) => {
return versionKey || config['version-resolver'].default
}

module.exports.generateChangeLog = generateChangeLog

module.exports.generateReleaseInfo = ({
commits,
config,
Expand Down
4 changes: 4 additions & 0 deletions lib/schema.js
Expand Up @@ -18,6 +18,10 @@ const schema = (context) => {
DEFAULT_CONFIG['change-template']
),

'change-title-escapes': Joi.string()
.allow('')
.default(DEFAULT_CONFIG['change-title-escapes']),

'no-changes-template': Joi.string().default(
DEFAULT_CONFIG['no-changes-template']
),
Expand Down
12 changes: 12 additions & 0 deletions schema.json
Expand Up @@ -15,6 +15,18 @@
"default": "* $TITLE (#$NUMBER) @$AUTHOR",
"type": "string"
},
"change-title-escapes": {
"anyOf": [
{
"type": "string",
"enum": [""]
},
{
"default": "",
"type": "string"
}
]
},
"no-changes-template": {
"default": "* No changes",
"type": "string"
Expand Down

0 comments on commit d472269

Please sign in to comment.