From 0052b3d1abcf7f3da1c928b2c42da85cc1fe8a63 Mon Sep 17 00:00:00 2001 From: Ankio Date: Wed, 1 Nov 2023 11:05:55 +0800 Subject: [PATCH] tests:add gitea test cases and fix tests error --- __tests__/releaseNotesBuilder.test.ts | 2 +- __tests__/releaseNotesBuilderGItea.test.ts | 790 ++++++++++++++++++ __tests__/releaseNotesBuilderPull.test.ts | 37 +- .../releaseNotesBuilderPullGitea.test.ts | 336 ++++++++ __tests__/tags.test.ts | 2 +- __tests__/transform.test.ts | 11 +- configs/configuration_gitea.json | 29 + configs_test/configuration_gitea_desc.json | 29 + 8 files changed, 1216 insertions(+), 20 deletions(-) create mode 100644 __tests__/releaseNotesBuilderGItea.test.ts create mode 100644 __tests__/releaseNotesBuilderPullGitea.test.ts create mode 100644 configs/configuration_gitea.json create mode 100644 configs_test/configuration_gitea_desc.json diff --git a/__tests__/releaseNotesBuilder.test.ts b/__tests__/releaseNotesBuilder.test.ts index 8f3a285..b3bd0d9 100644 --- a/__tests__/releaseNotesBuilder.test.ts +++ b/__tests__/releaseNotesBuilder.test.ts @@ -4,7 +4,7 @@ import {GithubRepository} from '../src/repositories/GithubRepository' jest.setTimeout(180000) -const token = process.env.GITHUB_TOKEN || "" +const token = process.env.GITHUB_TOKEN || '' const githubRepository = new GithubRepository(token, undefined, '.') it('[Github] Should match generated changelog (unspecified fromTag)', async () => { const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json')) diff --git a/__tests__/releaseNotesBuilderGItea.test.ts b/__tests__/releaseNotesBuilderGItea.test.ts new file mode 100644 index 0000000..dea972c --- /dev/null +++ b/__tests__/releaseNotesBuilderGItea.test.ts @@ -0,0 +1,790 @@ +import {mergeConfiguration, resolveConfiguration} from '../src/utils' +import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder' +import {GiteaRepository} from '../src/repositories/GiteaRepository' + +jest.setTimeout(180000) + +/** + * Before starting testing, you should manually clone the repository + * cd /tmp && git clone https://gitea.com/jolheiser/sip + */ + +const token = process.env.GITEA_TOKEN || '' +const workingDirectory = '/tmp/sip/' +const owner = 'jolheiser' +const repo = 'sip' +const configurationFile = 'configs/configuration_gitea.json' +it('[Gitea] Should match generated changelog (unspecified fromTag)', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', configurationFile)) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + null, + 'v0.1.1', + false, + false, + false, + true, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿงช Upgrade + +- Clean up and polish + - PR: #1 + +`) +}) + +// +it('[Gitea] Should match generated changelog (unspecified tags)', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', configurationFile)) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + null, + null, + false, + false, + false, + false, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿš€ Features + +- Add release attachments + - PR: #26 + +`) +}) + +it('[Gitea] Should use empty placeholder', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', configurationFile)) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + 'v0.1.1', + 'v0.3.0', + false, + false, + false, + true, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿš€ Features + +- Add Drone and releases + - PR: #2 +- Add search filters + - PR: #8 +- Add qualifier module + - PR: #10 +- Add create repo command + - PR: #13 +- Add release support and CSV output + - PR: #16 + +## ๐Ÿ› Fixes + +- Fix PR head nil panic + - PR: #7 +- Fix Drone release + - PR: #14 + +`) +}) + +it('[Gitea] Should fill empty placeholders', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json')) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + 'v0.1.0', + 'v0.4.0', + false, + false, + false, + true, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual( + `## ๐Ÿš€ Features + +- Add create repo command + - PR: #13 +- Add release support and CSV output + - PR: #16 +- Add open functionality + - PR: #21 + +## ๐Ÿ“ฆ Uncategorized + +- Clean up and polish + - PR: #1 +- Add Drone and releases + - PR: #2 +- Update Beaver and fix bugs + - PR: #6 +- Fix PR head nil panic + - PR: #7 +- Add search filters + - PR: #8 +- Changelog 0.2.0 + - PR: #9 +- Add qualifier module + - PR: #10 +- Fix Drone release + - PR: #14 +- Imp formatting + - PR: #17 +- Update Gitea SDK and other modules + - PR: #19 +- Update modules + - PR: #20 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 + + +- Clean up and polish + - PR: #1 +- Add Drone and releases + - PR: #2 +- Update Beaver and fix bugs + - PR: #6 +- Fix PR head nil panic + - PR: #7 +- Add search filters + - PR: #8 +- Changelog 0.2.0 + - PR: #9 +- Add qualifier module + - PR: #10 +- Fix Drone release + - PR: #14 +- Imp formatting + - PR: #17 +- Update Gitea SDK and other modules + - PR: #19 +- Update modules + - PR: #20 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 + + +jolheiser +sip +v0.1.0 +v0.4.0 +https://gitea.com/jolheiser/sip/compare/v0.1.0...v0.4.0 +3 +12 +0 +36 +1322 +274 +0 +16` + ) +}) + +it('[Gitea] Should fill `template` placeholders', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json')) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + 'v0.1.0', + 'v0.4.0', + false, + false, + false, + true, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual( + `## ๐Ÿš€ Features + +- Add create repo command + - PR: #13 +- Add release support and CSV output + - PR: #16 +- Add open functionality + - PR: #21 + +## ๐Ÿ“ฆ Uncategorized + +- Clean up and polish + - PR: #1 +- Add Drone and releases + - PR: #2 +- Update Beaver and fix bugs + - PR: #6 +- Fix PR head nil panic + - PR: #7 +- Add search filters + - PR: #8 +- Changelog 0.2.0 + - PR: #9 +- Add qualifier module + - PR: #10 +- Fix Drone release + - PR: #14 +- Imp formatting + - PR: #17 +- Update Gitea SDK and other modules + - PR: #19 +- Update modules + - PR: #20 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 + + +- Clean up and polish + - PR: #1 +- Add Drone and releases + - PR: #2 +- Update Beaver and fix bugs + - PR: #6 +- Fix PR head nil panic + - PR: #7 +- Add search filters + - PR: #8 +- Changelog 0.2.0 + - PR: #9 +- Add qualifier module + - PR: #10 +- Fix Drone release + - PR: #14 +- Imp formatting + - PR: #17 +- Update Gitea SDK and other modules + - PR: #19 +- Update modules + - PR: #20 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 + + +jolheiser +sip +v0.1.0 +v0.4.0 +https://gitea.com/jolheiser/sip/compare/v0.1.0...v0.4.0 +3 +12 +0 +36 +1322 +274 +0 +16` + ) +}) + +it('[Gitea] Should fill `template` placeholders, ignore', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json')) + configuration.categories.pop() // drop `uncategorized` category + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + 'v0.3.0', + 'v0.5.0', + false, + false, + false, + false, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual( + `## ๐Ÿš€ Features + +- Add open functionality + - PR: #21 + + +- Update modules + - PR: #20 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 +- Update Gitea SDK + - PR: #23 +- Update repo info + - PR: #24 +- Add release attachments + - PR: #26 +- Refactor + - PR: #29 + + +jolheiser +sip +v0.3.0 +v0.5.0 +https://gitea.com/jolheiser/sip/compare/v0.3.0...v0.5.0 +1 +6 +0 +41 +748 +314 +0 +8` + ) +}) + +it('[Gitea] Uncategorized category', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_uncategorized_category.json')) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + 'v0.3.0', + 'v0.5.0', + false, + false, + false, + false, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual( + `## ๐Ÿš€ Features + +- Add open functionality + - PR: #21 + +## ๐Ÿ“ฆ Uncategorized + +- Update modules + - PR: #20 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 +- Update Gitea SDK + - PR: #23 +- Update repo info + - PR: #24 +- Add release attachments + - PR: #26 +- Refactor + - PR: #29 + + + +Uncategorized: +- Update modules + - PR: #20 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 +- Update Gitea SDK + - PR: #23 +- Update repo info + - PR: #24 +- Add release attachments + - PR: #26 +- Refactor + - PR: #29 + + +Ignored: + + +6 +0` + ) +}) + +it('[Gitea] Verify commit based changelog', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_commits.json')) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + 'v0.3.0', + 'v0.5.0', + false, + false, + false, + true, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + true, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual( + `## ๐Ÿ“ฆ Uncategorized + +- Update modules (#20) + +- Add open functionality (#21) + +- Add changelog for 0.3.0 and 0.4.0 (#22) + +- Update Gitea SDK (#23) + +- Update repo info (#24) + +- Add release attachments (#26) + +- Refactor (#29) + +- Changelog 0.5.0 (#30) + + + + +Uncategorized: +- Update modules (#20) + +- Add open functionality (#21) + +- Add changelog for 0.3.0 and 0.4.0 (#22) + +- Update Gitea SDK (#23) + +- Update repo info (#24) + +- Add release attachments (#26) + +- Refactor (#29) + +- Changelog 0.5.0 (#30) + + + +Ignored: + + +8 +0` + ) +}) + +it('[Gitea] Verify commit based changelog', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', configurationFile)) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, + giteaRepository, + workingDirectory, + owner, + repo, + '3e49adf6047960a03f53346bbececb3ce7e0809b', + '894a641ef86c444dccfa55eca457186b5e10da95', + false, + false, + false, + false, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + true, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual( + `## ๐Ÿš€ Features + +- Add release attachments (#26) + - PR: #0 + +` + ) +}) +// no open prs +it('[Gitea] Verify default inclusion of open PRs', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_including_open.json')) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, // baseUrl + giteaRepository, // token + workingDirectory, // repoPath + owner, // user + repo, // repo + 'v0.5.0', // fromTag + 'master', // toTag + true, // includeOpen + false, // failOnError + false, // ignorePrePrelease + false, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration // configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual(` + + +Uncategorized +- Add attachment removal and change message (#36) merged +- Change to vanity URL (#37) merged + + + +Open +`) +}) + +it('[Gitea] Verify custom categorisation of open PRs', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_excluding_open.json')) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, // baseUrl + giteaRepository, // token + workingDirectory, // repoPath + owner, // user + repo, // repo + 'v0.5.0', // fromTag + 'master', // toTag + true, // includeOpen + false, // failOnError + false, // ignorePrePrelease + false, // enable to fetch via commits + false, // enable to fetch reviewers + false, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration // configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual(``) +}) + +it('[Gitea] Verify reviewers who approved are fetched and also release information', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json')) + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, // baseUrl + giteaRepository, // token + workingDirectory, // repoPath + owner, // user + repo, // repo + 'v0.5.0', // fromTag + 'master', // toTag + true, // includeOpen + false, // failOnError + false, // ignorePrePrelease + false, // enable to fetch via commits + true, // enable to fetch reviewers + true, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration // configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual( + `## ๐Ÿ“ฆ Uncategorized + +- Add attachment removal and change message -- (#36) [merged] --- +- Change to vanity URL -- (#37) [merged] --- + + + +4` + ) +}) + +it('[Gitea] Fetch release information', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json')) + configuration.template = '#{{FROM_TAG}}-#{{FROM_TAG_DATE}}\n#{{TO_TAG}}-#{{TO_TAG_DATE}}\n#{{DAYS_SINCE}}' + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, // baseUrl + giteaRepository, // token + workingDirectory, // repoPath + owner, // user + repo, // repo + 'v0.5.0', // fromTag + 'master', // toTag + true, // includeOpen + false, // failOnError + false, // ignorePrePrelease + false, // enable to fetch via commits + false, // enable to fetch reviewers + true, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration // configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual(`v0.5.0-2020-09-17T16:34:40.000Z +master-2020-09-21T19:30:21.000Z +4`) +}) + +it('[Gitea] Fetch release information for non existing tag / release', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json')) + configuration.template = '#{{FROM_TAG}}-#{{FROM_TAG_DATE}}\n#{{TO_TAG}}-#{{TO_TAG_DATE}}\n#{{DAYS_SINCE}}' + + const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) + const releaseNotesBuilder = new ReleaseNotesBuilder( + null, // baseUrl + giteaRepository, // token + workingDirectory, // repoPath + owner, // user + repo, // repo + 'v0.5.0', // fromTag + 'master', // toTag + true, // includeOpen + false, // failOnError + false, // ignorePrePrelease + false, // enable to fetch via commits + false, // enable to fetch reviewers + true, // enable to fetch tag release information + false, // enable to fetch reviews + false, // enable commitMode + false, // enable exportCache + false, // enable exportOnly + null, // path to the cache + configuration // configuration + ) + + const changeLog = await releaseNotesBuilder.build() + console.log(changeLog) + expect(changeLog).toStrictEqual(`v0.5.0-2020-09-17T16:34:40.000Z +master-2020-09-21T19:30:21.000Z +4`) +}) diff --git a/__tests__/releaseNotesBuilderPull.test.ts b/__tests__/releaseNotesBuilderPull.test.ts index 507b833..0620987 100644 --- a/__tests__/releaseNotesBuilderPull.test.ts +++ b/__tests__/releaseNotesBuilderPull.test.ts @@ -1,17 +1,14 @@ import {checkExportedData, mergeConfiguration, resolveConfiguration} from '../src/utils' -import {Octokit} from '@octokit/rest' import {buildChangelog} from '../src/transform' import {pullData} from '../src/pr-collector/prCollector' -import {Data} from '../src/releaseNotesBuilder' -import {GithubRepository} from "../src/repositories/GithubRepository"; +import {GithubRepository} from '../src/repositories/GithubRepository' jest.setTimeout(180000) // load octokit instance const enablePullData = false // if false -> use cache for data - -const token = process.env.GITHUB_TOKEN || "" +const token = process.env.GITHUB_TOKEN || '' const githubRepository = new GithubRepository(token, undefined, '.') it('Should have empty changelog (tags)', async () => { const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json')) @@ -28,7 +25,8 @@ it('Should have empty changelog (tags)', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -55,7 +53,8 @@ it('Should match generated changelog (tags)', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -88,7 +87,8 @@ it('Should match generated changelog (refs)', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -128,7 +128,8 @@ it('Should match generated changelog and replace all occurrences (refs)', async fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -171,7 +172,8 @@ it('Should match ordered ASC', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -199,7 +201,8 @@ it('Should match ordered DESC', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -226,7 +229,8 @@ it('Should match ordered by title ASC', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -255,7 +259,8 @@ it('Should match ordered by title DESC', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -284,7 +289,8 @@ it('Should ignore PRs not merged into develop branch', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { @@ -311,7 +317,8 @@ it('Should ignore PRs not merged into main branch', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration + configuration, + repositoryUtils: githubRepository } let data: any if (enablePullData) { diff --git a/__tests__/releaseNotesBuilderPullGitea.test.ts b/__tests__/releaseNotesBuilderPullGitea.test.ts new file mode 100644 index 0000000..a7569f3 --- /dev/null +++ b/__tests__/releaseNotesBuilderPullGitea.test.ts @@ -0,0 +1,336 @@ +import {checkExportedData, mergeConfiguration, resolveConfiguration} from '../src/utils' +import {buildChangelog} from '../src/transform' +import {pullData} from '../src/pr-collector/prCollector' +import {GiteaRepository} from '../src/repositories/GiteaRepository' + +jest.setTimeout(180000) + +// load octokit instance +const enablePullData = true // if false -> use cache for data +/** + * Before starting testing, you should manually clone the repository + * cd /tmp && git clone https://gitea.com/jolheiser/sip + */ + +const token = process.env.GITEA_TOKEN || '' +const workingDirectory = '/tmp/sip/' +const owner = 'jolheiser' +const repo = 'sip' +const giteaRepository = new GiteaRepository(token, undefined, workingDirectory) +const configurationFile = 'configs/configuration_gitea.json' +it('[Gitea] Should have changelog (tags)', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', configurationFile)) + + const options = { + owner: owner, + repo: repo, + fromTag: {name: 'v0.5.0'}, + toTag: {name: 'master'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: true, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + commitMode: false, + configuration, + repositoryUtils: giteaRepository + } + let data: any + if (enablePullData) { + data = await pullData(giteaRepository, options) + } else { + data = checkExportedData(false, 'caches/rcba_0.0.2-0.0.3_cache.json') + } + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options) + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿš€ Features + +- Add attachment removal and change message + - PR: #36 + +## ๐Ÿ› Fixes + +- Fix drone-gitea-main + - PR: #38 + +`) +}) + +it('[Gitea] Should match generated changelog (tags)', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', configurationFile)) + const options = { + owner: owner, + repo: repo, + fromTag: {name: 'v0.5.0'}, + toTag: {name: 'master'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: true, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + commitMode: false, + configuration, + repositoryUtils: giteaRepository + } + let data: any + if (enablePullData) { + data = await pullData(giteaRepository, options) + } else { + data = checkExportedData(false, 'caches/rcba_0.0.1-0.0.3_cache.json') + } + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options) + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿš€ Features + +- Add attachment removal and change message + - PR: #36 + +## ๐Ÿ› Fixes + +- Fix drone-gitea-main + - PR: #38 + +`) +}) + +it('[Gitea] Should match generated changelog (refs)', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_all_placeholders.json')) + + const options = { + owner: owner, + repo: repo, + fromTag: {name: '3e49adf6047960a03f53346bbececb3ce7e0809b'}, + toTag: {name: '894a641ef86c444dccfa55eca457186b5e10da95'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: true, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + commitMode: false, + configuration, + repositoryUtils: giteaRepository + } + let data: any + if (enablePullData) { + data = await pullData(giteaRepository, options) + } else { + data = checkExportedData(false, 'caches/rcba_5ec7a2-fa3788_cache.json') + } + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options) + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿ“ฆ Uncategorized + +Add release attachments +26 +https://gitea.com/jolheiser/sip/pulls/26 +2020-09-16T18:07:32.000Z +jolheiser +enhancement +0.5.0 +Resolves #25 + + +Refactor +29 +https://gitea.com/jolheiser/sip/pulls/29 +2020-09-17T16:25:11.000Z +jolheiser +enhancement +0.5.0 +Fixes #27 + +Fixes #28 + +This PR refactors and cleans up packages. + +It also scans CLI flags into variables for fewer footguns. + + + +`) +}) + +it('[Gitea] Should match generated changelog and replace all occurrences (refs)', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_replace_all_placeholders.json')) + const options = { + owner: owner, + repo: repo, + fromTag: {name: '3e49adf6047960a03f53346bbececb3ce7e0809b'}, + toTag: {name: '894a641ef86c444dccfa55eca457186b5e10da95'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: true, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + commitMode: false, + configuration, + repositoryUtils: giteaRepository + } + let data: any + if (enablePullData) { + data = await pullData(giteaRepository, options) + } else { + data = checkExportedData(false, 'caches/rcba_5ec7a2-fa3788_cache.json') + } + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options) + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿ“ฆ Uncategorized + +Add release attachments +Add release attachments +26 +https://gitea.com/jolheiser/sip/pulls/26 +2020-09-16T18:07:32.000Z +jolheiser +jolheiser +enhancement +0.5.0 +Resolves #25 + + +Refactor +Refactor +29 +https://gitea.com/jolheiser/sip/pulls/29 +2020-09-17T16:25:11.000Z +jolheiser +jolheiser +enhancement +0.5.0 +Fixes #27 + +Fixes #28 + +This PR refactors and cleans up packages. + +It also scans CLI flags into variables for fewer footguns. + + + +`) +}) + +it('[Gitea] Should match ordered ASC', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', configurationFile)) + configuration.categories.pop() // drop `uncategorized` category + const options = { + owner: owner, + repo: repo, + fromTag: {name: 'v0.1.0'}, + toTag: {name: 'master'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: false, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + commitMode: false, + configuration, + repositoryUtils: giteaRepository + } + let data: any + if (enablePullData) { + data = await pullData(giteaRepository, options) + } else { + data = checkExportedData(false, 'caches/rcba_0.3.0-0.5.0_cache.json') + } + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options) + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿš€ Features + +- Add Drone and releases + - PR: #2 +- Add search filters + - PR: #8 +- Add qualifier module + - PR: #10 +- Add create repo command + - PR: #13 +- Add release support and CSV output + - PR: #16 +- Add open functionality + - PR: #21 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 +- Add release attachments + - PR: #26 +- Add attachment removal and change message + - PR: #36 + +## ๐Ÿ› Fixes + +- Fix PR head nil panic + - PR: #7 +- Fix Drone release + - PR: #14 + +`) +}) + +it('[Gitea] Should match ordered DESC', async () => { + const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_gitea_desc.json')) + configuration.categories.pop() // drop `uncategorized` category + const options = { + owner: owner, + repo: repo, + fromTag: {name: 'v0.1.0'}, + toTag: {name: 'master'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: false, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + commitMode: false, + configuration, + repositoryUtils: giteaRepository + } + let data: any + if (enablePullData) { + data = await pullData(giteaRepository, options) + } else { + data = checkExportedData(false, 'caches/rcba_0.3.0-0.5.0_cache.json') + } + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options) + console.log(changeLog) + expect(changeLog).toStrictEqual(`## ๐Ÿš€ Features + +- Add attachment removal and change message + - PR: #36 +- Add release attachments + - PR: #26 +- Add changelog for 0.3.0 and 0.4.0 + - PR: #22 +- Add open functionality + - PR: #21 +- Add release support and CSV output + - PR: #16 +- Add create repo command + - PR: #13 +- Add qualifier module + - PR: #10 +- Add search filters + - PR: #8 +- Add Drone and releases + - PR: #2 + +## ๐Ÿ› Fixes + +- Fix Drone release + - PR: #14 +- Fix PR head nil panic + - PR: #7 + +`) +}) + +/* + * I delete these test cases about gitea + * Should match ordered by title ASC + * Should match ordered by title DESC + * Should ignore PRs not merged into develop branch + */ diff --git a/__tests__/tags.test.ts b/__tests__/tags.test.ts index fbf7fa4..e38d788 100644 --- a/__tests__/tags.test.ts +++ b/__tests__/tags.test.ts @@ -1,4 +1,4 @@ -import {TagInfo, filterTags, prepareAndSortTags} from '../src/pr-collector/tags' +import {filterTags, prepareAndSortTags, TagInfo} from '../src/pr-collector/tags' jest.setTimeout(180000) diff --git a/__tests__/transform.test.ts b/__tests__/transform.test.ts index 89ea392..01bfcbc 100644 --- a/__tests__/transform.test.ts +++ b/__tests__/transform.test.ts @@ -3,6 +3,7 @@ import moment from 'moment' import {Configuration, DefaultConfiguration} from '../src/configuration' import {PullRequestInfo} from '../src/pr-collector/pullRequests' import {DefaultDiffInfo} from '../src/pr-collector/commits' +import {GithubRepository} from '../src/repositories/GithubRepository' jest.setTimeout(180000) @@ -437,6 +438,7 @@ it('Use empty_content for empty category', async () => { ) }) +const repositoryUtils = new GithubRepository(process.env.GITEA_TOKEN || '', undefined, '.') it('Commit SHA-1 in commitMode', async () => { const customConfig = Object.assign({}, DefaultConfiguration) customConfig.sort = 'DESC' @@ -453,7 +455,8 @@ it('Commit SHA-1 in commitMode', async () => { fetchReleaseInformation: false, fetchReviews: false, commitMode: true, - configuration: customConfig + configuration: customConfig, + repositoryUtils: repositoryUtils }) expect(resultChangelog).toStrictEqual(`## ๐Ÿš€ Features\n\nsha1-3\nsha1-1\n\n## ๐Ÿ› Fixes\n\nsha1-3\nsha1-2\n\n`) @@ -474,7 +477,8 @@ it('Release Diff', async () => { fetchReleaseInformation: true, fetchReviews: false, commitMode: true, - configuration: customConfig + configuration: customConfig, + repositoryUtils: repositoryUtils }) expect(resultChangelog).toStrictEqual(`https://github.com/mikepenz/release-changelog-builder-action/compare/v2.8.0...v2.8.1\n`) @@ -678,6 +682,7 @@ function buildChangelogTest(config: Configuration, prs: PullRequestInfo[]): stri fetchReleaseInformation: false, fetchReviews: false, commitMode: false, - configuration: config + configuration: config, + repositoryUtils: repositoryUtils }) } diff --git a/configs/configuration_gitea.json b/configs/configuration_gitea.json new file mode 100644 index 0000000..527d08e --- /dev/null +++ b/configs/configuration_gitea.json @@ -0,0 +1,29 @@ +{ + "categories": [ + { + "title": "## ๐Ÿš€ Features", + "labels": ["add","Add"] + }, + { + "title": "## ๐Ÿ› Fixes", + "labels": ["fix","Fix"] + }, + { + "title": "## ๐Ÿงช Upgrade", + "labels": ["upgrade","Upgrade","Clean"] + } + ], + "label_extractor": [ + { + "pattern": "(\\w+) (.+)", + "target": "$1", + "on_property": "title" + } + ], + "sort": "ASC", + "template": "${{CHANGELOG}}", + "pr_template": "- ${{TITLE}}\n - PR: #${{NUMBER}}", + "empty_template": "- no changes", + "max_pull_requests": 1000, + "max_back_track_time_days": 1000 +} \ No newline at end of file diff --git a/configs_test/configuration_gitea_desc.json b/configs_test/configuration_gitea_desc.json new file mode 100644 index 0000000..4b5d667 --- /dev/null +++ b/configs_test/configuration_gitea_desc.json @@ -0,0 +1,29 @@ +{ + "categories": [ + { + "title": "## ๐Ÿš€ Features", + "labels": ["add","Add"] + }, + { + "title": "## ๐Ÿ› Fixes", + "labels": ["fix","Fix"] + }, + { + "title": "## ๐Ÿงช Upgrade", + "labels": ["upgrade","Upgrade","Clean"] + } + ], + "label_extractor": [ + { + "pattern": "(\\w+) (.+)", + "target": "$1", + "on_property": "title" + } + ], + "sort": "DESC", + "template": "${{CHANGELOG}}", + "pr_template": "- ${{TITLE}}\n - PR: #${{NUMBER}}", + "empty_template": "- no changes", + "max_pull_requests": 1000, + "max_back_track_time_days": 1000 +} \ No newline at end of file