- refactor action and move different functionalities in better classes

- merge releaseNotes and releaseNotesBuilder
- update testcases to cover new structure
This commit is contained in:
Mike Penz
2023-05-26 12:09:48 +00:00
committed by GitHub
parent 061b8ff198
commit 66470e5f14
8 changed files with 473 additions and 494 deletions
@@ -1,6 +1,7 @@
import {ReleaseNotes} from '../src/releaseNotes'
import {mergeConfiguration, resolveConfiguration} from '../src/utils'
import {pullData} from '../src/releaseNotesBuilder'
import {Octokit} from '@octokit/rest'
import { buildChangelog } from '../src/transform'
jest.setTimeout(180000)
@@ -11,7 +12,8 @@ const octokit = new Octokit({
it('Should have empty changelog (tags)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.0.1'},
@@ -25,14 +27,14 @@ it('Should have empty changelog (tags)', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual('- no changes')
})
it('Should match generated changelog (tags)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.0.1'},
@@ -46,7 +48,7 @@ it('Should match generated changelog (tags)', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests
@@ -58,7 +60,7 @@ 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 releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
@@ -72,7 +74,7 @@ it('Should match generated changelog (refs)', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests
@@ -92,7 +94,7 @@ 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 releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
@@ -106,7 +108,7 @@ it('Should match generated changelog and replace all occurrences (refs)', async
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests
@@ -128,7 +130,7 @@ nhoelzl
it('Should match ordered ASC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_asc.json'))
const releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
@@ -142,14 +144,14 @@ it('Should match ordered ASC', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🚀 Features\n\n22\n24\n25\n26\n28\n\n## 🐛 Fixes\n\n23\n\n`)
})
it('Should match ordered DESC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_desc.json'))
const releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
@@ -163,14 +165,14 @@ it('Should match ordered DESC', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🚀 Features\n\n28\n26\n25\n24\n22\n\n## 🐛 Fixes\n\n23\n\n`)
})
it('Should match ordered by title ASC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_asc.json'))
const releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
@@ -184,7 +186,7 @@ it('Should match ordered by title ASC', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(
`## 🚀 Features\n\nEnhanced action logs\nImprove README\nImproved configuration failure handling\nImproved defaults if no configuration is provided\nIntroduce additional placeholders [milestone, labels, assignees, reviewers]\n\n## 🐛 Fixes\n\nImproved handling for non existing tags\n\n`
@@ -193,7 +195,7 @@ 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 releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v0.3.0'},
@@ -207,7 +209,7 @@ it('Should match ordered by title DESC', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(
`## 🚀 Features\n\nIntroduce additional placeholders [milestone, labels, assignees, reviewers]\nImproved defaults if no configuration is provided\nImproved configuration failure handling\nImprove README\nEnhanced action logs\n\n## 🐛 Fixes\n\nImproved handling for non existing tags\n\n`
@@ -216,7 +218,7 @@ 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 releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v1.3.1'},
@@ -230,14 +232,14 @@ it('Should ignore PRs not merged into develop branch', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`150\n\n`)
})
it('Should ignore PRs not merged into main branch', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_main.json'))
const releaseNotes = new ReleaseNotes(octokit, {
const data = await pullData(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: 'v1.3.1'},
@@ -251,7 +253,7 @@ it('Should ignore PRs not merged into main branch', async () => {
configuration
})
const changeLog = await releaseNotes.pull()
const changeLog = buildChangelog(data.diffInfo, data.mergedPullRequests, data.options)
console.log(changeLog)
expect(changeLog).toStrictEqual(`153\n\n`)
})