Merge pull request #458 from mikepenz/develop

dev -> main
This commit is contained in:
Mike Penz
2021-08-27 13:55:44 +02:00
committed by GitHub
14 changed files with 574 additions and 298 deletions
+11 -4
View File
@@ -175,11 +175,16 @@ This configuration is a `.json` file in the following format.
"flags": "gu" "flags": "gu"
}, },
{ {
"pattern": "(.) (.+)", "pattern": "\\[Issue\\]",
"target": "$1", "on_property": "title",
"on_property": "title" "method": "match"
} }
], ],
"duplicate_filter": {
"pattern": "\\[ABC-....\\]",
"on_property": "title",
"method": "match"
},
"transformers": [ "transformers": [
{ {
"pattern": "[\\-\\*] (\\[(...|TEST|CI|SKIP)\\])( )?(.+?)\n(.+?[\\-\\*] )(.+)", "pattern": "[\\-\\*] (\\[(...|TEST|CI|SKIP)\\])( )?(.+?)\n(.+?[\\-\\*] )(.+)",
@@ -290,17 +295,19 @@ Table of descriptions for the `configuration.json` options to configure the resu
| categories | An array of `category` specifications, offering a flexible way to group changes into categories | | categories | An array of `category` specifications, offering a flexible way to group changes into categories |
| category.title | The display name of a category in the changelog | | category.title | The display name of a category in the changelog |
| 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 | | 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 |
| category.exhaustive | Will require all labels defined within this category to be present on the matching PR. |
| ignore_labels | An array of labels, to match pull request labels against. If any PR label overlaps, the pull request will be ignored from the changelog. This takes precedence over category labels | | ignore_labels | An array of labels, to match pull request labels against. If any PR label overlaps, the pull request will be ignored from the changelog. This takes precedence over category labels |
| sort | The sort order of pull requests. [ASC, DESC] | | sort | The sort order of pull requests. [ASC, DESC] |
| template | Specifies the global template to pick for creating the changelog. See [Template placeholders](#template-placeholders) for possible values | | template | Specifies the global template to pick for creating the changelog. See [Template placeholders](#template-placeholders) for possible values |
| pr_template | Defines the per pull request template. See [PR Template placeholders](#pr-template-placeholders) for possible values | | pr_template | Defines the per pull request template. See [PR Template placeholders](#pr-template-placeholders) for possible values |
| empty_template | Template to pick if no changes are detected. See [Template placeholders](#template-placeholders) for possible values | | empty_template | Template to pick if no changes are detected. See [Template placeholders](#template-placeholders) for possible values |
| label_extractor | An array of `transform` specifications, offering a flexible API to extract additinal labels from a PR (Default: `body`, Default in commit mode: `commit message`). | | label_extractor | An array of `Extractor` specifications, offering a flexible API to extract additinal labels from a PR (Default: `body`, Default in commit mode: `commit message`). |
| label_extractor.pattern | A `regex` pattern, extracting values of the change message. | | label_extractor.pattern | A `regex` pattern, extracting values of the change message. |
| label_extractor.target | The result pattern. The result text will be used as label. If empty, no label is created. (Unused for `match` method) | | label_extractor.target | The result pattern. The result text will be used as label. If empty, no label is created. (Unused for `match` method) |
| label_extractor.on_property | The property to retrieve the text from. This is optional. Defaults to: `body`. Alternative values: `title`, `author`, `milestone`. | | label_extractor.on_property | The property to retrieve the text from. This is optional. Defaults to: `body`. Alternative values: `title`, `author`, `milestone`. |
| label_extractor.method | The extraction method used. Defaults to: `replace`. Alternative value: `match`. The method specified references the JavaScript String method. | | label_extractor.method | The extraction method used. Defaults to: `replace`. Alternative value: `match`. The method specified references the JavaScript String method. |
| label_extractor.flags | Defines the regex flags specified for the pattern. Default: `gu` | | label_extractor.flags | Defines the regex flags specified for the pattern. Default: `gu` |
| duplicate_filter | Defines the `Extractor` to use for retrieving the identifier for a PR. In case of duplicates will keep the last matching pull request (depends on `sort`). See `label_extractor` for details on `Extractor` properties. |
| transformers | An array of `transform` specifications, offering a flexible API to modify the text per pull request. This is applied on the change text created with `pr_template`. `transformers` are executed per change, in the order specified | | transformers | An array of `transform` specifications, offering a flexible API to modify the text per pull request. This is applied on the change text created with `pr_template`. `transformers` are executed per change, in the order specified |
| transformer.pattern | A `regex` pattern, extracting values of the change message. | | transformer.pattern | A `regex` pattern, extracting values of the change message. |
| transformer.target | The result pattern, the regex groups will be filled into. Allows for full transformation of a pull request message. Including potentially specified texts | | transformer.target | The result pattern, the regex groups will be filled into. Allows for full transformation of a pull request message. Including potentially specified texts |
+2 -2
View File
@@ -54,9 +54,9 @@ test('should write result to file', () => {
// should succeed // should succeed
expect(result).toBeDefined() expect(result).toBeDefined()
const readOutput = fs.readFileSync("test.md") const readOutput = fs.readFileSync('test.md')
fs.unlinkSync("test.md") fs.unlinkSync('test.md')
expect(readOutput.toString()).not.toBe('') expect(readOutput.toString()).not.toBe('')
}) })
+8 -8
View File
@@ -18,7 +18,7 @@ it('Should have empty changelog (tags)', async () => {
toTag: 'v0.0.2', toTag: 'v0.0.2',
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: configuration configuration
}) })
const changeLog = await releaseNotes.pull() const changeLog = await releaseNotes.pull()
@@ -35,7 +35,7 @@ it('Should match generated changelog (tags)', async () => {
toTag: 'v0.0.3', toTag: 'v0.0.3',
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: configuration configuration
}) })
const changeLog = await releaseNotes.pull() const changeLog = await releaseNotes.pull()
@@ -60,7 +60,7 @@ it('Should match generated changelog (refs)', async () => {
toTag: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa', toTag: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa',
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: configuration configuration
}) })
const changeLog = await releaseNotes.pull() const changeLog = await releaseNotes.pull()
@@ -93,7 +93,7 @@ it('Should match generated changelog and replace all occurrences (refs)', async
toTag: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa', toTag: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa',
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: configuration configuration
}) })
const changeLog = await releaseNotes.pull() const changeLog = await releaseNotes.pull()
@@ -128,7 +128,7 @@ it('Should match ordered ASC', async () => {
toTag: 'v0.5.0', toTag: 'v0.5.0',
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: configuration configuration
}) })
const changeLog = await releaseNotes.pull() const changeLog = await releaseNotes.pull()
@@ -150,7 +150,7 @@ it('Should match ordered DESC', async () => {
toTag: 'v0.5.0', toTag: 'v0.5.0',
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: configuration configuration
}) })
const changeLog = await releaseNotes.pull() const changeLog = await releaseNotes.pull()
@@ -172,7 +172,7 @@ it('Should ignore PRs not merged into develop branch', async () => {
toTag: 'v1.4.0', toTag: 'v1.4.0',
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: configuration configuration
}) })
const changeLog = await releaseNotes.pull() const changeLog = await releaseNotes.pull()
@@ -192,7 +192,7 @@ it('Should ignore PRs not merged into main branch', async () => {
toTag: 'v1.4.0', toTag: 'v1.4.0',
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: configuration configuration
}) })
const changeLog = await releaseNotes.pull() const changeLog = await releaseNotes.pull()
+3 -3
View File
@@ -45,7 +45,9 @@ it('Should match generated changelog (unspecified tags)', async () => {
const changeLog = await releaseNotesBuilder.build() const changeLog = await releaseNotesBuilder.build()
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🐛 Fixes\n\n- Stacktrace Data can be an array\n - PR: #39\n\n`) expect(changeLog).toStrictEqual(
`## 🐛 Fixes\n\n- Stacktrace Data can be an array\n - PR: #39\n\n`
)
}) })
it('Should use empty placeholder', async () => { it('Should use empty placeholder', async () => {
@@ -168,7 +170,6 @@ it('Uncategorized category', async () => {
) )
}) })
it('Verify commit based changelog', async () => { it('Verify commit based changelog', async () => {
const configuration = resolveConfiguration( const configuration = resolveConfiguration(
'', '',
@@ -194,7 +195,6 @@ it('Verify commit based changelog', async () => {
) )
}) })
it('Verify commit based changelog, with emoji categorisation', async () => { it('Verify commit based changelog, with emoji categorisation', async () => {
const configuration = resolveConfiguration( const configuration = resolveConfiguration(
'', '',
+260 -111
View File
@@ -1,191 +1,340 @@
import {buildChangelog} from '../src/transform' import {buildChangelog} from '../src/transform'
import { PullRequestInfo } from '../src/pullRequests' import {PullRequestInfo} from '../src/pullRequests'
import moment from 'moment' import moment from 'moment'
import { DefaultConfiguration } from '../src/configuration'; import { DefaultConfiguration, Configuration } from '../src/configuration';
jest.setTimeout(180000) jest.setTimeout(180000)
let configuration = DefaultConfiguration const configuration = Object.assign({}, DefaultConfiguration)
configuration.categories = [ configuration.categories = [
{ {
"title": "## 🚀 Features", title: '## 🚀 Features',
"labels": ["[Feature]"] labels: ['[Feature]']
}, },
{ {
"title": "## 🐛 Fixes", title: '## 🐛 Fixes',
"labels": ["[Bug]", "[Issue]"] labels: ['[Bug]', '[Issue]']
}, },
{ {
"title": "## 🧪 Tests", title: '## 🧪 Tests',
"labels": ["[Test]"] labels: ['[Test]']
} }
] ]
let mergedPullRequests: PullRequestInfo[] = [] // list of PRs without labels assigned (extract from title)
mergedPullRequests.push({ const mergedPullRequests: PullRequestInfo[] = []
mergedPullRequests.push(
{
number: 1, number: 1,
title: "[Feature][AB-1234] - this is a PR 1 title message", title: '[Feature][AB-1234] - this is a PR 1 title message',
htmlURL: "", htmlURL: '',
baseBranch: "", baseBranch: '',
mergedAt: moment(), mergedAt: moment(),
mergeCommitSha: "sha1", mergeCommitSha: 'sha1',
author: "Mike", author: 'Mike',
repoName: "test-repo", repoName: 'test-repo',
labels: new Set<string>(), labels: new Set<string>(),
milestone: "", milestone: '',
body: "no magic body for this matter", body: 'no magic body for this matter',
assignees: [], assignees: [],
requestedReviewers: [] requestedReviewers: []
}, { },
{
number: 2, number: 2,
title: "[Issue][AB-4321] - this is a PR 2 title message", title: '[Issue][AB-4321] - this is a PR 2 title message',
htmlURL: "", htmlURL: '',
baseBranch: "", baseBranch: '',
mergedAt: moment(), mergedAt: moment(),
mergeCommitSha: "sha1", mergeCommitSha: 'sha1',
author: "Mike", author: 'Mike',
repoName: "test-repo", repoName: 'test-repo',
labels: new Set<string>(), labels: new Set<string>(),
milestone: "", milestone: '',
body: "no magic body for this matter", body: 'no magic body for this matter',
assignees: [], assignees: [],
requestedReviewers: [] requestedReviewers: []
}, { },
{
number: 3, number: 3,
title: "[Issue][Feature][AB-1234321] - this is a PR 3 title message", title: '[Issue][Feature][AB-1234321] - this is a PR 3 title message',
htmlURL: "", htmlURL: '',
baseBranch: "", baseBranch: '',
mergedAt: moment(), mergedAt: moment(),
mergeCommitSha: "sha1", mergeCommitSha: 'sha1',
author: "Mike", author: 'Mike',
repoName: "test-repo", repoName: 'test-repo',
labels: new Set<string>(), labels: new Set<string>(),
milestone: "", milestone: '',
body: "no magic body for this matter", body: 'no magic body for this matter',
assignees: [], assignees: [],
requestedReviewers: [] requestedReviewers: []
}, { },
{
number: 4, number: 4,
title: "[AB-404] - not found label", title: '[AB-404] - not found label',
htmlURL: "", htmlURL: '',
baseBranch: "", baseBranch: '',
mergedAt: moment(), mergedAt: moment(),
mergeCommitSha: "sha1", mergeCommitSha: 'sha1',
author: "Mike", author: 'Mike',
repoName: "test-repo", repoName: 'test-repo',
labels: new Set<string>(), labels: new Set<string>(),
milestone: "", milestone: '',
body: "no magic body for this matter", body: 'no magic body for this matter',
assignees: [], assignees: [],
requestedReviewers: [] requestedReviewers: []
}) }
)
it('Extract label from title, combined regex', async () => { it('Extract label from title, combined regex', async () => {
configuration.label_extractor = [ configuration.label_extractor = [
{ {
"pattern": ".*(\\[Feature\\]|\\[Issue\\]).*", pattern: '.*(\\[Feature\\]|\\[Issue\\]).*',
"target": "$1", target: '$1',
"on_property": "title" on_property: 'title'
} }
] ]
const resultChangelog = buildChangelog( const resultChangelog = buildChangelog(mergedPullRequests, {
mergedPullRequests, owner: 'mikepenz',
{ repo: 'test-repo',
owner: "mikepenz", fromTag: '1.0.0',
repo: "test-repo", toTag: '2.0.0',
fromTag: "1.0.0",
toTag: "2.0.0",
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: 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`) 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 () => { it('Extract label from title, split regex', async () => {
configuration.label_extractor = [ configuration.label_extractor = [
{ {
"pattern": ".*(\\[Feature\\]).*", pattern: '.*(\\[Feature\\]).*',
"target": "$1", target: '$1',
"on_property": "title" on_property: 'title'
}, },
{ {
"pattern": ".*(\\[Issue\\]).*", pattern: '.*(\\[Issue\\]).*',
"target": "$1", target: '$1',
"on_property": "title" on_property: 'title'
} }
] ]
const resultChangelog = buildChangelog( const resultChangelog = buildChangelog(mergedPullRequests, {
mergedPullRequests, owner: 'mikepenz',
{ repo: 'test-repo',
owner: "mikepenz", fromTag: '1.0.0',
repo: "test-repo", toTag: '2.0.0',
fromTag: "1.0.0",
toTag: "2.0.0",
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: 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`) 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`
)
}) })
it('Extract label from title, match', async () => { it('Extract label from title, match', async () => {
configuration.label_extractor = [ configuration.label_extractor = [
{ {
"pattern": "\\[Feature\\]", pattern: '\\[Feature\\]',
"on_property": "title", on_property: 'title',
"method": "match" method: 'match'
}, },
{ {
"pattern": "\\[Issue\\]", pattern: '\\[Issue\\]',
"on_property": "title", on_property: 'title',
"method": "match" method: 'match'
} }
] ]
const resultChangelog = buildChangelog( const resultChangelog = buildChangelog(mergedPullRequests, {
mergedPullRequests, owner: 'mikepenz',
{ repo: 'test-repo',
owner: "mikepenz", fromTag: '1.0.0',
repo: "test-repo", toTag: '2.0.0',
fromTag: "1.0.0",
toTag: "2.0.0",
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: 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`) 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`
)
}) })
it('Extract label from title, match multiple', async () => { it('Extract label from title, match multiple', async () => {
configuration.label_extractor = [ configuration.label_extractor = [
{ {
"pattern": "\\[Feature\\]|\\[Issue\\]", pattern: '\\[Feature\\]|\\[Issue\\]',
"on_property": "title", on_property: 'title',
"method": "match" method: 'match'
} }
] ]
const resultChangelog = buildChangelog( const resultChangelog = buildChangelog(mergedPullRequests, {
mergedPullRequests, owner: 'mikepenz',
{ repo: 'test-repo',
owner: "mikepenz", fromTag: '1.0.0',
repo: "test-repo", toTag: '2.0.0',
fromTag: "1.0.0",
toTag: "2.0.0",
failOnError: false, failOnError: false,
commitMode: false, commitMode: false,
configuration: 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`) 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`
)
})
// test set of PRs with lables predefined
const pullRequestsWithLabels: PullRequestInfo[] = []
pullRequestsWithLabels.push(
{
number: 1,
title: '[ABC-1234] - this is a PR 1 title message',
htmlURL: '',
baseBranch: '',
mergedAt: moment(),
mergeCommitSha: 'sha1',
author: 'Mike',
repoName: 'test-repo',
labels: new Set<string>().add('feature'),
milestone: '',
body: 'no magic body for this matter',
assignees: [],
requestedReviewers: []
},
{
number: 2,
title: '[ABC-4321] - this is a PR 2 title message',
htmlURL: '',
baseBranch: '',
mergedAt: moment(),
mergeCommitSha: 'sha1',
author: 'Mike',
repoName: 'test-repo',
labels: new Set<string>().add('issue').add('fix'),
milestone: '',
body: 'no magic body for this matter',
assignees: [],
requestedReviewers: []
},
{
number: 3,
title: '[ABC-1234] - this is a PR 3 title message',
htmlURL: '',
baseBranch: '',
mergedAt: moment().add(1, 'days'),
mergeCommitSha: 'sha1',
author: 'Mike',
repoName: 'test-repo',
labels: new Set<string>().add('issue').add('feature').add('fix'),
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>().add(''),
milestone: '',
body: 'no magic body for this matter',
assignees: [],
requestedReviewers: []
}
)
it('Match multiple labels exhaustive for category', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
{
title: '## 🚀 Features and 🐛 Issues',
labels: ['Feature', 'Issue'],
exhaustive: true
},
{
title: '## 🚀 Features',
labels: ['Feature', 'Feature2'],
exhaustive: true
},
{
title: '## 🐛 Fixes',
labels: ['Issue', 'Issue2'],
exhaustive: true
}
]
const resultChangelog = buildChangelog(pullRequestsWithLabels, {
owner: 'mikepenz',
repo: 'test-repo',
fromTag: '1.0.0',
toTag: '2.0.0',
failOnError: false,
commitMode: false,
configuration: customConfig
})
expect(resultChangelog).toStrictEqual(
`## 🚀 Features and 🐛 Issues\n\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n`
)
})
it('Deduplicate duplicated PRs', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.duplicate_filter = {
pattern: '\\[ABC-....\\]',
on_property: 'title',
method: 'match'
}
const resultChangelog = buildChangelog(pullRequestsWithLabels, {
owner: 'mikepenz',
repo: 'test-repo',
fromTag: '1.0.0',
toTag: '2.0.0',
failOnError: false,
commitMode: false,
configuration: customConfig
})
expect(resultChangelog).toStrictEqual(
`## 🚀 Features\n\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n## 🐛 Fixes\n\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n- [ABC-4321] - this is a PR 2 title message\n - PR: #2\n\n`
)
})
it('Deduplicate duplicated PRs DESC', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.sort = "DESC"
customConfig.duplicate_filter = {
pattern: '\\[ABC-....\\]',
on_property: 'title',
method: 'match'
}
const resultChangelog = buildChangelog(pullRequestsWithLabels, {
owner: 'mikepenz',
repo: 'test-repo',
fromTag: '1.0.0',
toTag: '2.0.0',
failOnError: false,
commitMode: false,
configuration: customConfig
})
expect(resultChangelog).toStrictEqual(
`## 🚀 Features\n\n- [ABC-1234] - this is a PR 1 title message\n - PR: #1\n\n## 🐛 Fixes\n\n- [ABC-4321] - this is a PR 2 title message\n - PR: #2\n\n`
)
}) })
Generated Vendored
+105 -55
View File
@@ -80,7 +80,7 @@ class Commits {
sha: commit.sha || '', sha: commit.sha || '',
summary: commit.commit.message.split('\n')[0], summary: commit.commit.message.split('\n')[0],
message: commit.commit.message, message: commit.commit.message,
date: moment_1.default((_a = commit.commit.committer) === null || _a === void 0 ? void 0 : _a.date), date: (0, moment_1.default)((_a = commit.commit.committer) === null || _a === void 0 ? void 0 : _a.date),
author: ((_b = commit.commit.author) === null || _b === void 0 ? void 0 : _b.name) || '', author: ((_b = commit.commit.author) === null || _b === void 0 ? void 0 : _b.name) || '',
prNumber: undefined prNumber: undefined
}); });
@@ -169,6 +169,7 @@ exports.DefaultConfiguration = {
], ],
ignore_labels: ['ignore'], ignore_labels: ['ignore'],
label_extractor: [], label_extractor: [],
duplicate_filter: undefined,
transformers: [], transformers: [],
tag_resolver: { tag_resolver: {
// defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified // defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified
@@ -269,7 +270,7 @@ class GitCommandManager {
} }
execGit(args, allowAllExitCodes = false, silent = false) { execGit(args, allowAllExitCodes = false, silent = false) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
utils_1.directoryExistsSync(this.workingDirectory, true); (0, utils_1.directoryExistsSync)(this.workingDirectory, true);
const result = new GitOutput(); const result = new GitOutput();
const stdout = []; const stdout = [];
const options = { const options = {
@@ -349,10 +350,10 @@ function run() {
try { try {
// read in path specification, resolve github workspace, and repo path // read in path specification, resolve github workspace, and repo path
const inputPath = core.getInput('path'); const inputPath = core.getInput('path');
const repositoryPath = utils_1.retrieveRepositoryPath(inputPath); const repositoryPath = (0, utils_1.retrieveRepositoryPath)(inputPath);
// read in configuration file if possible // read in configuration file if possible
const configurationFile = core.getInput('configuration'); const configurationFile = core.getInput('configuration');
const configuration = utils_1.resolveConfiguration(repositoryPath, configurationFile); const configuration = (0, utils_1.resolveConfiguration)(repositoryPath, configurationFile);
// read in repository inputs // read in repository inputs
const token = core.getInput('token'); const token = core.getInput('token');
const owner = core.getInput('owner') || github.context.repo.owner; const owner = core.getInput('owner') || github.context.repo.owner;
@@ -370,10 +371,10 @@ function run() {
const outputFile = core.getInput('outputFile'); const outputFile = core.getInput('outputFile');
if (outputFile !== '') { if (outputFile !== '') {
core.debug(`Enabled writing the changelog to disk`); core.debug(`Enabled writing the changelog to disk`);
utils_1.writeOutput(repositoryPath, outputFile, result); (0, utils_1.writeOutput)(repositoryPath, outputFile, result);
} }
} }
catch (error) { catch (error /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
core.setFailed(error.message); core.setFailed(error.message);
} }
}); });
@@ -444,7 +445,7 @@ class PullRequests {
}); });
return mapPullRequest(data); return mapPullRequest(data);
} }
catch (e) { catch (e /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
core.warning(`⚠️ Cannot find PR ${owner}/${repo}#${prNumber} - ${e.message}`); core.warning(`⚠️ Cannot find PR ${owner}/${repo}#${prNumber} - ${e.message}`);
return null; return null;
} }
@@ -471,7 +472,7 @@ class PullRequests {
} }
const firstPR = prs[0]; const firstPR = prs[0];
if (firstPR === undefined || if (firstPR === undefined ||
(firstPR.merged_at && fromDate.isAfter(moment_1.default(firstPR.merged_at))) || (firstPR.merged_at && fromDate.isAfter((0, moment_1.default)(firstPR.merged_at))) ||
mergedPRs.length >= maxPullRequests) { mergedPRs.length >= maxPullRequests) {
if (mergedPRs.length >= maxPullRequests) { if (mergedPRs.length >= maxPullRequests) {
core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`); core.warning(`⚠️ Reached 'maxPullRequests' count ${maxPullRequests}`);
@@ -526,7 +527,7 @@ const mapPullRequest = (pr) => {
title: pr.title, title: pr.title,
htmlURL: pr.html_url, htmlURL: pr.html_url,
baseBranch: pr.base.ref, baseBranch: pr.base.ref,
mergedAt: moment_1.default(pr.merged_at), mergedAt: (0, moment_1.default)(pr.merged_at),
mergeCommitSha: pr.merge_commit_sha || '', mergeCommitSha: pr.merge_commit_sha || '',
author: ((_a = pr.user) === null || _a === void 0 ? void 0 : _a.login) || '', author: ((_a = pr.user) === null || _a === void 0 ? void 0 : _a.login) || '',
repoName: pr.base.repo.full_name, repoName: pr.base.repo.full_name,
@@ -612,7 +613,7 @@ class ReleaseNotes {
return null; return null;
} }
core.startGroup('📦 Build changelog'); core.startGroup('📦 Build changelog');
const resultChangelog = transform_1.buildChangelog(mergedPullRequests, this.options); const resultChangelog = (0, transform_1.buildChangelog)(mergedPullRequests, this.options);
core.endGroup(); core.endGroup();
return resultChangelog; return resultChangelog;
}); });
@@ -627,7 +628,7 @@ class ReleaseNotes {
commits = yield commitsApi.getDiff(owner, repo, fromTag, toTag); commits = yield commitsApi.getDiff(owner, repo, fromTag, toTag);
} }
catch (error) { catch (error) {
utils_1.failOrError(`💥 Failed to retrieve - Invalid tag? - Because of: ${error}`, failOnError); (0, utils_1.failOrError)(`💥 Failed to retrieve - Invalid tag? - Because of: ${error}`, failOnError);
return []; return [];
} }
if (commits.length === 0) { if (commits.length === 0) {
@@ -659,7 +660,7 @@ class ReleaseNotes {
const pullRequestsApi = new pullRequests_1.PullRequests(octokit); const pullRequestsApi = new pullRequests_1.PullRequests(octokit);
const pullRequests = yield pullRequestsApi.getBetweenDates(owner, repo, fromDate, toDate, configuration.max_pull_requests || configuration_1.DefaultConfiguration.max_pull_requests); const pullRequests = yield pullRequestsApi.getBetweenDates(owner, repo, fromDate, toDate, configuration.max_pull_requests || configuration_1.DefaultConfiguration.max_pull_requests);
core.info(`️ Retrieved ${pullRequests.length} merged PRs for ${owner}/${repo}`); core.info(`️ Retrieved ${pullRequests.length} merged PRs for ${owner}/${repo}`);
const prCommits = commits_1.filterCommits(commits, configuration.exclude_merge_branches || const prCommits = (0, commits_1.filterCommits)(commits, configuration.exclude_merge_branches ||
configuration_1.DefaultConfiguration.exclude_merge_branches); configuration_1.DefaultConfiguration.exclude_merge_branches);
core.info(`️ Retrieved ${prCommits.length} release commits for ${owner}/${repo}`); core.info(`️ Retrieved ${prCommits.length} release commits for ${owner}/${repo}`);
// create array of commits for this release // create array of commits for this release
@@ -691,7 +692,7 @@ class ReleaseNotes {
if (commits.length === 0) { if (commits.length === 0) {
return []; return [];
} }
const prCommits = commits_1.filterCommits(commits, configuration.exclude_merge_branches || const prCommits = (0, commits_1.filterCommits)(commits, configuration.exclude_merge_branches ||
configuration_1.DefaultConfiguration.exclude_merge_branches); configuration_1.DefaultConfiguration.exclude_merge_branches);
core.info(`️ Retrieved ${prCommits.length} commits for ${owner}/${repo}`); core.info(`️ Retrieved ${prCommits.length} commits for ${owner}/${repo}`);
return prCommits.map(function (commit) { return prCommits.map(function (commit) {
@@ -778,7 +779,7 @@ class ReleaseNotesBuilder {
var _a, _b; var _a, _b;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (!this.owner) { if (!this.owner) {
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError); (0, utils_1.failOrError)(`💥 Missing or couldn't resolve 'owner'`, this.failOnError);
return null; return null;
} }
else { else {
@@ -786,7 +787,7 @@ class ReleaseNotesBuilder {
core.debug(`Resolved 'owner' as ${this.owner}`); core.debug(`Resolved 'owner' as ${this.owner}`);
} }
if (!this.repo) { if (!this.repo) {
utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, this.failOnError); (0, utils_1.failOrError)(`💥 Missing or couldn't resolve 'owner'`, this.failOnError);
return null; return null;
} }
else { else {
@@ -805,7 +806,7 @@ class ReleaseNotesBuilder {
configuration_1.DefaultConfiguration.max_tags_to_fetch, this.configuration.tag_resolver || configuration_1.DefaultConfiguration.tag_resolver); configuration_1.DefaultConfiguration.max_tags_to_fetch, this.configuration.tag_resolver || configuration_1.DefaultConfiguration.tag_resolver);
const thisTag = (_a = tagRange.to) === null || _a === void 0 ? void 0 : _a.name; const thisTag = (_a = tagRange.to) === null || _a === void 0 ? void 0 : _a.name;
if (!thisTag) { if (!thisTag) {
utils_1.failOrError(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError); (0, utils_1.failOrError)(`💥 Missing or couldn't resolve 'toTag'`, this.failOnError);
return null; return null;
} }
else { else {
@@ -815,7 +816,7 @@ class ReleaseNotesBuilder {
} }
const previousTag = (_b = tagRange.from) === null || _b === void 0 ? void 0 : _b.name; const previousTag = (_b = tagRange.from) === null || _b === void 0 ? void 0 : _b.name;
if (previousTag == null) { if (previousTag == null) {
utils_1.failOrError(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError); (0, utils_1.failOrError)(`💥 Unable to retrieve previous tag given ${this.toTag}`, this.failOnError);
return null; return null;
} }
this.fromTag = previousTag; this.fromTag = previousTag;
@@ -832,7 +833,7 @@ class ReleaseNotesBuilder {
}; };
const releaseNotes = new releaseNotes_1.ReleaseNotes(octokit, options); const releaseNotes = new releaseNotes_1.ReleaseNotes(octokit, options);
return ((yield releaseNotes.pull()) || return ((yield releaseNotes.pull()) ||
transform_1.fillAdditionalPlaceholders(this.configuration.empty_template || (0, transform_1.fillAdditionalPlaceholders)(this.configuration.empty_template ||
configuration_1.DefaultConfiguration.empty_template, options)); configuration_1.DefaultConfiguration.empty_template, options));
}); });
} }
@@ -953,7 +954,7 @@ class Tags {
else { else {
core.info(`️ Only one tag found for the given repository. Usually this is the case for the initial release.`); core.info(`️ Only one tag found for the given repository. Usually this is the case for the initial release.`);
// if not specified try to retrieve tag from git // if not specified try to retrieve tag from git
const gitHelper = yield gitHelper_1.createCommandManager(repositoryPath); const gitHelper = yield (0, gitHelper_1.createCommandManager)(repositoryPath);
const initialCommit = yield gitHelper.initialCommit(); const initialCommit = yield gitHelper.initialCommit();
core.info(`🔖 Resolved initial commit (${initialCommit}) from 'git rev-list --max-parents=0 HEAD'`); core.info(`🔖 Resolved initial commit (${initialCommit}) from 'git rev-list --max-parents=0 HEAD'`);
return { name: initialCommit, commit: initialCommit }; return { name: initialCommit, commit: initialCommit };
@@ -991,7 +992,7 @@ class Tags {
} }
else { else {
// if not specified try to retrieve tag from git // if not specified try to retrieve tag from git
const gitHelper = yield gitHelper_1.createCommandManager(repositoryPath); const gitHelper = yield (0, gitHelper_1.createCommandManager)(repositoryPath);
const latestTag = yield gitHelper.latestTag(); const latestTag = yield gitHelper.latestTag();
core.info(`🔖 Resolved current tag (${latestTag}) from 'git rev-list --tags --skip=0 --max-count=1'`); core.info(`🔖 Resolved current tag (${latestTag}) from 'git rev-list --tags --skip=0 --max-count=1'`);
resultToTag = { resultToTag = {
@@ -1133,38 +1134,40 @@ function buildChangelog(prs, options) {
const config = options.configuration; const config = options.configuration;
const sort = config.sort || configuration_1.DefaultConfiguration.sort; const sort = config.sort || configuration_1.DefaultConfiguration.sort;
const sortAsc = sort.toUpperCase() === 'ASC'; const sortAsc = sort.toUpperCase() === 'ASC';
prs = pullRequests_1.sortPullRequests(prs, sortAsc); prs = (0, pullRequests_1.sortPullRequests)(prs, sortAsc);
core.info(`️ Sorted all pull requests ascending: ${sort}`); core.info(`️ Sorted all pull requests ascending: ${sort}`);
// drop duplicate pull requests
if (config.duplicate_filter !== undefined) {
const extractor = validateTransformer(config.duplicate_filter);
if (extractor != null) {
core.info(`️ Remove duplicated pull requests using \`duplicate_filter\``);
const deduplicatedMap = new Map();
for (const pr of prs) {
const extracted = extractValues(pr, extractor, 'dupliate_filter');
if (extracted !== null && extracted.length > 0) {
deduplicatedMap.set(extracted[0], pr);
}
else {
core.debug(`️ PR (${pr.number}) did not resolve a ID using the \`duplicate_filter\``);
}
}
const deduplicatedPRs = Array.from(deduplicatedMap.values());
const removedElements = prs.length - deduplicatedPRs.length;
core.info(`️ Removed ${removedElements} pull requests during deduplication`);
prs = deduplicatedPRs;
}
else {
core.warning(`⚠️ Configured \`duplicate_filter\` invalid.`);
}
}
// extract additional labels from the commit message // extract additional labels from the commit message
const labelExtractors = validateTransformers(config.label_extractor); const labelExtractors = validateTransformers(config.label_extractor);
for (const extractor of labelExtractors) { for (const extractor of labelExtractors) {
if (extractor.pattern != null) {
for (const pr of prs) { for (const pr of prs) {
let onValue; const extracted = extractValues(pr, extractor, 'label_extractor');
if (extractor.onProperty !== undefined) { if (extracted !== null) {
let value = pr[extractor.onProperty]; for (const label of extracted) {
if (value === undefined) { pr.labels.add(label);
core.warning(`⚠️ the provided property '${extractor.onProperty}' for \`label_extractor\` is not valid`);
value = pr['body'];
}
onValue = value;
}
else {
onValue = pr.body;
}
if (extractor.method === 'match') {
const lables = onValue.match(extractor.pattern);
if (lables !== null) {
for (const label of lables) {
pr.labels.add(label.toLocaleLowerCase());
}
}
}
else {
const label = onValue.replace(extractor.pattern, extractor.target);
if (label !== '') {
pr.labels.add(label.toLocaleLowerCase());
}
} }
} }
} }
@@ -1195,11 +1198,19 @@ function buildChangelog(prs, options) {
} }
let matched = false; let matched = false;
for (const [category, pullRequests] of categorized) { for (const [category, pullRequests] of categorized) {
if (category.exhaustive === true) {
if (haveEveryElements(category.labels.map(lbl => lbl.toLocaleLowerCase()), pr.labels)) {
pullRequests.push(body);
matched = true;
}
}
else {
if (haveCommonElements(category.labels.map(lbl => lbl.toLocaleLowerCase()), pr.labels)) { if (haveCommonElements(category.labels.map(lbl => lbl.toLocaleLowerCase()), pr.labels)) {
pullRequests.push(body); pullRequests.push(body);
matched = true; matched = true;
} }
} }
}
if (!matched) { if (!matched) {
// we allow to have pull requests included in an "uncategorized" category // we allow to have pull requests included in an "uncategorized" category
for (const [category, pullRequests] of categorized) { for (const [category, pullRequests] of categorized) {
@@ -1264,6 +1275,9 @@ exports.fillAdditionalPlaceholders = fillAdditionalPlaceholders;
function haveCommonElements(arr1, arr2) { function haveCommonElements(arr1, arr2) {
return arr1.some(item => arr2.has(item)); return arr1.some(item => arr2.has(item));
} }
function haveEveryElements(arr1, arr2) {
return arr1.every(item => arr2.has(item));
}
function fillTemplate(pr, template) { function fillTemplate(pr, template) {
var _a, _b, _c; var _a, _b, _c;
let transformed = template; let transformed = template;
@@ -1295,7 +1309,18 @@ function validateTransformers(specifiedTransformers) {
const transformers = specifiedTransformers || configuration_1.DefaultConfiguration.transformers; const transformers = specifiedTransformers || configuration_1.DefaultConfiguration.transformers;
return transformers return transformers
.map(transformer => { .map(transformer => {
return validateTransformer(transformer);
})
.filter(transformer => (transformer === null || transformer === void 0 ? void 0 : transformer.pattern) != null)
.map(transformer => {
return transformer;
});
}
function validateTransformer(transformer) {
var _a; var _a;
if (transformer === undefined) {
return null;
}
try { try {
let onProperty = undefined; let onProperty = undefined;
let method = undefined; let method = undefined;
@@ -1312,13 +1337,38 @@ function validateTransformers(specifiedTransformers) {
} }
catch (e) { catch (e) {
core.warning(`⚠️ Bad replacer regex: ${transformer.pattern}`); core.warning(`⚠️ Bad replacer regex: ${transformer.pattern}`);
return { return null;
pattern: null,
target: ''
};
} }
}) }
.filter(transformer => transformer.pattern != null); function extractValues(pr, extractor, extractor_usecase) {
if (extractor.pattern == null) {
return null;
}
let onValue;
if (extractor.onProperty !== undefined) {
let value = pr[extractor.onProperty];
if (value === undefined) {
core.warning(`⚠️ the provided property '${extractor.onProperty}' for \`${extractor_usecase}\` is not valid`);
value = pr['body'];
}
onValue = value;
}
else {
onValue = pr.body;
}
if (extractor.method === 'match') {
const lables = onValue.match(extractor.pattern);
if (lables !== null) {
return lables.map(label => label.toLocaleLowerCase());
}
}
else {
const label = onValue.replace(extractor.pattern, extractor.target);
if (label !== '') {
return [label.toLocaleLowerCase()];
}
}
return null;
} }
@@ -1432,7 +1482,7 @@ function directoryExistsSync(inputPath, required) {
try { try {
stats = fs.statSync(inputPath); stats = fs.statSync(inputPath);
} }
catch (error) { catch (error /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
if (error.code === 'ENOENT') { if (error.code === 'ENOENT') {
if (!required) { if (!required) {
return false; return false;
@@ -1460,7 +1510,7 @@ function writeOutput(githubWorkspacePath, outputFile, changelog) {
try { try {
fs.writeFileSync(outputPath, changelog); fs.writeFileSync(outputPath, changelog);
} }
catch (error) { catch (error /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
core.warning(`⚠️ Could not write the file to disk - ${error.message}`); core.warning(`⚠️ Could not write the file to disk - ${error.message}`);
} }
} }
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+7 -7
View File
@@ -31,7 +31,7 @@
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "2.3.2", "prettier": "2.3.2",
"ts-jest": "^27.0.5", "ts-jest": "^27.0.5",
"typescript": "^4.3.5" "typescript": "^4.4.2"
} }
}, },
"node_modules/@actions/core": { "node_modules/@actions/core": {
@@ -6616,9 +6616,9 @@
} }
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "4.3.5", "version": "4.4.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz",
"integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", "integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==",
"dev": true, "dev": true,
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
@@ -12049,9 +12049,9 @@
} }
}, },
"typescript": { "typescript": {
"version": "4.3.5", "version": "4.4.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz",
"integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", "integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==",
"dev": true "dev": true
}, },
"unbox-primitive": { "unbox-primitive": {
+1 -1
View File
@@ -54,6 +54,6 @@
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "2.3.2", "prettier": "2.3.2",
"ts-jest": "^27.0.5", "ts-jest": "^27.0.5",
"typescript": "^4.3.5" "typescript": "^4.4.2"
} }
} }
+9 -6
View File
@@ -3,32 +3,34 @@ export interface Configuration {
max_pull_requests: number max_pull_requests: number
max_back_track_time_days: number max_back_track_time_days: number
exclude_merge_branches: string[] exclude_merge_branches: string[]
sort: string sort: string // "ASC" or "DESC"
template: string template: string
pr_template: string pr_template: string
empty_template: string empty_template: string
categories: Category[] categories: Category[]
ignore_labels: string[] ignore_labels: string[]
label_extractor: Extractor[] label_extractor: Extractor[]
duplicate_filter?: Extractor // extract an identifier from a PR used to detect duplicates, will keep the last match (depends on `sort`)
transformers: Transformer[] transformers: Transformer[]
tag_resolver: TagResolver tag_resolver: TagResolver
base_branches: string[] base_branches: string[]
} }
export interface Category { export interface Category {
title: string title: string // the title of this category
labels: string[] labels: string[] // labels to associate PRs to this category
exhaustive?: boolean // requires all labels to be present in the PR
} }
export interface Transformer { export interface Transformer {
pattern: string pattern: string // the regex pattern to match
target?: string target?: string // the target string to transform the source string using the regex to
flags?: string // the regex flag to use for RegExp flags?: string // the regex flag to use for RegExp
} }
export interface Extractor extends Transformer { export interface Extractor extends Transformer {
on_property?: 'title' | 'author' | 'milestone' | 'body' | undefined // retrieve the property to extract the value from on_property?: 'title' | 'author' | 'milestone' | 'body' | undefined // retrieve the property to extract the value from
method?: 'replace' | 'match' | undefined // the method to use to extract the value method?: 'replace' | 'match' | undefined // the method to use to extract the value, `match` will not use the `target` property
} }
export interface TagResolver { export interface TagResolver {
@@ -60,6 +62,7 @@ export const DefaultConfiguration: Configuration = {
], // the categories to support for the ordering ], // the categories to support for the ordering
ignore_labels: ['ignore'], // list of lables being ignored from the changelog ignore_labels: ['ignore'], // list of lables being ignored from the changelog
label_extractor: [], // extracts additional labels from the commit message given a regex label_extractor: [], // extracts additional labels from the commit message given a regex
duplicate_filter: undefined, // extract an identifier from a PR used to detect duplicates, will keep the last match (depends on `sort`)
transformers: [], // transformers to apply on the PR description according to the `pr_template` transformers: [], // transformers to apply on the PR description according to the `pr_template`
tag_resolver: { tag_resolver: {
// defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified // defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified
+1 -1
View File
@@ -56,7 +56,7 @@ async function run(): Promise<void> {
core.debug(`Enabled writing the changelog to disk`) core.debug(`Enabled writing the changelog to disk`)
writeOutput(repositoryPath, outputFile, result) writeOutput(repositoryPath, outputFile, result)
} }
} catch (error) { } catch (error: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
core.setFailed(error.message) core.setFailed(error.message)
} }
} }
+1 -1
View File
@@ -40,7 +40,7 @@ export class PullRequests {
}) })
return mapPullRequest(data) return mapPullRequest(data)
} catch (e) { } catch (e: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
core.warning( core.warning(
`⚠️ Cannot find PR ${owner}/${repo}#${prNumber} - ${e.message}` `⚠️ Cannot find PR ${owner}/${repo}#${prNumber} - ${e.message}`
) )
+99 -32
View File
@@ -19,37 +19,42 @@ export function buildChangelog(
prs = sortPullRequests(prs, sortAsc) prs = sortPullRequests(prs, sortAsc)
core.info(`️ Sorted all pull requests ascending: ${sort}`) core.info(`️ Sorted all pull requests ascending: ${sort}`)
// drop duplicate pull requests
if (config.duplicate_filter !== undefined) {
const extractor = validateTransformer(config.duplicate_filter)
if (extractor != null) {
core.info(`️ Remove duplicated pull requests using \`duplicate_filter\``)
const deduplicatedMap = new Map<string, PullRequestInfo>()
for (const pr of prs) {
const extracted = extractValues(pr, extractor, 'dupliate_filter')
if (extracted !== null && extracted.length > 0) {
deduplicatedMap.set(extracted[0], pr)
} else {
core.debug(
`️ PR (${pr.number}) did not resolve a ID using the \`duplicate_filter\``
)
}
}
const deduplicatedPRs = Array.from(deduplicatedMap.values())
const removedElements = prs.length - deduplicatedPRs.length
core.info(
`️ Removed ${removedElements} pull requests during deduplication`
)
prs = deduplicatedPRs
} else {
core.warning(`⚠️ Configured \`duplicate_filter\` invalid.`)
}
}
// extract additional labels from the commit message // extract additional labels from the commit message
const labelExtractors = validateTransformers(config.label_extractor) const labelExtractors = validateTransformers(config.label_extractor)
for (const extractor of labelExtractors) { for (const extractor of labelExtractors) {
if (extractor.pattern != null) {
for (const pr of prs) { for (const pr of prs) {
let onValue const extracted = extractValues(pr, extractor, 'label_extractor')
if (extractor.onProperty !== undefined) { if (extracted !== null) {
let value: string = pr[extractor.onProperty] for (const label of extracted) {
if (value === undefined) { pr.labels.add(label)
core.warning(
`⚠️ the provided property '${extractor.onProperty}' for \`label_extractor\` is not valid`
)
value = pr['body']
}
onValue = value
} else {
onValue = pr.body
}
if (extractor.method === 'match') {
const lables = onValue.match(extractor.pattern)
if (lables !== null) {
for (const label of lables) {
pr.labels.add(label.toLocaleLowerCase())
}
}
} else {
const label = onValue.replace(extractor.pattern, extractor.target)
if (label !== '') {
pr.labels.add(label.toLocaleLowerCase())
}
} }
} }
} }
@@ -103,6 +108,17 @@ export function buildChangelog(
let matched = false let matched = false
for (const [category, pullRequests] of categorized) { for (const [category, pullRequests] of categorized) {
if (category.exhaustive === true) {
if (
haveEveryElements(
category.labels.map(lbl => lbl.toLocaleLowerCase()),
pr.labels
)
) {
pullRequests.push(body)
matched = true
}
} else {
if ( if (
haveCommonElements( haveCommonElements(
category.labels.map(lbl => lbl.toLocaleLowerCase()), category.labels.map(lbl => lbl.toLocaleLowerCase()),
@@ -113,6 +129,7 @@ export function buildChangelog(
matched = true matched = true
} }
} }
}
if (!matched) { if (!matched) {
// we allow to have pull requests included in an "uncategorized" category // we allow to have pull requests included in an "uncategorized" category
@@ -213,6 +230,10 @@ function haveCommonElements(arr1: string[], arr2: Set<string>): Boolean {
return arr1.some(item => arr2.has(item)) return arr1.some(item => arr2.has(item))
} }
function haveEveryElements(arr1: string[], arr2: Set<string>): Boolean {
return arr1.every(item => arr2.has(item))
}
function fillTemplate(pr: PullRequestInfo, template: string): string { function fillTemplate(pr: PullRequestInfo, template: string): string {
let transformed = template let transformed = template
transformed = transformed.replace(/\${{NUMBER}}/g, pr.number.toString()) transformed = transformed.replace(/\${{NUMBER}}/g, pr.number.toString())
@@ -260,6 +281,20 @@ function validateTransformers(
specifiedTransformers || DefaultConfiguration.transformers specifiedTransformers || DefaultConfiguration.transformers
return transformers return transformers
.map(transformer => { .map(transformer => {
return validateTransformer(transformer)
})
.filter(transformer => transformer?.pattern != null)
.map(transformer => {
return transformer as RegexTransformer
})
}
function validateTransformer(
transformer?: Transformer
): RegexTransformer | null {
if (transformer === undefined) {
return null
}
try { try {
let onProperty = undefined let onProperty = undefined
let method = undefined let method = undefined
@@ -279,13 +314,45 @@ function validateTransformers(
} }
} catch (e) { } catch (e) {
core.warning(`⚠️ Bad replacer regex: ${transformer.pattern}`) core.warning(`⚠️ Bad replacer regex: ${transformer.pattern}`)
return { return null
pattern: null, }
target: '' }
function extractValues(
pr: PullRequestInfo,
extractor: RegexTransformer,
extractor_usecase: string
): string[] | null {
if (extractor.pattern == null) {
return null
}
let onValue
if (extractor.onProperty !== undefined) {
let value: string = pr[extractor.onProperty]
if (value === undefined) {
core.warning(
`⚠️ the provided property '${extractor.onProperty}' for \`${extractor_usecase}\` is not valid`
)
value = pr['body']
}
onValue = value
} else {
onValue = pr.body
}
if (extractor.method === 'match') {
const lables = onValue.match(extractor.pattern)
if (lables !== null) {
return lables.map(label => label.toLocaleLowerCase())
}
} else {
const label = onValue.replace(extractor.pattern, extractor.target)
if (label !== '') {
return [label.toLocaleLowerCase()]
} }
} }
}) return null
.filter(transformer => transformer.pattern != null)
} }
interface RegexTransformer { interface RegexTransformer {
+2 -2
View File
@@ -96,7 +96,7 @@ export function directoryExistsSync(
let stats: fs.Stats let stats: fs.Stats
try { try {
stats = fs.statSync(inputPath) stats = fs.statSync(inputPath)
} catch (error) { } catch (error: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
if (error.code === 'ENOENT') { if (error.code === 'ENOENT') {
if (!required) { if (!required) {
return false return false
@@ -132,7 +132,7 @@ export function writeOutput(
core.debug(`outputPath = '${outputPath}'`) core.debug(`outputPath = '${outputPath}'`)
try { try {
fs.writeFileSync(outputPath, changelog) fs.writeFileSync(outputPath, changelog)
} catch (error) { } catch (error: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
core.warning(`⚠️ Could not write the file to disk - ${error.message}`) core.warning(`⚠️ Could not write the file to disk - ${error.message}`)
} }
} }