- introduce new configuration option to define category labels to be exhaustive
- require all labels of a category to be present in the matching PR - update to typescript 4.4.x - recompile dist
This commit is contained in:
@@ -16,19 +16,20 @@ export interface Configuration {
|
||||
}
|
||||
|
||||
export interface Category {
|
||||
title: string
|
||||
labels: string[]
|
||||
title: string // the title of this category
|
||||
labels: string[] // labels to associate PRs to this category
|
||||
exhaustive?: boolean // requires all labels to be present in the PR
|
||||
}
|
||||
|
||||
export interface Transformer {
|
||||
pattern: string
|
||||
target?: string
|
||||
pattern: string // the regex pattern to match
|
||||
target?: string // the target string to transform the source string using the regex to
|
||||
flags?: string // the regex flag to use for RegExp
|
||||
}
|
||||
|
||||
export interface Extractor extends Transformer {
|
||||
on_property?: 'title' | 'author' | 'milestone' | 'body' | undefined // retrieve the property to extract the value from
|
||||
method?: 'replace' | 'match' | undefined // the method to use to extract the value
|
||||
method?: 'replace' | 'match' | undefined // the method to use to extract the value, `match` will not use the `target` property
|
||||
}
|
||||
|
||||
export interface TagResolver {
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ async function run(): Promise<void> {
|
||||
core.debug(`Enabled writing the changelog to disk`)
|
||||
writeOutput(repositoryPath, outputFile, result)
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ export class PullRequests {
|
||||
})
|
||||
|
||||
return mapPullRequest(data)
|
||||
} catch (e) {
|
||||
} catch (e: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
|
||||
core.warning(
|
||||
`⚠️ Cannot find PR ${owner}/${repo}#${prNumber} - ${e.message}`
|
||||
)
|
||||
|
||||
+24
-8
@@ -103,14 +103,26 @@ export function buildChangelog(
|
||||
|
||||
let matched = false
|
||||
for (const [category, pullRequests] of categorized) {
|
||||
if (
|
||||
haveCommonElements(
|
||||
category.labels.map(lbl => lbl.toLocaleLowerCase()),
|
||||
pr.labels
|
||||
)
|
||||
) {
|
||||
pullRequests.push(body)
|
||||
matched = true
|
||||
if (category.exhaustive === true) {
|
||||
if (
|
||||
haveEveryElements(
|
||||
category.labels.map(lbl => lbl.toLocaleLowerCase()),
|
||||
pr.labels
|
||||
)
|
||||
) {
|
||||
pullRequests.push(body)
|
||||
matched = true
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
haveCommonElements(
|
||||
category.labels.map(lbl => lbl.toLocaleLowerCase()),
|
||||
pr.labels
|
||||
)
|
||||
) {
|
||||
pullRequests.push(body)
|
||||
matched = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +225,10 @@ function haveCommonElements(arr1: string[], arr2: Set<string>): Boolean {
|
||||
return arr1.some(item => arr2.has(item))
|
||||
}
|
||||
|
||||
function haveEveryElements(arr1: string[], arr2: Set<string>): Boolean {
|
||||
return arr1.every(item => arr2.has(item))
|
||||
}
|
||||
|
||||
function fillTemplate(pr: PullRequestInfo, template: string): string {
|
||||
let transformed = template
|
||||
transformed = transformed.replace(/\${{NUMBER}}/g, pr.number.toString())
|
||||
|
||||
+2
-2
@@ -96,7 +96,7 @@ export function directoryExistsSync(
|
||||
let stats: fs.Stats
|
||||
try {
|
||||
stats = fs.statSync(inputPath)
|
||||
} catch (error) {
|
||||
} catch (error: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
|
||||
if (error.code === 'ENOENT') {
|
||||
if (!required) {
|
||||
return false
|
||||
@@ -132,7 +132,7 @@ export function writeOutput(
|
||||
core.debug(`outputPath = '${outputPath}'`)
|
||||
try {
|
||||
fs.writeFileSync(outputPath, changelog)
|
||||
} catch (error) {
|
||||
} catch (error: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) {
|
||||
core.warning(`⚠️ Could not write the file to disk - ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user