diff --git a/README.md b/README.md index cdedadf..0f2eec5 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,7 @@ For advanced use cases additional settings can be provided to the action ### PR Template placeholders -Table of supported placeholders allowed to be used in the `template` configuration. +Table of supported placeholders allowed to be used in the `pr_template` configuration. | **Placeholder** | **Description** | |------------------|-------------------------------------------------------------| @@ -230,33 +230,40 @@ Table of supported placeholders allowed to be used in the `template` configurati ### Template placeholders -Table of supported placeholders allowed to be used in the `pr_template` configuration. +Table of supported placeholders allowed to be used in the `template` and `empty_template` (only supports placeholder marked for empty) configuration. + +| **Placeholder** | **Description** | **Empty** | +|----------------------------|----------------------------------------------------------------------------------------------------|:---------:| +| `${{CHANGELOG}}` | The contents of the changelog, matching the labels as specified in the categories configuration | | +| `${{UNCATEGORIZED}}` | All pull requests not matching a specified label in categories | | +| `${{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 | +| `${{TO_TAG}}` | Defines until which tag the changelog did consider merged pull requests | x | +| `${{CATEGORIZED_COUNT}}` | The count of PRs which were categorized | | +| `${{UNCATEGORIZED_COUNT}}` | The count of PRs and changes which were not categorized. No label overlapping with category labels | | -| **Placeholder** | **Description** | -|----------------------|-------------------------------------------------------------------------------------------------| -| `${{CHANGELOG}}` | The contents of the changelog, matching the labels as specified in the categories configuration | -| `${{UNCATEGORIZED}}` | All pull requests not matching a specified label in categories | ### Configuration Specification Table of descriptions for the `configuration.json` options. -| **Input** | **Description** | -|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 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 | +| **Input** | **Description** | +|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 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 | -| sort | The sort order of pull requests. [ASC, DESC] | -| template | Specifies the global template to pick for creating the changelog. See [Template placeholders](#template-placeholders) for possible values | -| pr_template | Defines the per pull request template. See [PR Template placeholders](#pr-template-placeholders) for possible values | -| empty_template | Template to pick if no changes are detected. Does not support placeholders | +| sort | The sort order of pull requests. [ASC, DESC] | +| template | Specifies the global template to pick for creating the changelog. See [Template placeholders](#template-placeholders) for possible values | +| pr_template | Defines the per pull request template. See [PR Template placeholders](#pr-template-placeholders) for possible values | +| empty_template | Template to pick if no changes are detected. See [Template placeholders](#template-placeholders) for possible values | | 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 | -| transformer.pattern | A `regex` pattern, extracting values of the change message. | -| transformer.target | The result pattern, the regex groups will be filled into. Allows for full transformation of a pull request message. Including potentially specified texts | -| max_tags_to_fetch | The maximum amount of tags to load from the API to find the previous tag. Loaded paginated with 100 per page | -| max_pull_requests | The maximum amount of pull requests to load from the API. Loaded paginated with 30 per page | -| max_back_track_time_days | Defines the max amount of days to go back in time per changelog | -| exclude_merge_branches | An array of branches to be ignored from processing as merge commits | +| transformer.pattern | A `regex` pattern, extracting values of the change message. | +| transformer.target | The result pattern, the regex groups will be filled into. Allows for full transformation of a pull request message. Including potentially specified texts | +| max_tags_to_fetch | The maximum amount of tags to load from the API to find the previous tag. Loaded paginated with 100 per page | +| max_pull_requests | The maximum amount of pull requests to load from the API. Loaded paginated with 30 per page | +| max_back_track_time_days | Defines the max amount of days to go back in time per changelog | +| exclude_merge_branches | An array of branches to be ignored from processing as merge commits | ## Contribute 🧬 diff --git a/src/releaseNotes.ts b/src/releaseNotes.ts index 853e197..3f8e3d7 100755 --- a/src/releaseNotes.ts +++ b/src/releaseNotes.ts @@ -31,7 +31,11 @@ export class ReleaseNotes { } core.startGroup('📦 Build changelog') - const resultChangelog = buildChangelog(mergedPullRequests, configuration) + const resultChangelog = buildChangelog( + mergedPullRequests, + configuration, + this.options + ) core.endGroup() return resultChangelog } diff --git a/src/releaseNotesBuilder.ts b/src/releaseNotesBuilder.ts index f5568bf..2b9aafd 100644 --- a/src/releaseNotesBuilder.ts +++ b/src/releaseNotesBuilder.ts @@ -6,6 +6,7 @@ import {failOrError} from './utils' import {Octokit} from '@octokit/rest' import {Tags} from './tags' import {ReleaseNotes} from './releaseNotes' +import {fillAdditionalPlaceholders} from './transform' export class ReleaseNotesBuilder { constructor( @@ -96,19 +97,23 @@ export class ReleaseNotesBuilder { core.endGroup() } - const releaseNotes = new ReleaseNotes(octokit, { + const options = { owner: this.owner, repo: this.repo, fromTag: this.fromTag, toTag: this.toTag, failOnError: this.failOnError, configuration: this.configuration - }) + } + const releaseNotes = new ReleaseNotes(octokit, options) return ( (await releaseNotes.pull()) || - this.configuration.empty_template || - DefaultConfiguration.empty_template + fillAdditionalPlaceholders( + this.configuration.empty_template || + DefaultConfiguration.empty_template, + options + ) ) } } diff --git a/src/transform.ts b/src/transform.ts index 39eb276..ce4e13c 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -1,5 +1,6 @@ import {PullRequestInfo, sortPullRequests} from './pullRequests' import * as core from '@actions/core' +import {ReleaseNotesOptions} from './releaseNotes' import { Category, Configuration, @@ -9,7 +10,8 @@ import { export function buildChangelog( prs: PullRequestInfo[], - config: Configuration + config: Configuration, + options: ReleaseNotesOptions ): string { // sort to target order const sort = config.sort || DefaultConfiguration.sort @@ -96,10 +98,37 @@ export function buildChangelog( '${{UNCATEGORIZED}}', changelogUncategorized ) + + // fill other placeholders + transformedChangelog = transformedChangelog.replace( + '${{CATEGORIZED_COUNT}}', + categorized.size.toString() + ) + transformedChangelog = transformedChangelog.replace( + '${{UNCATEGORIZED_COUNT}}', + uncategorized.length.toString() + ) + transformedChangelog = fillAdditionalPlaceholders( + transformedChangelog, + options + ) + core.info(`ℹ️ Filled template`) return transformedChangelog } +export function fillAdditionalPlaceholders( + text: string, + options: ReleaseNotesOptions +): string { + let transformed = text + transformed = transformed.replace('${{OWNER}}', options.owner) + transformed = transformed.replace('${{REPO}}', options.repo) + transformed = transformed.replace('${{FROM_TAG}}', options.fromTag) + transformed = transformed.replace('${{TO_TAG}}', options.toTag) + return transformed +} + function haveCommonElements(arr1: string[], arr2: string[]): Boolean { return arr1.some(item => arr2.includes(item)) }