Skip to content

Commit 9a903f7

Browse files
authored
Merge pull request #1440 from mikepenz/develop
dev -> main
2 parents be351b0 + 9da101a commit 9a903f7

26 files changed

+17248
-15152
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,21 @@ Similar to `REVIEWS`, `REFERENCED` PRs also offer special placeholders.
525525
</p>
526526
</details>
527527

528+
### Commit Template placeholders
529+
530+
Table of supported placeholders allowed to be used in the `commit_template` configuration, which will be included in the release notes / changelog. Applies to `HYBRID` and `COMMIT` modes only.
531+
532+
| **Placeholder** | **Description** |
533+
|--------------------|----------------------------------------------------------------------------------------------------|
534+
| `#{{NUMBER}}` | Always 0. |
535+
| `#{{TITLE}}` | The commit summary. |
536+
| `#{{STATUS}}` | Always `merged`. |
537+
| `#{{CREATED_AT}}` | The ISO time of the commit. |
538+
| `#{{MERGE_SHA}}` | The commit SHA. |
539+
| `#{{AUTHOR}}` | The username of the commit Author. |
540+
| `#{{AUTHOR_NAME}}` | The name of the commit Author (Can be empty). |
541+
| `#{{BODY}}` | The commit message. |
542+
528543
### Configuration Specification
529544

