- introduce additional placeholders supported by the template
- introduce placeholder support into `empty_template` - introduce new placeholders for templates, update README with new placeholders
This commit is contained in:
@@ -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,26 +230,33 @@ 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
|
||||
+5
-1
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()) ||
|
||||
fillAdditionalPlaceholders(
|
||||
this.configuration.empty_template ||
|
||||
DefaultConfiguration.empty_template
|
||||
DefaultConfiguration.empty_template,
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+30
-1
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user