Implement commit_template

This commit is contained in:
Bob Loblaw
2025-01-31 20:10:11 +01:00
committed by Mike Penz
parent 623490aa2a
commit b8fa364bab
7 changed files with 794 additions and 14 deletions
+45 -3
View File
@@ -15,8 +15,50 @@ it('Configurations are merged correctly', async () => {
const mergedConfiguration = mergeConfiguration(configurationJson, configurationFile) const mergedConfiguration = mergeConfiguration(configurationJson, configurationFile)
console.log(mergedConfiguration) const expectedStringified = JSON.stringify(mergedConfiguration, null, 2)
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(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
}`
) )
}) })
+183 -1
View File
@@ -367,7 +367,7 @@ it('Default configuration with commit mode', async () => {
it('Default configuration with commit mode and custom placeholder', async () => { it('Default configuration with commit mode and custom placeholder', async () => {
const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'COMMIT')) const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'COMMIT'))
configuration.pr_template = '- #{{TITLE_ONLY}}' configuration.commit_template = '- #{{TITLE_ONLY}}'
configuration.trim_values = true configuration.trim_values = true
configuration.custom_placeholders = [ 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` `## 🚀 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)
})
+7 -2
View File
@@ -477,9 +477,14 @@ const repositoryUtils = new GithubRepository(process.env.GITEA_TOKEN || '', unde
it('Commit SHA-1 in commitMode', async () => { it('Commit SHA-1 in commitMode', async () => {
const customConfig = Object.assign({}, DefaultConfiguration) const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.sort = 'DESC' 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', owner: 'mikepenz',
repo: 'test-repo', repo: 'test-repo',
fromTag: {name: '1.0.0'}, fromTag: {name: '1.0.0'},
@@ -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
}
}
}
+3 -1
View File
@@ -3,6 +3,7 @@ import {Extractor, PullConfiguration, Regex, Rule} from './pr-collector/types.js
export interface Configuration extends PullConfiguration { export interface Configuration extends PullConfiguration {
template: string template: string
pr_template: string pr_template: string
commit_template: string // (COMMIT and HYBRID mode only for PRs converted to commits)
empty_template: string empty_template: string
categories: Category[] categories: Category[]
ignore_labels: string[] 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. 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 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* 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) 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 template: '#{{CHANGELOG}}', // the global template to host the changelog
pr_template: '- #{{TITLE}}\n - PR: ##{{NUMBER}}', // the per PR template to pick 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 empty_template: '- no changes', // the template to use if no pull requests are found
categories: [ categories: [
{ {
@@ -106,7 +109,6 @@ export const DefaultConfiguration: Configuration = {
export const DefaultCommitConfiguration: Configuration = { export const DefaultCommitConfiguration: Configuration = {
...DefaultConfiguration, ...DefaultConfiguration,
pr_template: '- #{{TITLE}}', // the per PR template to pick
categories: [ categories: [
{ {
title: '## 🚀 Features', title: '## 🚀 Features',
+61 -6
View File
@@ -127,22 +127,47 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o
core.info(`️ Using ${validatedTransformers.length} transformers to rewrite content`) 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) { if (validatedTransformers.length > 0) {
for (const pr of prs) { for (const pr of prs) {
const prAsObject = pr as unknown as Record<string, unknown> const prAsObject = pr as unknown as Record<string, unknown>
transformObject(prAsObject, validatedTransformers) 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( const prInfoMap = buildInfoMapAndFillPlaceholderContext(
prs, realPrs,
config.pr_template, config.pr_template,
groupedPlaceholders, groupedPlaceholders,
customPlaceholdersTemplateContext, customPlaceholdersTemplateContext,
config 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 // bring PRs into the order of categories
const categories = config.categories const categories = config.categories
const flatCategories = flatten(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`) core.info(`️ Ordered all pull requests into ${categories.length} categories`)
// serialize and provide the categorized content as json // 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 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) const [matched, consumed] = recursiveCategorizePr(category, pr, body)
if (consumed) { if (consumed) {
continue prLoop continue prLoop
@@ -282,7 +308,8 @@ function buildPrStringsAndFillCategoryEntries(
if (!matchedOnce) { if (!matchedOnce) {
// we allow to have pull requests included in an "uncategorized" category // we allow to have pull requests included in an "uncategorized" category
for (const category of flatCategories) { const filteredFlatCategories = filterCategoriesByPrType(flatCategories, pr)
for (const category of filteredFlatCategories) {
category.entries = category.entries || [] category.entries = category.entries || []
if ((category.labels === undefined || category.labels.length === 0) && category.rules === undefined) { if ((category.labels === undefined || category.labels.length === 0) && category.rules === undefined) {
// check if any exclude label matches for the "uncategorized" category // 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) 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 { function buildCoreReleaseNotesTemplateContext(options: ReleaseNotesOptions): TemplateContext {
@@ -867,3 +902,23 @@ function hasChildWithEntries(category: Category): boolean {
} }
return hasEntries 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')
}
}
+25 -1
View File
@@ -107,6 +107,16 @@ export function checkExportedData(exportCache: boolean, cacheInput: string | nul
options.toTag.date = moment(options.toTag.date) 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 { return {
diffInfo, diffInfo,
mergedPullRequests, mergedPullRequests,
@@ -198,6 +208,19 @@ export function mergeConfiguration(jc?: Configuration, fc?: Configuration, mode?
def = DefaultConfiguration 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 { return {
max_tags_to_fetch: jc?.max_tags_to_fetch || fc?.max_tags_to_fetch || def.max_tags_to_fetch, 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, 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, exclude_merge_branches: jc?.exclude_merge_branches || fc?.exclude_merge_branches || def.exclude_merge_branches,
sort: jc?.sort || fc?.sort || def.sort, sort: jc?.sort || fc?.sort || def.sort,
template: jc?.template || fc?.template || def.template, 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, empty_template: jc?.empty_template || fc?.empty_template || def.empty_template,
categories: jc?.categories || fc?.categories || def.categories, categories: jc?.categories || fc?.categories || def.categories,
ignore_labels: jc?.ignore_labels || fc?.ignore_labels || def.ignore_labels, ignore_labels: jc?.ignore_labels || fc?.ignore_labels || def.ignore_labels,