- introduce new configuration option, allowing to provide an empty_content for categories matching no PRs
- FIX https://github.com/mikepenz/release-changelog-builder-action/issues/804
This commit is contained in:
@@ -163,13 +163,14 @@ This configuration is a `.json` file in the following format.
|
||||
},
|
||||
{
|
||||
"title": "## 🧪 Tests",
|
||||
"labels": ["test"],
|
||||
"labels": ["test"]
|
||||
},
|
||||
{
|
||||
"title": "## 🧪 Tests and some 🪄 Magic",
|
||||
"labels": ["test", "magic"],
|
||||
"exclude_labels": ["no-magic"],
|
||||
"exhaustive": true,
|
||||
"empty_content": "- no matching PRs"
|
||||
}
|
||||
],
|
||||
"ignore_labels": [
|
||||
@@ -325,6 +326,7 @@ Table of descriptions for the `configuration.json` options to configure the resu
|
||||
| category.labels | An array of labels, to match pull request labels against. If any PR label matches any category label, the pull request will show up under this category. |
|
||||
| category.exclude_labels | Similar to `labels`, an array of labels to match PRs against, but if a match occurs the PR is excluded from this category. |
|
||||
| category.exhaustive | Will require all labels defined within this category to be present on the matching PR. |
|
||||
| category.empty_content | If the category has no matching PRs, this content will be used. When not set, the category will be skipped in the changelog. |
|
||||
| ignore_labels | An array of labels, to match pull request labels against. If any PR label overlaps, the pull request will be ignored from the changelog. This takes precedence over category labels |
|
||||
| sort | A `sort` specification, offering the ability to define sort order and property. |
|
||||
| sort.order | The sort order. Allowed values: `ASC`, `DESC` |
|
||||
|
||||
@@ -456,6 +456,38 @@ it('Deduplicate duplicated PRs DESC', async () => {
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
it('Use empty_content for empty category', async () => {
|
||||
const customConfig = Object.assign({}, DefaultConfiguration)
|
||||
customConfig.categories = [
|
||||
{
|
||||
title: '## 🚀 Features and 🐛 Issues',
|
||||
labels: ['Never-Matching-Category'],
|
||||
empty_content: "- No PRs in this category"
|
||||
},
|
||||
{
|
||||
title: '## 🚀 Features',
|
||||
labels: ['Feature'],
|
||||
}
|
||||
]
|
||||
|
||||
const resultChangelog = buildChangelog(pullRequestsWithLabels, {
|
||||
owner: 'mikepenz',
|
||||
repo: 'test-repo',
|
||||
fromTag: '1.0.0',
|
||||
toTag: '2.0.0',
|
||||
includeOpen: false,
|
||||
failOnError: false,
|
||||
fetchReviewers: false,
|
||||
commitMode: false,
|
||||
configuration: customConfig
|
||||
})
|
||||
|
||||
expect(resultChangelog).toStrictEqual(
|
||||
`## 🚀 Features and 🐛 Issues\n\n- No PRs in this category\n\n## 🚀 Features\n\n- [ABC-1234] - this is a PR 1 title message\n - PR: #1\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n`
|
||||
)
|
||||
})
|
||||
|
||||
it('Commit SHA-1 in commitMode', async () => {
|
||||
const customConfig = Object.assign({}, DefaultConfiguration)
|
||||
customConfig.sort = "DESC"
|
||||
|
||||
+5
-2
@@ -1487,8 +1487,11 @@ function buildChangelog(prs, options) {
|
||||
for (const pr of pullRequests) {
|
||||
changelog = `${changelog + pr}\n`;
|
||||
}
|
||||
// add space between
|
||||
changelog = `${changelog}\n`;
|
||||
changelog = `${changelog}\n`; // add space between sections
|
||||
}
|
||||
else if (category.empty_content !== undefined) {
|
||||
changelog = `${changelog + category.title}\n\n`;
|
||||
changelog = `${changelog + category.empty_content}\n\n`;
|
||||
}
|
||||
}
|
||||
core.info(`✒️ Wrote ${categorizedPrs.length} categorized pull requests down`);
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -21,6 +21,7 @@ export interface Category {
|
||||
labels: string[] // labels to associate PRs to this category
|
||||
exclude_labels?: string[] // if an exclude label is detected, the PR will be excluded from this category
|
||||
exhaustive?: boolean // requires all labels to be present in the PR
|
||||
empty_content ?: string // if the category has no matching PRs, this content will be used. If not set, the category will be skipped in the changelog.
|
||||
}
|
||||
|
||||
export interface Sort {
|
||||
|
||||
+4
-3
@@ -183,9 +183,10 @@ export function buildChangelog(
|
||||
for (const pr of pullRequests) {
|
||||
changelog = `${changelog + pr}\n`
|
||||
}
|
||||
|
||||
// add space between
|
||||
changelog = `${changelog}\n`
|
||||
changelog = `${changelog}\n` // add space between sections
|
||||
} else if (category.empty_content !== undefined) {
|
||||
changelog = `${changelog + category.title}\n\n`
|
||||
changelog = `${changelog + category.empty_content}\n\n`
|
||||
}
|
||||
}
|
||||
core.info(`✒️ Wrote ${categorizedPrs.length} categorized pull requests down`)
|
||||
|
||||
Reference in New Issue
Block a user