Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag-prefix config option #997

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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