- move pr collection into npm module

(publish without any furhter notes or docs)
- refactor action to use npm dependency
This commit is contained in:
Mike Penz
2023-06-03 11:22:52 +00:00
committed by GitHub
parent 4a9ea3cd6a
commit e7dc26611c
28 changed files with 3529 additions and 1808 deletions
+3 -1
View File
@@ -13,5 +13,7 @@ it('Configurations are merged correctly', async () => {
const mergedConfiguration = mergeConfiguration(configurationJson, configurationFile)
console.log(mergedConfiguration)
expect(JSON.stringify(mergedConfiguration)).toEqual(`{\"max_tags_to_fetch\":200,\"max_pull_requests\":1000,\"max_back_track_time_days\":1000,\"exclude_merge_branches\":[],\"sort\":\"DESC\",\"template\":\"$\{\{CHANGELOG}}\",\"pr_template\":\"- $\{\{TITLE}}\\n - PR: #$\{\{NUMBER}}\",\"empty_template\":\"- no magic changes\",\"categories\":[{\"title\":\"## 🚀 Features\",\"labels\":[\"feature\"]},{\"title\":\"## 🐛 Fixes\",\"labels\":[\"fix\"]},{\"title\":\"## 🧪 Tests\",\"labels\":[\"test\"]}],\"ignore_labels\":[\"ignore\"],\"label_extractor\":[],\"transformers\":[],\"tag_resolver\":{\"method\":\"semver\"},\"base_branches\":[],\"custom_placeholders\":[],\"trim_values\":true}`)
expect(JSON.stringify(mergedConfiguration)).toEqual(
`{\"max_tags_to_fetch\":200,\"max_pull_requests\":1000,\"max_back_track_time_days\":1000,\"exclude_merge_branches\":[],\"sort\":\"DESC\",\"template\":\"$\{\{CHANGELOG}}\",\"pr_template\":\"- $\{\{TITLE}}\\n - PR: #$\{\{NUMBER}}\",\"empty_template\":\"- no magic changes\",\"categories\":[{\"title\":\"## 🚀 Features\",\"labels\":[\"feature\"]},{\"title\":\"## 🐛 Fixes\",\"labels\":[\"fix\"]},{\"title\":\"## 🧪 Tests\",\"labels\":[\"test\"]}],\"ignore_labels\":[\"ignore\"],\"label_extractor\":[],\"transformers\":[],\"tag_resolver\":{\"method\":\"semver\"},\"base_branches\":[],\"custom_placeholders\":[],\"trim_values\":true}`
)
})
+181 -131
View File
@@ -1,7 +1,7 @@
import {mergeConfiguration, resolveConfiguration} from '../src/utils'
import {pullData} from '../src/releaseNotesBuilder'
import {Octokit} from '@octokit/rest'
import { buildChangelog } from '../src/transform'
import {buildChangelog} from '../src/transform'
jest.setTimeout(180000)
@@ -13,19 +13,24 @@ const octokit = new Octokit({
it('Should have empty changelog (tags)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.0.1'},
toTag: {name: 'v0.0.2'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.0.1'},
toTag: {name: 'v0.0.2'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -34,19 +39,24 @@ it('Should have empty changelog (tags)', async () => {
it('Should match generated changelog (tags)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.0.1'},
toTag: {name: 'v0.0.3'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.0.1'},
toTag: {name: 'v0.0.3'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -60,19 +70,24 @@ it('Should match generated changelog (tags)', async () => {
it('Should match generated changelog (refs)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_all_placeholders.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
toTag: {name: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
toTag: {name: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -94,19 +109,24 @@ nhoelzl
it('Should match generated changelog and replace all occurrences (refs)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_replace_all_placeholders.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
toTag: {name: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
toTag: {name: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -130,19 +150,24 @@ nhoelzl
it('Should match ordered ASC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_asc.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
toTag: {name: 'v0.5.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
toTag: {name: 'v0.5.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -151,19 +176,24 @@ it('Should match ordered ASC', async () => {
it('Should match ordered DESC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_desc.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
toTag: {name: 'v0.5.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
toTag: {name: 'v0.5.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -172,19 +202,24 @@ it('Should match ordered DESC', async () => {
it('Should match ordered by title ASC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_asc.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
toTag: {name: 'v0.5.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
toTag: {name: 'v0.5.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -195,19 +230,24 @@ it('Should match ordered by title ASC', async () => {
it('Should match ordered by title DESC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_desc.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
toTag: {name: 'v0.5.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
toTag: {name: 'v0.5.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -218,19 +258,24 @@ it('Should match ordered by title DESC', async () => {
it('Should ignore PRs not merged into develop branch', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_develop.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v1.3.1'},
toTag: {name: 'v1.4.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v1.3.1'},
toTag: {name: 'v1.4.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
@@ -239,19 +284,24 @@ it('Should ignore PRs not merged into develop branch', async () => {
it('Should ignore PRs not merged into main branch', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_main.json'))
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v1.3.1'},
toTag: {name: 'v1.4.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}, false, false)
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v1.3.1'},
toTag: {name: 'v1.4.0'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog)
+3 -9
View File
@@ -23,9 +23,7 @@ it('Should order tags correctly using semver', async () => {
})
.join(',')
expect(sorted).toStrictEqual(
`2020.4.0,2020.4.0-rc02,2020.3.2,v2020.3.1,2020.3.1-rc03,2020.3.1-rc01,2020.3.1-b01,v2020.3.0`
)
expect(sorted).toStrictEqual(`2020.4.0,2020.4.0-rc02,2020.3.2,v2020.3.1,2020.3.1-rc03,2020.3.1-rc01,2020.3.1-b01,v2020.3.0`)
})
it('Should order tags correctly using semver', async () => {
@@ -54,9 +52,7 @@ it('Should order tags correctly using semver', async () => {
})
.join(',')
expect(sorted).toStrictEqual(
`1000.0.0,100.0.0,20.0.2,10.1.0,10.1.0-2,10.0.0,2.0.0,1.0.0,1.0.0-a01,0.1.0,0.1.0-b01,0.0.1,0.0.1-rc01`
)
expect(sorted).toStrictEqual(`1000.0.0,100.0.0,20.0.2,10.1.0,10.1.0-2,10.0.0,2.0.0,1.0.0,1.0.0-a01,0.1.0,0.1.0-b01,0.0.1,0.0.1-rc01`)
})
it('Should order tags alphabetical', async () => {
@@ -85,9 +81,7 @@ it('Should order tags alphabetical', async () => {
})
.join(',')
expect(sorted).toStrictEqual(
`a,20.0.2,2.0.0,1000.0.0,10.1.0,10.1.0-2,10.0.0,1.0.0,1.0.0-a01,v1,0.1.0-b01,0.0.1,0.0.1-rc01`
)
expect(sorted).toStrictEqual(`a,20.0.2,2.0.0,1000.0.0,10.1.0,10.1.0-2,10.0.0,1.0.0,1.0.0-a01,v1,0.1.0-b01,0.0.1,0.0.1-rc01`)
})
it('Should filter tags correctly using the regex', async () => {
+49 -53
View File
@@ -313,41 +313,41 @@ 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: ['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: [],
milestone: '',
body: 'Some fancy body message',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
status: 'open'
}
number: 6,
title: 'Still pending open pull request (Current)',
htmlURL: '',
baseBranch: '',
createdAt: moment(),
mergedAt: moment(),
mergeCommitSha: 'sha1',
author: 'Mike',
repoName: 'test-repo',
labels: ['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: [],
milestone: '',
body: 'Some fancy body message',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
status: 'open'
}
)
it('Match multiple labels exhaustive for category', async () => {
@@ -457,9 +457,7 @@ it('Release Diff', async () => {
configuration: customConfig
})
expect(resultChangelog).toStrictEqual(
`https://github.com/mikepenz/release-changelog-builder-action/compare/v2.8.0...v2.8.1\n`
)
expect(resultChangelog).toStrictEqual(`https://github.com/mikepenz/release-changelog-builder-action/compare/v2.8.0...v2.8.1\n`)
})
it('Use exclude labels to not include a PR within a category.', async () => {
@@ -532,7 +530,6 @@ it('Extract custom placeholder from PR body and replace in global template', asy
)
})
it('Use Rules to include a PR within a Category.', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
@@ -542,12 +539,12 @@ it('Use Rules to include a PR within a Category.', async () => {
exclude_labels: ['Fix'],
rules: [
{
pattern: "\[ABC-1234\]",
on_property: "title"
pattern: '[ABC-1234]',
on_property: 'title'
},
{
pattern: "merged",
on_property: "status"
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true
@@ -568,8 +565,8 @@ it('Use Rules to get all open PRs in a Category.', async () => {
title: '## Open PRs only',
rules: [
{
pattern: "open",
on_property: "status"
pattern: 'open',
on_property: 'status'
}
]
}
@@ -577,7 +574,6 @@ 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))
@@ -599,7 +595,8 @@ it('Use Rules to get current open PR and merged categorised.', async () => {
],
exhaustive: true,
exhaustive_rules: false
},{
},
{
title: '## 🐛 Issues',
labels: ['Issue'],
rules: [
@@ -627,8 +624,8 @@ it('Use Rules to get all open PRs in one Category and merged categorised.', asyn
title: '## Open PRs only',
rules: [
{
pattern: "open",
on_property: "status"
pattern: 'open',
on_property: 'status'
}
]
},
@@ -637,11 +634,11 @@ it('Use Rules to get all open PRs in one Category and merged categorised.', asyn
labels: ['Feature', 'Issue'],
rules: [
{
pattern: "merged",
on_property: "status"
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true,
exhaustive: true
}
]
expect(buildChangelogTest(customConfig, prs)).toStrictEqual(
@@ -649,7 +646,6 @@ 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',