From b8fa364bab5e86b78ffb325d3212a0a394d4ab56 Mon Sep 17 00:00:00 2001 From: Bob Loblaw Date: Thu, 23 Jan 2025 21:31:13 +0100 Subject: [PATCH] Implement commit_template --- __tests__/configuration.test.ts | 48 +- __tests__/releaseNotesBuilderPull.test.ts | 184 ++++++- __tests__/transform.test.ts | 9 +- ...al-hybrid-separate-cats-1e1c8e-325b74.json | 470 ++++++++++++++++++ src/configuration.ts | 4 +- src/transform.ts | 67 ++- src/utils.ts | 26 +- 7 files changed, 794 insertions(+), 14 deletions(-) create mode 100644 caches/github_conventional-hybrid-separate-cats-1e1c8e-325b74.json diff --git a/__tests__/configuration.test.ts b/__tests__/configuration.test.ts index b637589..9f58fbf 100644 --- a/__tests__/configuration.test.ts +++ b/__tests__/configuration.test.ts @@ -15,8 +15,50 @@ 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}` + const expectedStringified = JSON.stringify(mergedConfiguration, null, 2) + + expect(expectedStringified).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}}", + "commit_template": "- #{{TITLE}}", + "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 +}` ) }) diff --git a/__tests__/releaseNotesBuilderPull.test.ts b/__tests__/releaseNotesBuilderPull.test.ts index 99ef1bb..302b717 100644 --- a/__tests__/releaseNotesBuilderPull.test.ts +++ b/__tests__/releaseNotesBuilderPull.test.ts @@ -367,7 +367,7 @@ it('Default configuration with commit mode', async () => { it('Default configuration with commit mode and custom placeholder', async () => { const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'COMMIT')) - configuration.pr_template = '- #{{TITLE_ONLY}}' + configuration.commit_template = '- #{{TITLE_ONLY}}' configuration.trim_values = true configuration.custom_placeholders = [ { @@ -408,3 +408,185 @@ it('Default configuration with commit mode and custom placeholder', async () => `## πŸš€ Features\n\n- add Bengali\n- add uzbek translation (#558)\n\n## πŸ› Fixes\n\n- Fix grammar and consistency in french translation (#546)\n- fix typo\n- Distinguish translations of 'Release/Publish'\n- fix translation typo for message (#567)\n\n## πŸ“¦ Other\n\n- new thi.ng links and descriptions\n- add link to git-changelog-command-line docker image\n- Add descriptions for commit types` ) }) + +it('Default configuration with hybrid mode and classic categories', async () => { + const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'HYBRID')) + const options = { + owner: 'conventional-commits', + repo: 'conventionalcommits.org', + fromTag: {name: '56cdc85d01fd11aa164bd958bbf6114a51abfcf6'}, + toTag: {name: '325b74fbc44bf34d9fa645951d076a450b4e26be'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: false, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + mode: 'HYBRID', + configuration, + repositoryUtils: githubRepository + } as ReleaseNotesOptions & Options + let data: any + if (enablePullData) { + data = await pullData(githubRepository, options as Options) + } else { + data = checkExportedData(false, 'caches/github_conventional-hybrid-1e1c8e-325b74.json') + } + const releaseNotesOptions = {...options, ...(data?.options ? data.options : {})} as unknown as ReleaseNotesOptions + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, releaseNotesOptions) + console.log(changeLog) + + const expected = `## πŸš€ Features + +- feat(lang): add Bengali +- feat(lang): add uzbek translation (#558) + +## πŸ› Fixes + +- fix: Fix grammar and consistency in french translation (#546) +- fix(ja): fix typo +- fix(zh-hant): Distinguish translations of 'Release/Publish' +- fix(ko): fix translation typo for message (#567) + +## πŸ“¦ Other + +- fix: Fix grammar and consistency in french translation +- Add/update tool/project links +- fix(ja): fix typo +- docs: add link to git-changelog-command-line docker image +- docs: Add descriptions for commit types +- fix(zh-hant): Distinguish translations of 'Release/Publish' +- "feat(lang): add Bengali translation" +- feat(lang): add uzbek translation +- fix(ko): fix translation typo for message +- doc: new thi.ng links and descriptions +- docs: add link to git-changelog-command-line docker image +- docs: Add descriptions for commit types + +` + + expect(changeLog).toStrictEqual(expected) +}) + +it('Default configuration with hybrid mode and with separate feature categories', async () => { + const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'HYBRID')) + const options = { + owner: 'conventional-commits', + repo: 'conventionalcommits.org', + fromTag: {name: '56cdc85d01fd11aa164bd958bbf6114a51abfcf6'}, + toTag: {name: '325b74fbc44bf34d9fa645951d076a450b4e26be'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: false, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + mode: 'HYBRID', + configuration, + repositoryUtils: githubRepository + } as ReleaseNotesOptions & Options + let data: any + if (enablePullData) { + data = await pullData(githubRepository, options as Options) + } else { + data = checkExportedData(false, 'caches/github_conventional-hybrid-separate-cats-1e1c8e-325b74.json') + } + const releaseNotesOptions = {...options, ...(data?.options ? data.options : {})} as unknown as ReleaseNotesOptions + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, releaseNotesOptions) + console.log(changeLog) + + const expected = `## πŸš€ Big features + +- feat(lang): add uzbek translation + +## πŸš€ Small features + +- feat(lang): add Bengali +- feat(lang): add uzbek translation (#558) + +## πŸ› Fixes + +- fix: Fix grammar and consistency in french translation +- fix(ja): fix typo +- fix(zh-hant): Distinguish translations of 'Release/Publish' +- fix(ko): fix translation typo for message +- fix: Fix grammar and consistency in french translation (#546) +- fix(ja): fix typo +- fix(zh-hant): Distinguish translations of 'Release/Publish' +- fix(ko): fix translation typo for message (#567) + +## πŸ“¦ Other + +- Add/update tool/project links +- docs: add link to git-changelog-command-line docker image +- docs: Add descriptions for commit types +- "feat(lang): add Bengali translation" +- doc: new thi.ng links and descriptions +- docs: add link to git-changelog-command-line docker image +- docs: Add descriptions for commit types + +` + + expect(changeLog).toStrictEqual(expected) +}) +it('Default configuration with hybrid mode and with separate feature categories and dup checker', async () => { + const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'HYBRID')) + const options = { + owner: 'conventional-commits', + repo: 'conventionalcommits.org', + fromTag: {name: '56cdc85d01fd11aa164bd958bbf6114a51abfcf6'}, + toTag: {name: '325b74fbc44bf34d9fa645951d076a450b4e26be'}, + includeOpen: false, + failOnError: false, + fetchViaCommits: false, + fetchReviewers: false, + fetchReleaseInformation: false, + fetchReviews: false, + mode: 'HYBRID', + configuration, + repositoryUtils: githubRepository + } as ReleaseNotesOptions & Options + let data: any + if (enablePullData) { + data = await pullData(githubRepository, options as Options) + } else { + data = checkExportedData(false, 'caches/github_conventional-hybrid-separate-cats-1e1c8e-325b74.json') + } + const releaseNotesOptions = {...options, ...(data?.options ? data.options : {})} as unknown as ReleaseNotesOptions + + releaseNotesOptions.configuration.duplicate_filter = { + pattern: '(.+) \\(#\\d+\\)', + target: '$1', + on_property: 'title' + } + + const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, releaseNotesOptions) + console.log(changeLog) + + // Test author's note: Here I was hoping the "add uzbek translation" pr would be categorized + // as a Big feature, but due to how duplicates are handled (i.e. previous ones get replaced by following duplicates) + // it ends up as a Small feature. I'm not sure if this is the desired behavior or not, but I'm leaving it as is for now. + const expected = `## πŸš€ Small features + +- feat(lang): add Bengali +- feat(lang): add uzbek translation (#558) + +## πŸ› Fixes + +- fix: Fix grammar and consistency in french translation +- fix(ja): fix typo +- fix(zh-hant): Distinguish translations of 'Release/Publish' +- fix(ko): fix translation typo for message (#567) + +## πŸ“¦ Other + +- Add/update tool/project links +- "feat(lang): add Bengali translation" +- doc: new thi.ng links and descriptions +- docs: add link to git-changelog-command-line docker image +- docs: Add descriptions for commit types + +` + + expect(changeLog).toStrictEqual(expected) +}) diff --git a/__tests__/transform.test.ts b/__tests__/transform.test.ts index 7d02a6d..12230da 100644 --- a/__tests__/transform.test.ts +++ b/__tests__/transform.test.ts @@ -477,9 +477,14 @@ const repositoryUtils = new GithubRepository(process.env.GITEA_TOKEN || '', unde it('Commit SHA-1 in commitMode', async () => { const customConfig = Object.assign({}, DefaultConfiguration) customConfig.sort = 'DESC' - customConfig.pr_template = '#{{MERGE_SHA}}' + customConfig.commit_template = '#{{MERGE_SHA}}' - const resultChangelog = buildChangelog(DefaultDiffInfo, pullRequestsWithLabels, { + // Since this is COMMIT mode, the prs would have been built with "number: 0" + const convertedPrs = pullRequestsWithLabels.map(pr => { + return {...pr, number: 0} + }) + + const resultChangelog = buildChangelog(DefaultDiffInfo, convertedPrs, { owner: 'mikepenz', repo: 'test-repo', fromTag: {name: '1.0.0'}, diff --git a/caches/github_conventional-hybrid-separate-cats-1e1c8e-325b74.json b/caches/github_conventional-hybrid-separate-cats-1e1c8e-325b74.json new file mode 100644 index 0000000..3b0d7e4 --- /dev/null +++ b/caches/github_conventional-hybrid-separate-cats-1e1c8e-325b74.json @@ -0,0 +1,470 @@ +{ + "mergedPullRequests": [ + { + "number": 546, + "title": "fix: Fix grammar and consistency in french translation", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/546", + "baseBranch": "master", + "branch": "patch-1", + "createdAt": "2023-09-11T18:44:40.000Z", + "mergedAt": "2023-10-18T23:36:08.000Z", + "mergeCommitSha": "fcb21b478f78297850894c71abee35ab98042823", + "author": "Yopai", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "I've reviewed the whole text to make it more natural for a native french speaking.", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 550, + "title": "Add/update tool/project links", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/550", + "baseBranch": "master", + "branch": "patch-1", + "createdAt": "2023-10-19T10:31:50.000Z", + "mergedAt": "2023-10-19T10:44:22.000Z", + "mergeCommitSha": "79d1a4cbdbf9f04eebc531c0e76e7fbb8ebb4b95", + "author": "postspectacular", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "- add link to thi.ng/monopub release tool\r\n- update thi.ng/umbrella project description", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 512, + "title": "fix(ja): fix typo", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/512", + "baseBranch": "master", + "branch": "patch-1", + "createdAt": "2023-03-14T15:13:19.000Z", + "mergedAt": "2023-10-19T10:45:42.000Z", + "mergeCommitSha": "64ae03aacea2a3cf5271f4217d266db10f2c3043", + "author": "moritasoshi", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "Fixed `ζ„ε‘³ηš„γ«γ‚’` -> `ζ„ε‘³ηš„γ«`.\r\n\r\n`ζ„ε‘³ηš„γ«γ‚’` is incorrect Japanese.", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 530, + "title": "docs: add link to git-changelog-command-line docker image", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/530", + "baseBranch": "master", + "branch": "feature/git-changelog-command-line-docker", + "createdAt": "2023-06-11T07:32:14.000Z", + "mergedAt": "2023-10-19T10:47:20.000Z", + "mergeCommitSha": "158a7b14ef1f8c24b3e9a7cee97bd0e2c0bd6397", + "author": "tomasbjerre", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 527, + "title": "docs: Add descriptions for commit types", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/527", + "baseBranch": "master", + "branch": "docs/zh-hans", + "createdAt": "2023-05-19T09:56:11.000Z", + "mergedAt": "2023-10-19T10:48:46.000Z", + "mergeCommitSha": "551cfd47a533f6222d0c9c06af096d4076b48bc9", + "author": "HExris", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 520, + "title": "fix(zh-hant): Distinguish translations of 'Release/Publish'", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/520", + "baseBranch": "master", + "branch": "fix-release-publish", + "createdAt": "2023-04-17T17:48:40.000Z", + "mergedAt": "2023-10-19T10:49:51.000Z", + "mergeCommitSha": "5b935ded2e6b2cbdb3cf24f327b49ed23e31858d", + "author": "hwhsu1231", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "Before:\r\n\r\n* Release: η™ΌεΈƒ, η‰ˆζœ¬, η‰ˆζœ¬ι‡‹ε‡Ί\r\n* Publish: η™ΌεΈƒ\r\n\r\nAfter:\r\n\r\n* Release: η™Όθ‘Œ(η‰ˆ)\r\n* Publish: η™ΌεΈƒ", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 551, + "title": "\"feat(lang): add Bengali translation\" ", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/551", + "baseBranch": "master", + "branch": "master", + "createdAt": "2023-10-30T22:10:26.000Z", + "mergedAt": "2023-11-05T13:42:26.000Z", + "mergeCommitSha": "69f9447d5648efb3bb028bc27a2276fcacb9a20d", + "author": "forhadakhan", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "This will add the Bengali translation.", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 558, + "title": "feat(lang): add uzbek translation", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/558", + "baseBranch": "master", + "branch": "feature/add-uzbek-lang", + "createdAt": "2024-01-02T12:32:12.000Z", + "mergedAt": "2024-01-22T07:55:14.000Z", + "mergeCommitSha": "f777146b5d331c9ee33b0028e861df14e3992fe9", + "author": "softXengineer", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 567, + "title": "fix(ko): fix translation typo for message", + "htmlURL": "https://github.com/conventional-commits/conventionalcommits.org/pull/567", + "baseBranch": "master", + "branch": "master", + "createdAt": "2024-01-29T12:05:13.000Z", + "mergedAt": "2024-01-29T12:49:09.000Z", + "mergeCommitSha": "325b74fbc44bf34d9fa645951d076a450b4e26be", + "author": "Igoc", + "repoName": "conventional-commits/conventionalcommits.org", + "labels": ["--rcba-merged"], + "milestone": "", + "body": "Fixed `λ©”μ„Έμ§€` β†’ `λ©”μ‹œμ§€`.\r\n\r\nReference: [ꡭ립ꡭ어원 ν‘œμ€€κ΅­μ–΄λŒ€μ‚¬μ „](https://stdict.korean.go.kr/search/searchView.do?word_no=113651&searchKeywordTo=3)", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "fix: Fix grammar and consistency in french translation (#546)", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2023-10-18T23:36:07.000Z", + "mergedAt": "2023-10-18T23:36:07.000Z", + "mergeCommitSha": "fcb21b478f78297850894c71abee35ab98042823", + "author": "Yopai", + "repoName": "", + "labels": [], + "milestone": "", + "body": "fix: Fix grammar and consistency in french translation (#546)", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "doc: new thi.ng links and descriptions", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2023-10-19T10:44:22.000Z", + "mergedAt": "2023-10-19T10:44:22.000Z", + "mergeCommitSha": "79d1a4cbdbf9f04eebc531c0e76e7fbb8ebb4b95", + "author": "postspectacular", + "repoName": "", + "labels": [], + "milestone": "", + "body": "doc: new thi.ng links and descriptions", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "fix(ja): fix typo", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2023-10-19T10:45:42.000Z", + "mergedAt": "2023-10-19T10:45:42.000Z", + "mergeCommitSha": "64ae03aacea2a3cf5271f4217d266db10f2c3043", + "author": "moritasoshi", + "repoName": "", + "labels": [], + "milestone": "", + "body": "fix(ja): fix typo", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "docs: add link to git-changelog-command-line docker image", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2023-10-19T10:47:20.000Z", + "mergedAt": "2023-10-19T10:47:20.000Z", + "mergeCommitSha": "158a7b14ef1f8c24b3e9a7cee97bd0e2c0bd6397", + "author": "tomasbjerre", + "repoName": "", + "labels": [], + "milestone": "", + "body": "docs: add link to git-changelog-command-line docker image", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "docs: Add descriptions for commit types", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2023-10-19T10:48:46.000Z", + "mergedAt": "2023-10-19T10:48:46.000Z", + "mergeCommitSha": "551cfd47a533f6222d0c9c06af096d4076b48bc9", + "author": "HExris", + "repoName": "", + "labels": [], + "milestone": "", + "body": "docs: Add descriptions for commit types", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "fix(zh-hant): Distinguish translations of 'Release/Publish'", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2023-10-19T10:49:51.000Z", + "mergedAt": "2023-10-19T10:49:51.000Z", + "mergeCommitSha": "5b935ded2e6b2cbdb3cf24f327b49ed23e31858d", + "author": "hwhsu1231", + "repoName": "", + "labels": [], + "milestone": "", + "body": "fix(zh-hant): Distinguish translations of 'Release/Publish'", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "feat(lang): add Bengali", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2023-11-05T13:42:26.000Z", + "mergedAt": "2023-11-05T13:42:26.000Z", + "mergeCommitSha": "69f9447d5648efb3bb028bc27a2276fcacb9a20d", + "author": "forhadakhan", + "repoName": "", + "labels": [], + "milestone": "", + "body": "feat(lang): add Bengali", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "feat(lang): add uzbek translation (#558)", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2024-01-22T07:55:14.000Z", + "mergedAt": "2024-01-22T07:55:14.000Z", + "mergeCommitSha": "f777146b5d331c9ee33b0028e861df14e3992fe9", + "author": "softXengineer", + "repoName": "", + "labels": [], + "milestone": "", + "body": "feat(lang): add uzbek translation (#558)", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + }, + { + "number": 0, + "title": "fix(ko): fix translation typo for message (#567)", + "htmlURL": "", + "baseBranch": "", + "createdAt": "2024-01-29T12:49:09.000Z", + "mergedAt": "2024-01-29T12:49:09.000Z", + "mergeCommitSha": "325b74fbc44bf34d9fa645951d076a450b4e26be", + "author": "Igoc", + "repoName": "", + "labels": [], + "milestone": "", + "body": "fix(ko): fix translation typo for message (#567)", + "assignees": [], + "requestedReviewers": [], + "approvedReviewers": [], + "status": "merged" + } + ], + "diffInfo": { + "changedFiles": 11, + "additions": 579, + "deletions": 96, + "changes": 675, + "commits": 9, + "commitInfo": [ + { + "sha": "fcb21b478f78297850894c71abee35ab98042823", + "summary": "fix: Fix grammar and consistency in french translation (#546)", + "message": "fix: Fix grammar and consistency in french translation (#546)", + "author": "Yopai", + "authorDate": "2023-10-18T23:36:07.000Z", + "committer": "web-flow", + "commitDate": "2023-10-18T23:36:07.000Z" + }, + { + "sha": "79d1a4cbdbf9f04eebc531c0e76e7fbb8ebb4b95", + "summary": "doc: new thi.ng links and descriptions", + "message": "doc: new thi.ng links and descriptions", + "author": "postspectacular", + "authorDate": "2023-10-19T10:44:22.000Z", + "committer": "web-flow", + "commitDate": "2023-10-19T10:44:22.000Z" + }, + { + "sha": "64ae03aacea2a3cf5271f4217d266db10f2c3043", + "summary": "fix(ja): fix typo", + "message": "fix(ja): fix typo", + "author": "moritasoshi", + "authorDate": "2023-10-19T10:45:42.000Z", + "committer": "web-flow", + "commitDate": "2023-10-19T10:45:42.000Z" + }, + { + "sha": "158a7b14ef1f8c24b3e9a7cee97bd0e2c0bd6397", + "summary": "docs: add link to git-changelog-command-line docker image", + "message": "docs: add link to git-changelog-command-line docker image", + "author": "tomasbjerre", + "authorDate": "2023-10-19T10:47:20.000Z", + "committer": "web-flow", + "commitDate": "2023-10-19T10:47:20.000Z" + }, + { + "sha": "551cfd47a533f6222d0c9c06af096d4076b48bc9", + "summary": "docs: Add descriptions for commit types", + "message": "docs: Add descriptions for commit types", + "author": "HExris", + "authorDate": "2023-10-19T10:48:46.000Z", + "committer": "web-flow", + "commitDate": "2023-10-19T10:48:46.000Z" + }, + { + "sha": "5b935ded2e6b2cbdb3cf24f327b49ed23e31858d", + "summary": "fix(zh-hant): Distinguish translations of 'Release/Publish'", + "message": "fix(zh-hant): Distinguish translations of 'Release/Publish'", + "author": "hwhsu1231", + "authorDate": "2023-10-19T10:49:51.000Z", + "committer": "web-flow", + "commitDate": "2023-10-19T10:49:51.000Z" + }, + { + "sha": "69f9447d5648efb3bb028bc27a2276fcacb9a20d", + "summary": "feat(lang): add Bengali", + "message": "feat(lang): add Bengali", + "author": "forhadakhan", + "authorDate": "2023-11-05T13:42:26.000Z", + "committer": "web-flow", + "commitDate": "2023-11-05T13:42:26.000Z" + }, + { + "sha": "f777146b5d331c9ee33b0028e861df14e3992fe9", + "summary": "feat(lang): add uzbek translation (#558)", + "message": "feat(lang): add uzbek translation (#558)", + "author": "softXengineer", + "authorDate": "2024-01-22T07:55:14.000Z", + "committer": "web-flow", + "commitDate": "2024-01-22T07:55:14.000Z" + }, + { + "sha": "325b74fbc44bf34d9fa645951d076a450b4e26be", + "summary": "fix(ko): fix translation typo for message (#567)", + "message": "fix(ko): fix translation typo for message (#567)", + "author": "Igoc", + "authorDate": "2024-01-29T12:49:09.000Z", + "committer": "web-flow", + "commitDate": "2024-01-29T12:49:09.000Z" + } + ] + }, + "options": { + "owner": "conventional-commits", + "repo": "conventionalcommits.org", + "fromTag": {"name": "1e1c8e11e6cb7e555e5e53f8eed5ba5fc5029993"}, + "toTag": {"name": "325b74fbc44bf34d9fa645951d076a450b4e26be"}, + "includeOpen": false, + "failOnError": false, + "fetchViaCommits": false, + "fetchReviewers": false, + "fetchReleaseInformation": false, + "fetchReviews": false, + "mode": "HYBRID", + "configuration": { + "max_tags_to_fetch": 200, + "max_pull_requests": 200, + "max_back_track_time_days": 365, + "exclude_merge_branches": [], + "sort": {"order": "ASC", "on_property": "mergedAt"}, + "template": "#{{CHANGELOG}}", + "pr_template": "- #{{TITLE}}", + "empty_template": "- no changes", + "categories": [ + {"title": "## πŸš€ Big features", "labels": ["feature", "feat"], "mode": "PR"}, + {"title": "## πŸš€ Small features", "labels": ["feature", "feat"], "mode": "COMMIT"}, + {"title": "## πŸ› Fixes", "labels": ["fix", "bug"]}, + {"title": "## πŸ§ͺ Tests", "labels": ["test"]}, + {"title": "## πŸ“¦ Other", "labels": []} + ], + "ignore_labels": ["ignore"], + "label_extractor": [ + { + "pattern": "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\\([\\w\\-\\.]+\\))?(!)?: ([\\w ])+([\\s\\S]*)", + "target": "$1", + "on_property": "title" + } + ], + "transformers": [], + "tag_resolver": {"method": "semver"}, + "base_branches": [], + "custom_placeholders": [], + "trim_values": false + } + } +} diff --git a/src/configuration.ts b/src/configuration.ts index 6c33520..2d9a979 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -3,6 +3,7 @@ import {Extractor, PullConfiguration, Regex, Rule} from './pr-collector/types.js export interface Configuration extends PullConfiguration { template: string pr_template: string + commit_template: string // (COMMIT and HYBRID mode only for PRs converted to commits) empty_template: string categories: Category[] ignore_labels: string[] @@ -25,6 +26,7 @@ export interface Category { empty_content?: string // if the category has no matching PRs, this content will be used. If not set, the category will be skipped in the changelog. categories?: Category[] // allows for nested categories, items matched for a child category won't show up in the parent consume?: boolean // defines if the matched PR will be consumed by this category. Consumed PRs won't show up in any category *after* + mode?: 'HYBRID' | 'COMMIT' | 'PR' // defines if this category applies to PRs, commits or both entries?: string[] // array of single changelog entries, used to construct the changelog. (this is filled during the build) } @@ -70,6 +72,7 @@ export const DefaultConfiguration: Configuration = { }, template: '#{{CHANGELOG}}', // the global template to host the changelog pr_template: '- #{{TITLE}}\n - PR: ##{{NUMBER}}', // the per PR template to pick + commit_template: '- #{{TITLE}}', // the per PR template to pick for commit based mode empty_template: '- no changes', // the template to use if no pull requests are found categories: [ { @@ -106,7 +109,6 @@ export const DefaultConfiguration: Configuration = { export const DefaultCommitConfiguration: Configuration = { ...DefaultConfiguration, - pr_template: '- #{{TITLE}}', // the per PR template to pick categories: [ { title: '## πŸš€ Features', diff --git a/src/transform.ts b/src/transform.ts index ad583e9..e8d3c5d 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -127,22 +127,47 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o core.info(`ℹ️ Using ${validatedTransformers.length} transformers to rewrite content`) + const includePrs = options.mode === 'PR' || options.mode === 'HYBRID' + const includeCommits = options.mode === 'COMMIT' || options.mode === 'HYBRID' + + // convert PRs to their text representation + const realPrs = includePrs ? prs.filter(x => x.number !== 0) : [] + const commitPrs = includeCommits ? prs.filter(x => x.number === 0) : [] + if (validatedTransformers.length > 0) { for (const pr of prs) { const prAsObject = pr as unknown as Record transformObject(prAsObject, validatedTransformers) } - core.info(`βœ’οΈ Transformed ${prs.length} pull requests`) + + if (includePrs) { + core.info(`βœ’οΈ Transformed ${realPrs.length} pull requests`) + } + + if (includeCommits) { + core.info(`βœ’οΈ Transformed ${commitPrs.length} commits`) + } } const prInfoMap = buildInfoMapAndFillPlaceholderContext( - prs, + realPrs, config.pr_template, groupedPlaceholders, customPlaceholdersTemplateContext, config ) + const commitInfoMap = buildInfoMapAndFillPlaceholderContext( + commitPrs, + config.commit_template, + groupedPlaceholders, + customPlaceholdersTemplateContext, + config + ) + + // If the mode is not HYBRID, the map will contain only one or the other map + const combinedInfoMap = mergeMaps(prInfoMap, commitInfoMap) + // bring PRs into the order of categories const categories = config.categories const flatCategories = flatten(config.categories) @@ -154,7 +179,7 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o } } - const prStrings = buildPrStringsAndFillCategoryEntries(prInfoMap, config.ignore_labels, categories, flatCategories) + const prStrings = buildPrStringsAndFillCategoryEntries(combinedInfoMap, config.ignore_labels, categories, flatCategories) core.info(`ℹ️ Ordered all pull requests into ${categories.length} categories`) // serialize and provide the categorized content as json @@ -272,7 +297,8 @@ function buildPrStringsAndFillCategoryEntries( } let matchedOnce = false // in case we matched once at least, the PR can't be uncategorized - for (const category of categories) { + const filteredCategories = filterCategoriesByPrType(categories, pr) + for (const category of filteredCategories) { const [matched, consumed] = recursiveCategorizePr(category, pr, body) if (consumed) { continue prLoop @@ -282,7 +308,8 @@ function buildPrStringsAndFillCategoryEntries( if (!matchedOnce) { // we allow to have pull requests included in an "uncategorized" category - for (const category of flatCategories) { + const filteredFlatCategories = filterCategoriesByPrType(flatCategories, pr) + for (const category of filteredFlatCategories) { category.entries = category.entries || [] if ((category.labels === undefined || category.labels.length === 0) && category.rules === undefined) { // check if any exclude label matches for the "uncategorized" category @@ -546,7 +573,15 @@ export function renderEmptyChangelogTemplate(template: string, options: ReleaseN const releaseNotesTemplateContext = buildCoreReleaseNotesTemplateContext(options) - return renderTemplateAndFillPlaceholderContext(template, releaseNotesTemplateContext, placeholders, undefined, options.configuration) + const renderedEmptyChangelogTemplate = renderTemplateAndFillPlaceholderContext( + template, + releaseNotesTemplateContext, + placeholders, + undefined, + options.configuration + ) + + return renderedEmptyChangelogTemplate } function buildCoreReleaseNotesTemplateContext(options: ReleaseNotesOptions): TemplateContext { @@ -867,3 +902,23 @@ function hasChildWithEntries(category: Category): boolean { } return hasEntries } + +/** + * Filters the provided categories based on the type of pull request information. + * + * @param {Category[]} categories - The list of categories to filter. + * @param {PullRequestInfo} prInfo - The pull request information used to determine the type of PR. + * @returns {Category[]} The filtered list of categories: + * - If 'prInfo' represents a real pull request (has a number other than 0), it excludes categories with mode 'COMMIT'. + * - If 'prInfo' represents a commit (has number 0), it excludes categories with mode 'PR'. + * - Defaults to keeping categories with mode 'HYBRID' in either case. + */ +function filterCategoriesByPrType(categories: Category[], prInfo: PullRequestInfo): Category[] { + const isRealPr = prInfo.number !== 0 + + if (isRealPr) { + return categories.filter(category => (category.mode || 'HYBRID') !== 'COMMIT') + } else { + return categories.filter(category => (category.mode || 'HYBRID') !== 'PR') + } +} diff --git a/src/utils.ts b/src/utils.ts index 293c898..10573ba 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -107,6 +107,16 @@ export function checkExportedData(exportCache: boolean, cacheInput: string | nul options.toTag.date = moment(options.toTag.date) } + // Handle backwards compatibility for addition of `commit_template` in COMMIT and HYBRID mode + // If there is no provided commit_template, fallback to the provided pr_template, + // and if that is not provided either, fallback to the default commit_template + const {mode, configuration} = options + const prTemplate = configuration?.pr_template + const commitTemplate = configuration?.commit_template + if ((mode === 'COMMIT' || mode === 'HYBRID') && !commitTemplate) { + options.configuration.commit_template = prTemplate || DefaultConfiguration.commit_template + } + return { diffInfo, mergedPullRequests, @@ -198,6 +208,19 @@ export function mergeConfiguration(jc?: Configuration, fc?: Configuration, mode? def = DefaultConfiguration } + // Handle backwards compatibility for addition of `commit_template` in COMMIT and HYBRID mode + // If there is no provided commit_template, fallback to the provided pr_template, + // and if that is not provided either, fallback to the default commit_template + const prTemplate = jc?.pr_template || fc?.pr_template + let commitTemplate = jc?.commit_template || fc?.commit_template + if ((mode === 'COMMIT' || mode === 'HYBRID') && !commitTemplate) { + if (prTemplate) { + commitTemplate = prTemplate + } else { + commitTemplate = def.commit_template + } + } + return { max_tags_to_fetch: jc?.max_tags_to_fetch || fc?.max_tags_to_fetch || def.max_tags_to_fetch, max_pull_requests: jc?.max_pull_requests || fc?.max_pull_requests || def.max_pull_requests, @@ -205,7 +228,8 @@ export function mergeConfiguration(jc?: Configuration, fc?: Configuration, mode? exclude_merge_branches: jc?.exclude_merge_branches || fc?.exclude_merge_branches || def.exclude_merge_branches, sort: jc?.sort || fc?.sort || def.sort, template: jc?.template || fc?.template || def.template, - pr_template: jc?.pr_template || fc?.pr_template || def.pr_template, + pr_template: prTemplate || def.pr_template, + commit_template: commitTemplate || def.commit_template, empty_template: jc?.empty_template || fc?.empty_template || def.empty_template, categories: jc?.categories || fc?.categories || def.categories, ignore_labels: jc?.ignore_labels || fc?.ignore_labels || def.ignore_labels,