- introduce test cases for transform.test.ts
- add test case to highlight label extractor feature FIX https://github.com/mikepenz/release-changelog-builder-action/issues/450 - test cases can easily be run via `npm test -- transform.test.ts` - slightly simplify releaseNotes.ts and transform.ts
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
import {buildChangelog} from '../src/transform'
|
||||
import { PullRequestInfo } from '../src/pullRequests'
|
||||
import moment from 'moment'
|
||||
import { DefaultConfiguration } from '../src/configuration';
|
||||
|
||||
jest.setTimeout(180000)
|
||||
|
||||
let configuration = DefaultConfiguration
|
||||
configuration.categories = [
|
||||
{
|
||||
"title": "## 🚀 Features",
|
||||
"labels": ["[Feature]"]
|
||||
},
|
||||
{
|
||||
"title": "## 🐛 Fixes",
|
||||
"labels": ["[Bug]", "[Issue]"]
|
||||
},
|
||||
{
|
||||
"title": "## 🧪 Tests",
|
||||
"labels": ["[Test]"]
|
||||
}
|
||||
]
|
||||
|
||||
let mergedPullRequests: PullRequestInfo[] = []
|
||||
mergedPullRequests.push({
|
||||
number: 1,
|
||||
title: "[Feature][AB-1234] - this is a PR 1 title message",
|
||||
htmlURL: "",
|
||||
baseBranch: "",
|
||||
mergedAt: moment(),
|
||||
mergeCommitSha: "sha1",
|
||||
author: "Mike",
|
||||
repoName: "test-repo",
|
||||
labels: new Set<string>(),
|
||||
milestone: "",
|
||||
body: "no magic body for this matter",
|
||||
assignees: [],
|
||||
requestedReviewers: []
|
||||
}, {
|
||||
number: 2,
|
||||
title: "[Issue][AB-4321] - this is a PR 2 title message",
|
||||
htmlURL: "",
|
||||
baseBranch: "",
|
||||
mergedAt: moment(),
|
||||
mergeCommitSha: "sha1",
|
||||
author: "Mike",
|
||||
repoName: "test-repo",
|
||||
labels: new Set<string>(),
|
||||
milestone: "",
|
||||
body: "no magic body for this matter",
|
||||
assignees: [],
|
||||
requestedReviewers: []
|
||||
}, {
|
||||
number: 3,
|
||||
title: "[Issue][Feature][AB-1234321] - this is a PR 3 title message",
|
||||
htmlURL: "",
|
||||
baseBranch: "",
|
||||
mergedAt: moment(),
|
||||
mergeCommitSha: "sha1",
|
||||
author: "Mike",
|
||||
repoName: "test-repo",
|
||||
labels: new Set<string>(),
|
||||
milestone: "",
|
||||
body: "no magic body for this matter",
|
||||
assignees: [],
|
||||
requestedReviewers: []
|
||||
}, {
|
||||
number: 4,
|
||||
title: "[AB-404] - not found label",
|
||||
htmlURL: "",
|
||||
baseBranch: "",
|
||||
mergedAt: moment(),
|
||||
mergeCommitSha: "sha1",
|
||||
author: "Mike",
|
||||
repoName: "test-repo",
|
||||
labels: new Set<string>(),
|
||||
milestone: "",
|
||||
body: "no magic body for this matter",
|
||||
assignees: [],
|
||||
requestedReviewers: []
|
||||
})
|
||||
|
||||
it('Extract label from title, combined regex', async () => {
|
||||
configuration.label_extractor = [
|
||||
{
|
||||
"pattern": ".*(\\[Feature\\]|\\[Issue\\]).*",
|
||||
"target": "$1",
|
||||
"on_property": "title"
|
||||
}
|
||||
]
|
||||
|
||||
const resultChangelog = buildChangelog(
|
||||
mergedPullRequests,
|
||||
{
|
||||
owner: "mikepenz",
|
||||
repo: "test-repo",
|
||||
fromTag: "1.0.0",
|
||||
toTag: "2.0.0",
|
||||
failOnError: false,
|
||||
commitMode: false,
|
||||
configuration: configuration
|
||||
}
|
||||
)
|
||||
|
||||
expect(resultChangelog).toStrictEqual(`## 🚀 Features\n\n- [Feature][AB-1234] - this is a PR 1 title message\n - PR: #1\n- [Issue][Feature][AB-1234321] - this is a PR 3 title message\n - PR: #3\n\n## 🐛 Fixes\n\n- [Issue][AB-4321] - this is a PR 2 title message\n - PR: #2\n\n`)
|
||||
})
|
||||
|
||||
it('Extract label from title, split regex', async () => {
|
||||
configuration.label_extractor = [
|
||||
{
|
||||
"pattern": ".*(\\[Feature\\]).*",
|
||||
"target": "$1",
|
||||
"on_property": "title"
|
||||
},
|
||||
{
|
||||
"pattern": ".*(\\[Issue\\]).*",
|
||||
"target": "$1",
|
||||
"on_property": "title"
|
||||
}
|
||||
]
|
||||
|
||||
const resultChangelog = buildChangelog(
|
||||
mergedPullRequests,
|
||||
{
|
||||
owner: "mikepenz",
|
||||
repo: "test-repo",
|
||||
fromTag: "1.0.0",
|
||||
toTag: "2.0.0",
|
||||
failOnError: false,
|
||||
commitMode: false,
|
||||
configuration: configuration
|
||||
}
|
||||
)
|
||||
|
||||
expect(resultChangelog).toStrictEqual(`## 🚀 Features\n\n- [Feature][AB-1234] - this is a PR 1 title message\n - PR: #1\n- [Issue][Feature][AB-1234321] - this is a PR 3 title message\n - PR: #3\n\n## 🐛 Fixes\n\n- [Issue][AB-4321] - this is a PR 2 title message\n - PR: #2\n- [Issue][Feature][AB-1234321] - this is a PR 3 title message\n - PR: #3\n\n`)
|
||||
})
|
||||
+42
-1282
File diff suppressed because it is too large
Load Diff
+1
-1
File diff suppressed because one or more lines are too long
+1
-7
@@ -20,8 +20,6 @@ export class ReleaseNotes {
|
||||
constructor(private octokit: Octokit, private options: ReleaseNotesOptions) {}
|
||||
|
||||
async pull(): Promise<string | null> {
|
||||
const {configuration} = this.options
|
||||
|
||||
let mergedPullRequests: PullRequestInfo[]
|
||||
if (!this.options.commitMode) {
|
||||
core.startGroup(`🚀 Load pull requests`)
|
||||
@@ -40,11 +38,7 @@ export class ReleaseNotes {
|
||||
}
|
||||
|
||||
core.startGroup('📦 Build changelog')
|
||||
const resultChangelog = buildChangelog(
|
||||
mergedPullRequests,
|
||||
configuration,
|
||||
this.options
|
||||
)
|
||||
const resultChangelog = buildChangelog(mergedPullRequests, this.options)
|
||||
core.endGroup()
|
||||
return resultChangelog
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import {
|
||||
Category,
|
||||
Configuration,
|
||||
DefaultConfiguration,
|
||||
Extractor,
|
||||
Transformer
|
||||
@@ -11,10 +10,10 @@ import {ReleaseNotesOptions} from './releaseNotes'
|
||||
|
||||
export function buildChangelog(
|
||||
prs: PullRequestInfo[],
|
||||
config: Configuration,
|
||||
options: ReleaseNotesOptions
|
||||
): string {
|
||||
// sort to target order
|
||||
const config = options.configuration
|
||||
const sort = config.sort || DefaultConfiguration.sort
|
||||
const sortAsc = sort.toUpperCase() === 'ASC'
|
||||
prs = sortPullRequests(prs, sortAsc)
|
||||
|
||||
Reference in New Issue
Block a user