Skip to content

Commit

Permalink
Merge pull request #998 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz committed Jan 6, 2023
2 parents d0814e5 + 6dc7444 commit da6847f
Show file tree
Hide file tree
Showing 19 changed files with 751 additions and 563 deletions.
25 changes: 19 additions & 6 deletions README.md
Expand Up @@ -195,7 +195,9 @@ The action supports flexible configuration options to modify vast areas of its b
> **Warning** It is required to have a `checkout` step prior to the changelog step if `configuration` is used, to allow the action to discover the configuration file. Use `configurationJson` as alternative.
This configuration is a `.json` file in the following format. (The below shocases *example* configurations for all possible options. In most scenarios most of the settings will not be needed, and the defaults will be appropiate.)
> **Note** It is possible to provide the configuration as file and as json via the yml file. The order of config values used: `configurationJson` > `configuration` > `DefaultConfiguration`.
This configuration is a `JSON` in the following format. (The below shocases *example* configurations for all possible options. In most scenarios most of the settings will not be needed, and the defaults will be appropiate.)

```json
{
Expand All @@ -217,7 +219,14 @@ This configuration is a `.json` file in the following format. (The below shocase
"labels": ["test", "magic"],
"exclude_labels": ["no-magic"],
"exhaustive": true,
"empty_content": "- no matching PRs"
"empty_content": "- no matching PRs",
"rules": [
{
"pattern": "open",
"on_property": "status",
"flags": "gu"
}
]
}
],
"ignore_labels": [
Expand Down Expand Up @@ -356,9 +365,9 @@ Table of supported placeholders allowed to be used in the `template` and `empty_
| `${{OWNER}}` | Describes the owner of the repository the changelog was generated for | x |
| `${{REPO}}` | The repository name of the repo the changelog was generated for | x |
| `${{FROM_TAG}}` | Defines the 'start' from where the changelog did consider merged pull requests | x |
| `${{FROM_TAG_DATE}}` | Defines the date at which the 'start' tag was created | x |
| `${{FROM_TAG_DATE}}` | Defines the date at which the 'start' tag was created. Requires `fetchReleaseInformation`. | x |
| `${{TO_TAG}}` | Defines until which tag the changelog did consider merged pull requests | x |
| `${{TO_TAG_DATE}}` | Defines the date at which the 'until' tag was created | x |
| `${{TO_TAG_DATE}}` | Defines the date at which the 'until' tag was created. Requires `fetchReleaseInformation`. | x |
| `${{RELEASE_DIFF}}` | Introduces a link to the full diff between from tag and to tag releases | x |
| `${{CHANGED_FILES}}` | The count of changed files. | |
| `${{ADDITIONS}}` | The count of code additions (lines). | |
Expand All @@ -379,10 +388,14 @@ Table of descriptions for the `configuration.json` options to configure the resu
|-----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| categories | An array of `category` specifications, offering a flexible way to group changes into categories. |
| category.title | The display name of a category in the changelog. |
| category.labels | An array of labels, to match pull request labels against. If any PR label matches any category label, the pull request will show up under this category. |
| category.labels | An array of labels, to match pull request labels against. If any PR label matches any category label, the pull request will show up under this category. (See `exhaustive` to change this) |
| category.exclude_labels | Similar to `labels`, an array of labels to match PRs against, but if a match occurs the PR is excluded from this category. |
| category.exhaustive | Will require all labels defined within this category to be present on the matching PR. |
| category.empty_content | If the category has no matching PRs, this content will be used. When not set, the category will be skipped in the changelog. |
| category.rules | An array of `rules` used to match PRs against. Any match will include the PR. (See `exhaustive` to change this) |
| category.rules.pattern | A `regex` pattern to match the property value towards. Uses `RegExp.test("val")` |
| category.rules.flags | Defines the regex flags specified for the pattern. Default: `gu`. |
| category.rules.on_property | The PR property to match against. [Possible values](https://github.com/mikepenz/release-changelog-builder-action/blob/feature/category_rules/src/configuration.ts#L33-L43). |
| 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 |
| sort | A `sort` specification, offering the ability to define sort order and property. |
| sort.order | The sort order. Allowed values: `ASC`, `DESC` |
Expand All @@ -395,7 +408,7 @@ Table of descriptions for the `configuration.json` options to configure the resu
| label_extractor.target | The result pattern. The result text will be used as label. If empty, no label is created. (Unused for `match` method) |
| label_extractor.on_property | The property to retrieve the text from. This is optional. Defaults to: `body`. Alternative values: `title`, `author`, `milestone`. |
| label_extractor.method | The extraction method used. Defaults to: `replace`. Alternative value: `match`. The method specified references the JavaScript String method. |
| label_extractor.flags | Defines the regex flags specified for the pattern. Default: `gu` |
| label_extractor.flags | Defines the regex flags specified for the pattern. Default: `gu`. |
| label_extractor.on_empty | Defines the placeholder to be filled in, if the regex does not lead to a result. |
| duplicate_filter | 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`). See `label_extractor` for details on `Extractor` properties. |
| transformers | An array of `transform` specifications, offering a flexible API to modify the text per pull request. This is applied on the change text created with `pr_template`. `transformers` are executed per change, in the order specified |
Expand Down
17 changes: 17 additions & 0 deletions __tests__/configuration.test.ts
@@ -0,0 +1,17 @@
import {mergeConfiguration, parseConfiguration, resolveConfiguration} from '../src/utils'

jest.setTimeout(180000)

it('Configurations are merged correctly', async () => {
const configurationJson = parseConfiguration(`{
"sort": "DESC",
"empty_template": "- no magic changes",
"trim_values": true
}`)
const configurationFile = resolveConfiguration('', 'configs/configuration.json')

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}`)
})
22 changes: 11 additions & 11 deletions __tests__/releaseNotes.test.ts
@@ -1,5 +1,5 @@
import {ReleaseNotes} from '../src/releaseNotes'
import {resolveConfiguration} from '../src/utils'
import {mergeConfiguration, resolveConfiguration} from '../src/utils'
import {Octokit} from '@octokit/rest'

