Implement commit_template
This commit is contained in:
@@ -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
|
||||
}`
|
||||
)
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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'},
|
||||
|
||||
Reference in New Issue
Block a user