530545
Table of descriptions for the `configuration.json` options to configure the resulting release notes / changelog.
@@ -543,12 +558,14 @@ Table of descriptions for the `configuration.json` options to configure the resu
543558
| category.rules.pattern | A `regex` pattern to match the property value towards. Uses `RegExp.test("val")` |
544559
| category.rules.flags | Defines the regex flags specified for the pattern. Default: `gu`. |
545560
| category.rules.on_property | The PR property to match against. [Possible values](https://github.com/mikepenz/release-changelog-builder-action/blob/develop/src/configuration.ts#L33-L43). |
561+
| category.mode | Defines if this category applies to PRs, commits or both. Allowed values: `PR`, `COMMIT`, `HYBRID`. Default: `HYBRID`. |
546562
| ignore_labels | An array of labels, to match pull request labels against. If any PR label overlaps, the pull request will be ignored from the changelog. This takes precedence over category labels |
547563
| sort | A `sort` specification, offering the ability to define sort order and property. |
548564
| sort.order | The sort order. Allowed values: `ASC`, `DESC` |
549565
| sort.on_property | The property to sort on. Allowed values: `mergedAt`, `title` |
550566
| template | Specifies the global template to pick for creating the changelog. See [Template placeholders](#template-placeholders) for possible values |
551567
| pr_template | Defines the per pull request template. See [PR Template placeholders](#pr-template-placeholders) for possible values |
568+
| commit_template | Defines the per commit template. Used in `HYBRID` and `COMMIT` modes only. If empty, uses the template defined for `pr_template`. See [Commit Template placeholders](#commit-template-placeholders) for possible values. |
552569
| empty_template | Template to pick if no changes are detected. See [Template placeholders](#template-placeholders) for possible values |
553570
| label_extractor.\[{\<EXTRACTOR\>}\] | An array of `Extractor` specifications, offering a flexible API to extract additional labels from a PR. Please see the documentation related to [Regex Configuration](#regex-configuration) for more details. |
554571
| duplicate_filter.{\<EXTRACTOR\>} | Defines the `Extractor` to use for retrieving the identifier for a PR. In case of duplicates will keep the last matching pull request (depends on `sort`). Please see the documentation related to [Regex Configuration](#regex-configuration) for more details. |

__tests__/configuration.test.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
21
import {mergeConfiguration, parseConfiguration, resolveConfiguration} from '../src/utils.js'
3-
import { clear } from "../src/transform.js";
2+
import {clear} from '../src/transform.js'
3+
import {jest} from '@jest/globals'
44

55
jest.setTimeout(180000)
66
clear()
@@ -15,8 +15,50 @@ it('Configurations are merged correctly', async () => {
1515

1616
const mergedConfiguration = mergeConfiguration(configurationJson, configurationFile)
1717

18-
console.log(mergedConfiguration)
19-
expect(JSON.stringify(mergedConfiguration)).toEqual(
20-
`{\"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}`
18+
const expectedStringified = JSON.stringify(mergedConfiguration, null, 2)
19+
20+
expect(expectedStringified).toEqual(
21+
`{
22+
"max_tags_to_fetch": 200,
23+
"max_pull_requests": 1000,
24+
"max_back_track_time_days": 1000,
25+
"exclude_merge_branches": [],
26+
"sort": "DESC",
27+
"template": "#{{CHANGELOG}}",
28+
"pr_template": "- #{{TITLE}}\\n - PR: ##{{NUMBER}}",
29+
"commit_template": "- #{{TITLE}}",
30+
"empty_template": "- no magic changes",
31+
"categories": [
32+
{
33+
"title": "## 🚀 Features",
34+
"labels": [
35+
"feature"
36+
]
37+
},
38+
{
39+
"title": "## 🐛 Fixes",
40+
"labels": [
41+
"fix"
42+
]
43+
},
44+
{
45+
"title": "## 🧪 Tests",
46+
"labels": [
47+
"test"
48+
]
49+
}
50+
],
51+
"ignore_labels": [
52+
"ignore"
53+
],
54+
"label_extractor": [],
55+
"transformers": [],
56+
"tag_resolver": {
57+
"method": "semver"
58+
},
59+
"base_branches": [],
60+
"custom_placeholders": [],
61+
"trim_values": true
62+
}`
2163
)
2264
})

__tests__/demo/demo.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {mergeConfiguration, resolveConfiguration} from '../../src/utils.js'
22
import {ReleaseNotesBuilder} from '../../src/releaseNotesBuilder.js'
33
import {GithubRepository} from '../../src/repositories/GithubRepository.js'
4+
import {jest} from '@jest/globals'
45

56
jest.setTimeout(180000)
67

__tests__/gitea/releaseNotesBuilderGitea.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {mergeConfiguration, resolveConfiguration} from '../../src/utils.js'
22
import {ReleaseNotesBuilder} from '../../src/releaseNotesBuilder.js'
33
import {GiteaRepository} from '../../src/repositories/GiteaRepository.js'
44
import {clear} from '../../src/transform.js'
5+
import {jest} from '@jest/globals'
56

67
jest.setTimeout(180000)
78
clear()

__tests__/gitea/releaseNotesBuilderPullGitea.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Options, pullData} from '../../src/pr-collector/prCollector.js'
44
import {GiteaRepository} from '../../src/repositories/GiteaRepository.js'
55
import {clear} from '../../src/transform.js'
66
import {ReleaseNotesOptions} from '../../src/releaseNotesBuilder.js'
7+
import {jest} from '@jest/globals'
78

89
jest.setTimeout(180000)
910
clear()

__tests__/main.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import * as process from 'process'
33
import * as cp from 'child_process'
44
import * as fs from 'fs'
55
import {clear} from '../src/transform.js'
6+
import {jest} from '@jest/globals'
7+
import { fileURLToPath } from 'url';
68

79
jest.setTimeout(180000)
810
clear()
911

12+
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
13+
const __dirname = path.dirname(__filename); // get the name of the directory
14+
1015
test('missing values should result in failure', () => {
1116
expect.assertions(1)
1217

__tests__/regexUtils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {transformStringToValue, validateRegex} from '../src/pr-collector/regexUtils.js'
22
import {Regex} from '../src/pr-collector/types.js'
33
import {clear} from '../src/transform.js'
4+
import {jest} from '@jest/globals'
45

56
jest.setTimeout(180000)
67
clear()

__tests__/releaseNotesBuilder.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {mergeConfiguration, resolveConfiguration} from '../src/utils.js'
22
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder.js'
33
import {GithubRepository} from '../src/repositories/GithubRepository.js'
44
import {clear} from '../src/transform.js'
5+
import {jest} from '@jest/globals'
56

67
jest.setTimeout(180000)
78
clear()

__tests__/releaseNotesBuilderPull.test.ts

Lines changed: 184 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Options, pullData} from '../src/pr-collector/prCollector.js'
44
import {GithubRepository} from '../src/repositories/GithubRepository.js'
55
import {clear} from '../src/transform.js'
66
import {ReleaseNotesOptions} from '../src/releaseNotesBuilder.js'
7+
import {jest} from '@jest/globals'
78

89
jest.setTimeout(180000)
910
clear()
@@ -366,7 +367,7 @@ it('Default configuration with commit mode', async () => {
366367

367368
it('Default configuration with commit mode and custom placeholder', async () => {
368369
const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'COMMIT'))
369-
configuration.pr_template = '- #{{TITLE_ONLY}}'
370+
configuration.commit_template = '- #{{TITLE_ONLY}}'
370371
configuration.trim_values = true
371372
configuration.custom_placeholders = [
372373
{
@@ -407,3 +408,185 @@ it('Default configuration with commit mode and custom placeholder', async () =>
407408
`## 🚀 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`
408409
)
409410
})
411+
412+
it('Default configuration with hybrid mode and classic categories', async () => {
413+
const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'HYBRID'))
414+
const options = {
415+
owner: 'conventional-commits',
416+
repo: 'conventionalcommits.org',
417+
fromTag: {name: '56cdc85d01fd11aa164bd958bbf6114a51abfcf6'},
418+
toTag: {name: '325b74fbc44bf34d9fa645951d076a450b4e26be'},
419+
includeOpen: false,
420+
failOnError: false,
421+
fetchViaCommits: false,
422+
fetchReviewers: false,
423+
fetchReleaseInformation: false,
424+
fetchReviews: false,
425+
mode: 'HYBRID',
426+
configuration,
427+
repositoryUtils: githubRepository
428+
} as ReleaseNotesOptions & Options
429+
let data: any
430+
if (enablePullData) {
431+
data = await pullData(githubRepository, options as Options)
432+
} else {
433+
data = checkExportedData(false, 'caches/github_conventional-hybrid-1e1c8e-325b74.json')
434+
}
435+
const releaseNotesOptions = {...options, ...(data?.options ? data.options : {})} as unknown as ReleaseNotesOptions
436+
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, releaseNotesOptions)
437+
console.log(changeLog)
438+
439+
const expected = `## 🚀 Features
440+
441+
- feat(lang): add Bengali
442+
- feat(lang): add uzbek translation (#558)
443+
444+
## 🐛 Fixes
445+
446+
- fix: Fix grammar and consistency in french translation (#546)
447+
- fix(ja): fix typo
448+
- fix(zh-hant): Distinguish translations of 'Release/Publish'
449+
- fix(ko): fix translation typo for message (#567)
450+
451+
## 📦 Other
452+
453+
- fix: Fix grammar and consistency in french translation
454+
- Add/update tool/project links
455+
- fix(ja): fix typo
456+
- docs: add link to git-changelog-command-line docker image
457+
- docs: Add descriptions for commit types
458+
- fix(zh-hant): Distinguish translations of 'Release/Publish'
459+
- "feat(lang): add Bengali translation"
460+
- feat(lang): add uzbek translation
461+
- fix(ko): fix translation typo for message
462+
- doc: new thi.ng links and descriptions
463+
- docs: add link to git-changelog-command-line docker image
464+
- docs: Add descriptions for commit types
465+
466+
`
467+
468+
expect(changeLog).toStrictEqual(expected)
469+
})
470+
471+
it('Default configuration with hybrid mode and with separate feature categories', async () => {
472+
const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'HYBRID'))
473+
const options = {
474+
owner: 'conventional-commits',
475+
repo: 'conventionalcommits.org',
476+
fromTag: {name: '56cdc85d01fd11aa164bd958bbf6114a51abfcf6'},
477+
toTag: {name: '325b74fbc44bf34d9fa645951d076a450b4e26be'},
478+
includeOpen: false,
479+
failOnError: false,
480+
fetchViaCommits: false,
481+
fetchReviewers: false,
482+
fetchReleaseInformation: false,
483+
fetchReviews: false,
484+
mode: 'HYBRID',
485+
configuration,
486+
repositoryUtils: githubRepository
487+
} as ReleaseNotesOptions & Options
488+
let data: any
489+
if (enablePullData) {
490+
data = await pullData(githubRepository, options as Options)
491+
} else {
492+
data = checkExportedData(false, 'caches/github_conventional-hybrid-separate-cats-1e1c8e-325b74.json')
493+
}
494+
const releaseNotesOptions = {...options, ...(data?.options ? data.options : {})} as unknown as ReleaseNotesOptions
495+
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, releaseNotesOptions)
496+
console.log(changeLog)
497+
498+
const expected = `## 🚀 Big features
499+
500+
- feat(lang): add uzbek translation
501+
502+
## 🚀 Small features
503+
504+
- feat(lang): add Bengali
505+
- feat(lang): add uzbek translation (#558)
506+
507+
## 🐛 Fixes
508+
509+
- fix: Fix grammar and consistency in french translation
510+
- fix(ja): fix typo
511+
- fix(zh-hant): Distinguish translations of 'Release/Publish'
512+
- fix(ko): fix translation typo for message
513+
- fix: Fix grammar and consistency in french translation (#546)
514+
- fix(ja): fix typo
515+
- fix(zh-hant): Distinguish translations of 'Release/Publish'
516+
- fix(ko): fix translation typo for message (#567)
517+
518+
## 📦 Other
519+
520+
- Add/update tool/project links
521+
- docs: add link to git-changelog-command-line docker image
522+
- docs: Add descriptions for commit types
523+
- "feat(lang): add Bengali translation"
524+
- doc: new thi.ng links and descriptions
525+
- docs: add link to git-changelog-command-line docker image
526+
- docs: Add descriptions for commit types
527+
528+
`
529+
530+
expect(changeLog).toStrictEqual(expected)
531+
})
532+
it('Default configuration with hybrid mode and with separate feature categories and dup checker', async () => {
533+
const configuration = Object.assign({}, mergeConfiguration(undefined, undefined, 'HYBRID'))
534+
const options = {
535+
owner: 'conventional-commits',
536+
repo: 'conventionalcommits.org',
537+
fromTag: {name: '56cdc85d01fd11aa164bd958bbf6114a51abfcf6'},
538+
toTag: {name: '325b74fbc44bf34d9fa645951d076a450b4e26be'},
539+
includeOpen: false,
540+
failOnError: false,
541+
fetchViaCommits: false,
542+
fetchReviewers: false,
543+
fetchReleaseInformation: false,
544+
fetchReviews: false,
545+
mode: 'HYBRID',
546+
configuration,
547+
repositoryUtils: githubRepository
548+
} as ReleaseNotesOptions & Options
549+
let data: any
550+
if (enablePullData) {
551+
data = await pullData(githubRepository, options as Options)
552+
} else {
553+
data = checkExportedData(false, 'caches/github_conventional-hybrid-separate-cats-1e1c8e-325b74.json')
554+
}
555+
const releaseNotesOptions = {...options, ...(data?.options ? data.options : {})} as unknown as ReleaseNotesOptions
556+
557+
releaseNotesOptions.configuration.duplicate_filter = {
558+
pattern: '(.+) \\(#\\d+\\)',
559+
target: '$1',
560+
on_property: 'title'
561+
}
562+
563+
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, releaseNotesOptions)
564+
console.log(changeLog)
565+
566+
// Test author's note: Here I was hoping the "add uzbek translation" pr would be categorized
567+
// as a Big feature, but due to how duplicates are handled (i.e. previous ones get replaced by following duplicates)
568+
// 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.
569+
const expected = `## 🚀 Small features
570+
571+
- feat(lang): add Bengali
572+
- feat(lang): add uzbek translation (#558)
573+
574+
## 🐛 Fixes
575+
576+
- fix: Fix grammar and consistency in french translation
577+
- fix(ja): fix typo
578+
- fix(zh-hant): Distinguish translations of 'Release/Publish'
579+
- fix(ko): fix translation typo for message (#567)
580+
581+
## 📦 Other
582+
583+
- Add/update tool/project links
584+
- "feat(lang): add Bengali translation"
585+
- doc: new thi.ng links and descriptions
586+
- docs: add link to git-changelog-command-line docker image
587+
- docs: Add descriptions for commit types
588+
589+
`
590+
591+
expect(changeLog).toStrictEqual(expected)
592+
})

__tests__/tags.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {TagResolver} from '../src/configuration.js'
22
import {validateRegex} from '../src/pr-collector/regexUtils.js'
33
import {filterTags, prepareAndSortTags, TagInfo, transformTags} from '../src/pr-collector/tags.js'
44
import {clear} from '../src/transform.js'
5+
import {jest} from '@jest/globals'
56

67
jest.setTimeout(180000)
78
clear()

0 commit comments

Comments
 (0)