jest.setTimeout(180000)
Expand All @@ -10,7 +10,7 @@ const octokit = new Octokit({
})

it('Should have empty changelog (tags)', async () => {
const configuration = resolveConfiguration('', 'configs/configuration.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand All @@ -31,7 +31,7 @@ it('Should have empty changelog (tags)', async () => {
})

it('Should match generated changelog (tags)', async () => {
const configuration = resolveConfiguration('', 'configs/configuration.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand All @@ -57,7 +57,7 @@ it('Should match generated changelog (tags)', async () => {
})

it('Should match generated changelog (refs)', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_all_placeholders.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_all_placeholders.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand Down Expand Up @@ -91,7 +91,7 @@ nhoelzl
})

it('Should match generated changelog and replace all occurrences (refs)', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_replace_all_placeholders.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_replace_all_placeholders.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand Down Expand Up @@ -127,7 +127,7 @@ nhoelzl
})

it('Should match ordered ASC', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_asc.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_asc.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand All @@ -148,7 +148,7 @@ it('Should match ordered ASC', async () => {
})

it('Should match ordered DESC', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_desc.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_desc.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand All @@ -169,7 +169,7 @@ it('Should match ordered DESC', async () => {
})

it('Should match ordered by title ASC', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_sort_title_asc.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_asc.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand All @@ -192,7 +192,7 @@ it('Should match ordered by title ASC', async () => {
})

it('Should match ordered by title DESC', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_sort_title_desc.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_desc.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand All @@ -215,7 +215,7 @@ it('Should match ordered by title DESC', async () => {
})

it('Should ignore PRs not merged into develop branch', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_base_branches_develop.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_develop.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand All @@ -236,7 +236,7 @@ it('Should ignore PRs not merged into develop branch', async () => {
})

it('Should ignore PRs not merged into main branch', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_base_branches_main.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_main.json'))
const releaseNotes = new ReleaseNotes(octokit, {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
Expand Down

0 comments on commit da6847f

Please sign in to comment.