Skip to content

Commit

Permalink
Merge pull request #1094 from mikepenz/develop
Browse files Browse the repository at this point in the history
merge dev into main
  • Loading branch information
mikepenz authored May 3, 2023
2 parents f7dd0f5 + 2b06a6b commit 342972d
Show file tree
Hide file tree
Showing 9 changed files with 649 additions and 471 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ This configuration is a `JSON` in the following format. (The below showcases *ex
"labels": ["test", "magic"],
"exclude_labels": ["no-magic"],
"exhaustive": true,
"exhaustive_rules": "false",
"empty_content": "- no matching PRs",
"rules": [
{
Expand Down Expand Up @@ -422,6 +423,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.exhaustive_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 () => {
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,
exhaustive_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
})
}
}
Loading

0 comments on commit 342972d

Please sign in to comment.