- 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:
Mike Penz
2022-07-08 10:40:47 +02:00
parent 9628cd4fe0
commit 89475f1193
6 changed files with 46 additions and 7 deletions
+3 -1
View File
@@ -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` |
+32
View File
@@ -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"
Generated Vendored
+5 -2
View File
@@ -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`);
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -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
View File
@@ -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`)