add possibility to configure if rules are and/or independently from labels

This commit is contained in:
Federico M. Facca
2023-05-03 17:50:51 +02:00
parent fa8d0100dc
commit 1794edb8f3
4 changed files with 17 additions and 8 deletions
+1
View File
@@ -422,6 +422,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. (See `exhaustive` to change this) | | 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. (See `exhaustive` to change this) |
| 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.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.exhaustive | Will require all labels defined within this category to be present on the matching PR. |
| category.exclusive_rules | Will require all rules defined within this category to be valid on the matching PR. If not defined, defaults to the value of `exhaustive` |
| 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. | | 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. |
| category.rules | An array of `rules` used to match PRs against. Any match will include the PR. (See `exhaustive` to change this) | | category.rules | An array of `rules` used to match PRs against. Any match will include the PR. (See `exhaustive` to change this) |
| category.rules.pattern | A `regex` pattern to match the property value towards. Uses `RegExp.test("val")` | | category.rules.pattern | A `regex` pattern to match the property value towards. Uses `RegExp.test("val")` |
+4 -5
View File
@@ -577,7 +577,7 @@ it('Use Rules to get all open PRs in a Category.', async () => {
it('Use Rules to get current open PR and merged categorised.', async () => { it('Use Rules to get current open PR and merged categorised.', async () => {
let prs = Array.from(pullRequestsWithLabels) let prs = Array.from(pullRequestsWithLabels)
prs.concat(Array.from(openPullRequestsWithLabels)) prs = prs.concat(Array.from(openPullRequestsWithLabels))
const customConfig = Object.assign({}, DefaultConfiguration) const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [ customConfig.categories = [
@@ -594,7 +594,8 @@ it('Use Rules to get current open PR and merged categorised.', async () => {
on_property: 'status' on_property: 'status'
} }
], ],
exhaustive: true exhaustive: true,
exclusive_rules: false
},{ },{
title: '## 🐛 Issues', title: '## 🐛 Issues',
labels: ['Issue'], labels: ['Issue'],
@@ -608,10 +609,8 @@ it('Use Rules to get current open PR and merged categorised.', async () => {
} }
] ]
console.log(buildChangelogTest(customConfig, prs))
expect(buildChangelogTest(customConfig, prs)).toStrictEqual( expect(buildChangelogTest(customConfig, prs)).toStrictEqual(
`## 🚀 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- Still pending open pull request\n - PR: #6\n\n## 🐛 Issues\n\n- [ABC-4321] - this is a PR 2 title message\n - PR: #2\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n` `## 🚀 Features\n\n- [ABC-1234] - this is a PR 1 title message\n - PR: #1\n- Still pending open pull request (Current)\n - PR: #6\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n## 🐛 Issues\n\n- [ABC-4321] - this is a PR 2 title message\n - PR: #2\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n`
) )
}) })
+2 -1
View File
@@ -23,7 +23,8 @@ export interface Category {
labels?: string[] // labels to associate PRs to 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 exclude_labels?: string[] // if an exclude label is detected, the PR will be excluded from this category
rules?: Rule[] // rules to associate PRs to this category rules?: Rule[] // rules to associate PRs to this category
exhaustive?: boolean // requires all labels AND/OR rules to be present in the PR exhaustive?: boolean // requires all labels to be present in the PR
exclusive_rules?: boolean // requires all rules to be present in the PR (if not set, defaults to exhaustive value)
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. 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.
} }
+10 -2
View File
@@ -133,8 +133,12 @@ export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], optio
pr.labels pr.labels
) )
} }
let exclusive_rules = true
if (category.exclusive_rules !== undefined) {
exclusive_rules = category.exclusive_rules
}
if (matched && category.rules !== undefined) { if (matched && category.rules !== undefined) {
matched = matchesRules(category.rules, pr, true) matched = matchesRules(category.rules, pr, exclusive_rules)
} }
} else { } else {
// if not exhaustive, do individual matches // if not exhaustive, do individual matches
@@ -145,9 +149,13 @@ export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], optio
pr.labels pr.labels
) )
} }
let exclusive_rules = false
if (category.exclusive_rules !== undefined) {
exclusive_rules = category.exclusive_rules
}
if (!matched && category.rules !== undefined) { if (!matched && category.rules !== undefined) {
// if no label did apply, check if any rule applies // if no label did apply, check if any rule applies
matched = matchesRules(category.rules, pr, false) matched = matchesRules(category.rules, pr, exclusive_rules)
} }
} }
if (matched) { if (matched) {