Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multi source configuration #996

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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 Down
17 changes: 17 additions & 0 deletions __tests__/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
30 changes: 15 additions & 15 deletions __tests__/releaseNotesBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {resolveConfiguration} from '../src/utils'
import {mergeConfiguration, resolveConfiguration} from '../src/utils'
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder'

jest.setTimeout(180000)

it('Should match generated changelog (unspecified fromTag)', async () => {
const configuration = resolveConfiguration('', 'configs/configuration.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand Down Expand Up @@ -34,7 +34,7 @@ it('Should match generated changelog (unspecified fromTag)', async () => {
})

it('Should match generated changelog (unspecified tags)', async () => {
const configuration = resolveConfiguration('', 'configs/configuration.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand All @@ -59,7 +59,7 @@ it('Should match generated changelog (unspecified tags)', async () => {
})

it('Should use empty placeholder', async () => {
const configuration = resolveConfiguration('', 'configs/configuration.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand All @@ -84,7 +84,7 @@ it('Should use empty placeholder', async () => {
})

it('Should fill empty placeholders', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand All @@ -111,7 +111,7 @@ it('Should fill empty placeholders', async () => {
})

it('Should fill `template` placeholders', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand All @@ -138,7 +138,7 @@ it('Should fill `template` placeholders', async () => {
})

it('Should fill `template` placeholders, ignore', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_empty_all_placeholders.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand All @@ -165,7 +165,7 @@ it('Should fill `template` placeholders, ignore', async () => {
})

it('Uncategorized category', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_uncategorized_category.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_uncategorized_category.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand All @@ -192,7 +192,7 @@ it('Uncategorized category', async () => {
})

it('Verify commit based changelog', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_commits.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_commits.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand All @@ -219,7 +219,7 @@ it('Verify commit based changelog', async () => {
})

it('Verify commit based changelog, with emoji categorisation', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_commits_emoji.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_commits_emoji.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null,
null,
Expand All @@ -246,7 +246,7 @@ it('Verify commit based changelog, with emoji categorisation', async () => {
})

it('Verify default inclusion of open PRs', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_including_open.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_including_open.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
null, // token
Expand All @@ -273,7 +273,7 @@ it('Verify default inclusion of open PRs', async () => {
})

it('Verify custom categorisation of open PRs', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_excluding_open.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_excluding_open.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
null, // token
Expand All @@ -300,7 +300,7 @@ it('Verify custom categorisation of open PRs', async () => {
})

it('Verify reviewers who approved are fetched and also release information', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_approvers.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json'))
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
null, // token
Expand All @@ -327,7 +327,7 @@ it('Verify reviewers who approved are fetched and also release information', asy
})

it('Fetch release information', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_approvers.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json'))
configuration.template = '${{FROM_TAG}}-${{FROM_TAG_DATE}}\n${{TO_TAG}}-${{TO_TAG_DATE}}\n${{DAYS_SINCE}}'
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
Expand All @@ -353,7 +353,7 @@ it('Fetch release information', async () => {
})

it('Fetch release information for non existing tag / release', async () => {
const configuration = resolveConfiguration('', 'configs_test/configuration_approvers.json')
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_approvers.json'))
configuration.template = '${{FROM_TAG}}-${{FROM_TAG_DATE}}\n${{TO_TAG}}-${{TO_TAG_DATE}}\n${{DAYS_SINCE}}'
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // baseUrl
Expand Down
Loading