Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
83 changes: 81 additions & 2 deletions __tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,46 @@ pullRequestsWithLabels.push(
}
)

const openPullRequestsWithLabels: PullRequestInfo[] = []
openPullRequestsWithLabels.push(
{
number: 6,
title: 'Still pending open pull request (Current)',
htmlURL: '',
baseBranch: '',
createdAt: moment(),
mergedAt: moment(),
mergeCommitSha: 'sha1',
author: 'Mike',
repoName: 'test-repo',
labels: new Set<string>().add('feature'),
milestone: '',
body: 'Some fancy body message',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
status: 'open'
},
{
number: 7,
title: 'Still pending open pull request',
htmlURL: '',
baseBranch: '',
createdAt: moment(),
mergedAt: moment(),
mergeCommitSha: 'sha1',
author: 'Mike',
repoName: 'test-repo',
labels: new Set<string>().add('feature'),
milestone: '',
body: 'Some fancy body message',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
status: 'open'
}
)

it('Match multiple labels exhaustive for category', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
Expand Down Expand Up @@ -534,8 +574,46 @@ it('Use Rules to get all open PRs in a Category.', async () => {
]
}
]
expect(buildChangelogTest(customConfig, prs)).toStrictEqual(`## Open PRs only\n\n- Still pending open pull request\n - PR: #6\n\n`)
})


it('Use Rules to get current open PR and merged categorised.', async () => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikepenz thanks for your support!

I have the feeling I am doing something wrong.... to check if the rules works correctly, i added a test. it seems that rules are combined with and logic and due to that, no output is generated in this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ps: sorry that my linter messed up :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikepenz to solve the issue, I introduced an additional configuration that allows to define whether rules are exclusive or not: category.exclusive_rules. When this value is not set, to guarantee backward compatibility, it is set to the same value as category.exhaustive.

I locally run tests, and all passes, including the one i defined.

let prs = Array.from(pullRequestsWithLabels)
prs = prs.concat(Array.from(openPullRequestsWithLabels))

const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
{
title: '## 🚀 Features',
labels: ['Feature'],
rules: [
{
pattern: '6',
on_property: 'number'
},
{
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true,
exclusive_rules: false
},{
title: '## 🐛 Issues',
labels: ['Issue'],
rules: [
{
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true
}
]

expect(buildChangelogTest(customConfig, prs)).toStrictEqual(
`## Open PRs only\n\n- Still pending open pull request\n - PR: #6\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 Expand Up @@ -571,6 +649,7 @@ it('Use Rules to get all open PRs in one Category and merged categorised.', asyn
)
})


function buildChangelogTest(config: Configuration, prs: PullRequestInfo[]): string {
return buildChangelog(DefaultDiffInfo, prs, {
owner: 'mikepenz',
Expand All @@ -585,4 +664,4 @@ function buildChangelogTest(config: Configuration, prs: PullRequestInfo[]): stri
commitMode: false,
configuration: config
})
}
}
3 changes: 3 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

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

/**
* Defines the properties of the PullRequestInfo useable in different configurations
*/
export type Property =
| 'number'
| 'title'
| 'branch'
| 'author'
Expand Down
4 changes: 3 additions & 1 deletion src/pullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,16 @@ export function compare(a: PullRequestInfo, b: PullRequestInfo, sort: Sort): num
* Helper function to retrieve a property from the PullRequestInfo
*/
export function retrieveProperty(pr: PullRequestInfo, property: Property, useCase: string): string {
let value: string | Set<string> | string[] | undefined = pr[property]
let value: string | number | Set<string> | string[] | undefined = pr[property]
if (value === undefined) {
core.warning(`⚠️ the provided property '${property}' for \`${useCase}\` is not valid. Fallback to 'body'`)
value = pr['body']
} else if (value instanceof Set) {
value = Array.from(value).join(',') // join into single string
} else if (Array.isArray(value)) {
value = value.join(',') // join into single string
} else {
value = value.toString()
}
return value
}
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