Skip to content

Commit

Permalink
- expand custom assignment and add testcase to verify ability to cons…
Browse files Browse the repository at this point in the history
…truct custom categories involving states of PRs
  • Loading branch information
mikepenz committed Apr 8, 2022
1 parent 6211ea4 commit f60b8b4
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 10 deletions.
29 changes: 28 additions & 1 deletion __tests__/releaseNotesBuilder.test.ts
Expand Up @@ -263,4 +263,31 @@ it('Verify default inclusion of open PRs', async () => {
expect(changeLog).toStrictEqual(
`## 🚀 Features\n\n- A feature to be going to v2 (nr3) (#3) merged\n- New feature to keep open (nr5) (#7) open\n\n\n\n\nUncategorized\n\n\n\nOpen\n- New feature to keep open (nr5) (#7) open\n`
)
})
})

it('Verify custom categorisation of open PRs', async () => {
const configuration = resolveConfiguration(
'',
'configs_test/configuration_excluding_open.json'
)
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
null, // token
'.', // repoPath
'mikepenz', // user
'release-changelog-builder-action-playground', // repo
'1.5.0', // fromTag
'2.0.0', // toTag
true, // includeOpen
false, // failOnError
false, // ignorePrePrelease
false, // commitMode
configuration // configuration
)

const changeLog = await releaseNotesBuilder.build()
console.log(changeLog)
expect(changeLog).toStrictEqual(
`## 🚀 Features Merged\n\n- A feature to be going to v2 (nr3) -- (#3) [merged] {feature}\n\n## 🚀 Features Open\n\n- New feature to keep open (nr5) -- (#7) [open] {feature}\n\n`
)
})
16 changes: 16 additions & 0 deletions configs_test/configuration_excluding_open.json
@@ -0,0 +1,16 @@
{
"categories": [
{
"title": "## 🚀 Features Merged",
"labels": ["feature"],
"exclude_labels": ["--rcba-open"]
},
{
"title": "## 🚀 Features Open",
"labels": ["feature", "--rcba-open"],
"exhaustive": true
}
],
"template": "${{CHANGELOG}}",
"pr_template": "- ${{TITLE}} -- (#${{NUMBER}}) [${{STATUS}}] {${{LABELS}}}"
}
8 changes: 4 additions & 4 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.

10 changes: 7 additions & 3 deletions src/pullRequests.ts
Expand Up @@ -160,8 +160,11 @@ export function sortPullRequests(
}

// helper function to add a special open label to prs not merged.
function addOpenLabel(labels: Set<string>): Set<string> {
labels.add('##rcba-open')
function attachSpeciaLabels(
status: 'open' | 'merged',
labels: Set<string>
): Set<string> {
labels.add(`--rcba-${status}`)
return labels
}

Expand All @@ -178,7 +181,8 @@ const mapPullRequest = (
mergeCommitSha: pr.merge_commit_sha || '',
author: pr.user?.login || '',
repoName: pr.base.repo.full_name,
labels: addOpenLabel(
labels: attachSpeciaLabels(
status,
new Set(
pr.labels?.map(lbl => lbl.name?.toLocaleLowerCase('en') || '') || []
)
Expand Down
2 changes: 1 addition & 1 deletion src/transform.ts
Expand Up @@ -323,7 +323,7 @@ function fillTemplate(pr: PullRequestInfo, template: string): string {
transformed = transformed.replace(/\${{AUTHOR}}/g, pr.author)
transformed = transformed.replace(
/\${{LABELS}}/g,
[...pr.labels]?.filter(l => !l.startsWith('##rcba-'))?.join(', ') || ''
[...pr.labels]?.filter(l => !l.startsWith('--rcba-'))?.join(', ') || ''
)
transformed = transformed.replace(/\${{MILESTONE}}/g, pr.milestone || '')
transformed = transformed.replace(/\${{BODY}}/g, pr.body)
Expand Down

0 comments on commit f60b8b4

Please sign in to comment.