Merge pull request #685 from mikepenz/feature/681

Expand new configuration option `exclude_labels` to `Category`
This commit is contained in:
Mike Penz
2022-02-11 11:23:19 +01:00
committed by GitHub
6 changed files with 82 additions and 5 deletions
+11 -4
View File
@@ -166,7 +166,13 @@ 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,
}
],
"ignore_labels": [
@@ -307,9 +313,10 @@ Table of descriptions for the `configuration.json` options to configure the resu
| **Input** | **Description** |
|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| categories | An array of `category` specifications, offering a flexible way to group changes into categories |
| category.title | The display name of a category in the changelog |
| 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 |
| categories | An array of `category` specifications, offering a flexible way to group changes into categories. |
| category.title | The display name of a category in the changelog. |
| 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. |
| 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 | The sort order of pull requests. [ASC, DESC] |
+37
View File
@@ -448,4 +448,41 @@ it('Release Diff', async () => {
expect(resultChangelog).toStrictEqual(
`https://github.com/mikepenz/release-changelog-builder-action/compare/v2.8.0...v2.8.1`
)
})
it('Use exclude labels to not include a PR within a category.', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
{
title: '## 🚀 Features and 🐛 Issues',
labels: ['Feature', 'Issue'],
exhaustive: true
},
{
title: '## 🚀 Features and 🐛 Issues But No 🐛 Fixes',
labels: ['Feature', 'Issue'],
exclude_labels: ['Fix'],
exhaustive: true
},
{
title: '## 🚀 Features and/or 🐛 Issues But No 🐛 Fixes',
labels: ['Feature', 'Issue'],
exclude_labels: ['Fix']
}
]
const resultChangelog = buildChangelog(pullRequestsWithLabels, {
owner: 'mikepenz',
repo: 'test-repo',
fromTag: '1.0.0',
toTag: '2.0.0',
failOnError: false,
commitMode: false,
configuration: customConfig
})
expect(resultChangelog).toStrictEqual(
`## 🚀 Features and 🐛 Issues\n\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n## 🚀 Features and/or 🐛 Issues But No 🐛 Fixes\n\n- [ABC-1234] - this is a PR 1 title message\n - PR: #1\n\n`
)
})
Generated Vendored
+12
View File
@@ -1270,6 +1270,18 @@ function buildChangelog(prs, options) {
}
let matched = false;
for (const [category, pullRequests] of categorized) {
// check if any exclude label matches
if (category.exclude_labels !== undefined) {
if (haveCommonElements(category.exclude_labels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels)) {
if (core.isDebug()) {
const prNum = pr.number;
const prLabels = pr.labels;
const excludeLabels = JSON.stringify(category.exclude_labels);
core.debug(`PR ${prNum} with labels: ${prLabels} excluded from category via exclude label: ${excludeLabels}`);
}
continue; // one of the exclude labels matched, skip the PR for this category
}
}
if (category.exhaustive === true) {
if (haveEveryElements(category.labels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels)) {
pullRequests.push(body);
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -19,6 +19,7 @@ export interface Configuration {
export interface Category {
title: string // the title of this 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
}
+20
View File
@@ -111,6 +111,26 @@ export function buildChangelog(
let matched = false
for (const [category, pullRequests] of categorized) {
// check if any exclude label matches
if (category.exclude_labels !== undefined) {
if (
haveCommonElements(
category.exclude_labels.map(lbl => lbl.toLocaleLowerCase('en')),
pr.labels
)
) {
if (core.isDebug()) {
const prNum = pr.number
const prLabels = pr.labels
const excludeLabels = JSON.stringify(category.exclude_labels)
core.debug(
`PR ${prNum} with labels: ${prLabels} excluded from category via exclude label: ${excludeLabels}`
)
}
continue // one of the exclude labels matched, skip the PR for this category
}
}
if (category.exhaustive === true) {
if (
haveEveryElements(