Skip to content

Commit

Permalink
Add tag-prefix config option
Browse files Browse the repository at this point in the history
  • Loading branch information
mxj4 committed Dec 29, 2021
1 parent 4ace379 commit 38a1641
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
27 changes: 22 additions & 5 deletions dist/index.js
Expand Up @@ -482,6 +482,7 @@ const { SORT_BY, SORT_DIRECTIONS } = __nccwpck_require__(16445)
const DEFAULT_CONFIG = Object.freeze({
'name-template': '',
'tag-template': '',
'tag-prefix': '',
'change-template': `* $TITLE (#$NUMBER) @$AUTHOR`,
'change-title-escapes': '',
'no-changes-template': `* No changes`,
Expand Down Expand Up @@ -620,10 +621,17 @@ module.exports.findReleases = async ({ ref, context, config }) => {

log({ context, message: `Found ${releases.length} releases` })

const { 'filter-by-commitish': filterByCommitish } = config
const filteredReleases = filterByCommitish
? releases.filter((r) => ref.match(`/${r.target_commitish}$`))
: releases
const {
'filter-by-commitish': filterByCommitish,
'tag-prefix': tagPrefix,
} = config
const filteredReleases = releases
.filter((r) =>
filterByCommitish ? ref.match(`/${r.target_commitish}$`) : r
)
.filter((r) =>
tagPrefix && tagPrefix.length > 0 ? r.tag_name.startsWith(tagPrefix) : r
)
const sortedPublishedReleases = sortReleases(
filteredReleases.filter((r) => !r.draft)
)
Expand Down Expand Up @@ -886,7 +894,12 @@ module.exports.generateReleaseInfo = ({
}

if (tag === undefined) {
tag = versionInfo ? template(config['tag-template'] || '', versionInfo) : ''
const partialTag = versionInfo
? template(config['tag-template'] || '', versionInfo)
: ''
tag = config['tag-prefix']
? `${config['tag-prefix']}${partialTag}`
: partialTag
}

if (name === undefined) {
Expand Down Expand Up @@ -999,6 +1012,10 @@ const schema = (context) => {
.allow('')
.default(DEFAULT_CONFIG['tag-template']),

'tag-prefix': Joi.string()
.allow('')
.default(DEFAULT_CONFIG['tag-prefix']),

'exclude-labels': Joi.array()
.items(Joi.string())
.default(DEFAULT_CONFIG['exclude-labels']),
Expand Down
1 change: 1 addition & 0 deletions lib/default-config.js
Expand Up @@ -3,6 +3,7 @@ const { SORT_BY, SORT_DIRECTIONS } = require('./sort-pull-requests')
const DEFAULT_CONFIG = Object.freeze({
'name-template': '',
'tag-template': '',
'tag-prefix': '',
'change-template': `* $TITLE (#$NUMBER) @$AUTHOR`,
'change-title-escapes': '',
'no-changes-template': `* No changes`,
Expand Down
22 changes: 17 additions & 5 deletions lib/releases.js
Expand Up @@ -28,10 +28,17 @@ module.exports.findReleases = async ({ ref, context, config }) => {

log({ context, message: `Found ${releases.length} releases` })

const { 'filter-by-commitish': filterByCommitish } = config
const filteredReleases = filterByCommitish
? releases.filter((r) => ref.match(`/${r.target_commitish}$`))
: releases
const {
'filter-by-commitish': filterByCommitish,
'tag-prefix': tagPrefix,
} = config
const filteredReleases = releases
.filter((r) =>
filterByCommitish ? ref.match(`/${r.target_commitish}$`) : r
)
.filter((r) =>
tagPrefix && tagPrefix.length > 0 ? r.tag_name.startsWith(tagPrefix) : r
)
const sortedPublishedReleases = sortReleases(
filteredReleases.filter((r) => !r.draft)
)
Expand Down Expand Up @@ -294,7 +301,12 @@ module.exports.generateReleaseInfo = ({
}

if (tag === undefined) {
tag = versionInfo ? template(config['tag-template'] || '', versionInfo) : ''
const partialTag = versionInfo
? template(config['tag-template'] || '', versionInfo)
: ''
tag = config['tag-prefix']
? `${config['tag-prefix']}${partialTag}`
: partialTag
}

if (name === undefined) {
Expand Down
4 changes: 4 additions & 0 deletions lib/schema.js
Expand Up @@ -38,6 +38,10 @@ const schema = (context) => {
.allow('')
.default(DEFAULT_CONFIG['tag-template']),

'tag-prefix': Joi.string()
.allow('')
.default(DEFAULT_CONFIG['tag-prefix']),

'exclude-labels': Joi.array()
.items(Joi.string())
.default(DEFAULT_CONFIG['exclude-labels']),
Expand Down
12 changes: 12 additions & 0 deletions schema.json
Expand Up @@ -59,6 +59,18 @@
}
]
},
"tag-prefix": {
"anyOf": [
{
"type": "string",
"enum": [""]
},
{
"default": "",
"type": "string"
}
]
},
"exclude-labels": {
"default": [],
"type": "array",
Expand Down

0 comments on commit 38a1641

Please sign in to comment.