Skip to content

Commit

Permalink
add possibility to configure if rules are and/or independently from l…
Browse files Browse the repository at this point in the history
…abels
  • Loading branch information
chicco785 committed May 3, 2023
1 parent fa8d010 commit 1794edb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.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.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")` |
Expand Down
9 changes: 4 additions & 5 deletions __tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
let prs = Array.from(pullRequestsWithLabels)
prs.concat(Array.from(openPullRequestsWithLabels))
prs = prs.concat(Array.from(openPullRequestsWithLabels))

const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
Expand All @@ -594,7 +594,8 @@ it('Use Rules to get current open PR and merged categorised.', async () => {
on_property: 'status'
}
],
exhaustive: true
exhaustive: true,
exclusive_rules: false
},{
title: '## 🐛 Issues',
labels: ['Issue'],
Expand All @@ -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(
`## 🚀 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`
)
})

Expand Down
3 changes: 2 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ 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
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.
}

Expand Down
12 changes: 10 additions & 2 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], optio
pr.labels
)
}
let exclusive_rules = true
if (category.exclusive_rules !== undefined) {
exclusive_rules = category.exclusive_rules
}
if (matched && category.rules !== undefined) {
matched = matchesRules(category.rules, pr, true)
matched = matchesRules(category.rules, pr, exclusive_rules)
}
} else {
// if not exhaustive, do individual matches
Expand All @@ -145,9 +149,13 @@ export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], optio
pr.labels
)
}
let exclusive_rules = false
if (category.exclusive_rules !== undefined) {
exclusive_rules = category.exclusive_rules
}
if (!matched && category.rules !== undefined) {
// 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) {
Expand Down

0 comments on commit 1794edb

Please sign in to comment.