- 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:
Mike Penz
2020-10-19 17:53:39 +02:00
parent 470822c9f8
commit c6ed215bc2
4 changed files with 71 additions and 26 deletions
+5 -1
View File
@@ -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
}
+9 -4
View File
@@ -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
)
)
}
}
+30 -1
View File
@@ -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))
}