Skip to content

Commit

Permalink
Category templating (release-drafter#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
rofafor authored Jan 28, 2021
1 parent 4a62108 commit 8ef32da
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"trailingComma": "es5",
"arrowParens": "always",
"semi": false,
"singleQuote": true,
"bracketSpacing": true
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ You can configure Release Drafter using the following key in your `.github/relea
| Key | Required | Description |
| ---------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `template` | Required | The template for the body of the draft release. Use [template variables](#template-variables) to insert values. |
| `category-template` | Optional | The template to use for each category. Use [category template variables](#category-template-variables) to insert values. Default: `"## $TITLE"`. |
| `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"` |
Expand Down Expand Up @@ -125,6 +126,14 @@ You can use any of the following variables in your `template`:
| `$CONTRIBUTORS` | A comma separated list of contributors to this release (pull request authors, commit authors, and commit committers). |
| `$PREVIOUS_TAG` | The previous releases’s tag. |

## Category Template Variables

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

| Variable | Description |
| -------- | ------------------------------------ |
| `$TITLE` | The category title, e.g. `Features`. |

## Next Version Variables

You can use any of the following variables in your `template`, `name-template` and `tag-template`:
Expand Down
10 changes: 9 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ const DEFAULT_CONFIG = Object.freeze({
'sort-direction': SORT_DIRECTIONS.descending,
prerelease: false,
'filter-by-commitish': false,
'category-template': `## $TITLE`,
})

module.exports.DEFAULT_CONFIG = DEFAULT_CONFIG
Expand Down Expand Up @@ -699,7 +700,10 @@ const generateChangeLog = (mergedPullRequests, config) => {

categorizedPullRequests.map((category, index) => {
if (category.pullRequests.length) {
changeLog.push(`## ${category.title}\n\n`)
changeLog.push(
template(config['category-template'], { $TITLE: category.title })
)
changeLog.push('\n\n')

changeLog.push(pullRequestToString(category.pullRequests))

Expand Down Expand Up @@ -952,6 +956,10 @@ const schema = (context) => {
})
.default(DEFAULT_CONFIG['version-resolver']),

'category-template': Joi.string()
.allow('')
.default(DEFAULT_CONFIG['category-template']),

template: Joi.string().required(),

_extends: Joi.string(),
Expand Down
1 change: 1 addition & 0 deletions lib/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const DEFAULT_CONFIG = Object.freeze({
'sort-direction': SORT_DIRECTIONS.descending,
prerelease: false,
'filter-by-commitish': false,
'category-template': `## $TITLE`,
})

module.exports.DEFAULT_CONFIG = DEFAULT_CONFIG
5 changes: 4 additions & 1 deletion lib/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ const generateChangeLog = (mergedPullRequests, config) => {

categorizedPullRequests.map((category, index) => {
if (category.pullRequests.length) {
changeLog.push(`## ${category.title}\n\n`)
changeLog.push(
template(config['category-template'], { $TITLE: category.title })
)
changeLog.push('\n\n')

changeLog.push(pullRequestToString(category.pullRequests))

Expand Down
4 changes: 4 additions & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ const schema = (context) => {
})
.default(DEFAULT_CONFIG['version-resolver']),

'category-template': Joi.string()
.allow('')
.default(DEFAULT_CONFIG['category-template']),

template: Joi.string().required(),

_extends: Joi.string(),
Expand Down
12 changes: 12 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@
"additionalProperties": false,
"patterns": []
},
"category-template": {
"anyOf": [
{
"type": "string",
"enum": [""]
},
{
"default": "## $TITLE",
"type": "string"
}
]
},
"template": {
"type": "string"
},
Expand Down
2 changes: 2 additions & 0 deletions test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const invalidConfigs = [
[{ template: { '👶': 'a' } }, 'must be a string'],
[{ template: null }, 'must be a string'],
[{ template: '' }, 'is not allowed to be empty'],
[{ 'category-template': ['## $TITLE'] }, 'must be a string'],
[{ 'category-template': null }, 'must be a string'],
[{ 'change-template': ['* $TITLE (#$NUMBER) @$AUTHOR'] }, 'must be a string'],
[{ 'change-template': null }, 'must be a string'],
[{ 'change-title-escapes': ['<_*'] }, 'must be a string'],
Expand Down

0 comments on commit 8ef32da

Please sign in to comment.