- 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
|
### 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** |
|
| **Placeholder** | **Description** |
|
||||||
|------------------|-------------------------------------------------------------|
|
|------------------|-------------------------------------------------------------|
|
||||||
@@ -230,26 +230,33 @@ Table of supported placeholders allowed to be used in the `template` configurati
|
|||||||
|
|
||||||
### Template placeholders
|
### 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
|
### Configuration Specification
|
||||||
|
|
||||||
Table of descriptions for the `configuration.json` options.
|
Table of descriptions for the `configuration.json` options.
|
||||||
|
|
||||||
| **Input** | **Description** |
|
| **Input** | **Description** |
|
||||||
|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| categories | An array of `category` specifications, offering a flexible way to group changes into categories |
|
| 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.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 |
|
||||||
| sort | The sort order of pull requests. [ASC, DESC] |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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.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 |
|
| 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')
|
core.startGroup('📦 Build changelog')
|
||||||
const resultChangelog = buildChangelog(mergedPullRequests, configuration)
|
const resultChangelog = buildChangelog(
|
||||||
|
mergedPullRequests,
|
||||||
|
configuration,
|
||||||
|
this.options
|
||||||
|
)
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
return resultChangelog
|
return resultChangelog
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {failOrError} from './utils'
|
|||||||
import {Octokit} from '@octokit/rest'
|
import {Octokit} from '@octokit/rest'
|
||||||
import {Tags} from './tags'
|
import {Tags} from './tags'
|
||||||
import {ReleaseNotes} from './releaseNotes'
|
import {ReleaseNotes} from './releaseNotes'
|
||||||
|
import {fillAdditionalPlaceholders} from './transform'
|
||||||
|
|
||||||
export class ReleaseNotesBuilder {
|
export class ReleaseNotesBuilder {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -96,19 +97,23 @@ export class ReleaseNotesBuilder {
|
|||||||
core.endGroup()
|
core.endGroup()
|
||||||
}
|
}
|
||||||
|
|
||||||
const releaseNotes = new ReleaseNotes(octokit, {
|
const options = {
|
||||||
owner: this.owner,
|
owner: this.owner,
|
||||||
repo: this.repo,
|
repo: this.repo,
|
||||||
fromTag: this.fromTag,
|
fromTag: this.fromTag,
|
||||||
toTag: this.toTag,
|
toTag: this.toTag,
|
||||||
failOnError: this.failOnError,
|
failOnError: this.failOnError,
|
||||||
configuration: this.configuration
|
configuration: this.configuration
|
||||||
})
|
}
|
||||||
|
const releaseNotes = new ReleaseNotes(octokit, options)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(await releaseNotes.pull()) ||
|
(await releaseNotes.pull()) ||
|
||||||
|
fillAdditionalPlaceholders(
|
||||||
this.configuration.empty_template ||
|
this.configuration.empty_template ||
|
||||||
DefaultConfiguration.empty_template
|
DefaultConfiguration.empty_template,
|
||||||
|
options
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-1
@@ -1,5 +1,6 @@
|
|||||||
import {PullRequestInfo, sortPullRequests} from './pullRequests'
|
import {PullRequestInfo, sortPullRequests} from './pullRequests'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
import {ReleaseNotesOptions} from './releaseNotes'
|
||||||
import {
|
import {
|
||||||
Category,
|
Category,
|
||||||
Configuration,
|
Configuration,
|
||||||
@@ -9,7 +10,8 @@ import {
|
|||||||
|
|
||||||
export function buildChangelog(
|
export function buildChangelog(
|
||||||
prs: PullRequestInfo[],
|
prs: PullRequestInfo[],
|
||||||
config: Configuration
|
config: Configuration,
|
||||||
|
options: ReleaseNotesOptions
|
||||||
): string {
|
): string {
|
||||||
// sort to target order
|
// sort to target order
|
||||||
const sort = config.sort || DefaultConfiguration.sort
|
const sort = config.sort || DefaultConfiguration.sort
|
||||||
@@ -96,10 +98,37 @@ export function buildChangelog(
|
|||||||
'${{UNCATEGORIZED}}',
|
'${{UNCATEGORIZED}}',
|
||||||
changelogUncategorized
|
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`)
|
core.info(`ℹ️ Filled template`)
|
||||||
return transformedChangelog
|
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 {
|
function haveCommonElements(arr1: string[], arr2: string[]): Boolean {
|
||||||
return arr1.some(item => arr2.includes(item))
|
return arr1.some(item => arr2.includes(item))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user