- add helper methods for tsts

- add new ability to recursively build changelog
- add feature to consume PRs if they were matched to a category
- keep header if children have entry
This commit is contained in:
Mike Penz
2024-03-01 20:11:14 +00:00
committed by GitHub
parent 4014bc63c1
commit f0ad0cf07a
7 changed files with 201 additions and 62 deletions
+27 -13
View File
@@ -307,27 +307,29 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o
function recursiveCategorizePr(category: Category, pr: PullRequestInfo, body: string): boolean[] {
let matched = false
let consumed = false
if (category.categories) {
const matchesParent = categorizePr(category, pr)
// only do children if parent also matches
if (category.categories && matchesParent) {
for (const childCategory of category.categories) {
const pullRequests = childCategory.entries || []
matched = categorizePr(childCategory, pr)
if (matched) {
pullRequests.push(body) // if matched add the PR to the list
}
if (childCategory.consume) {
consumed = true
continue
}
const [childMatched, childConsumed] = recursiveCategorizePr(childCategory, pr, body)
matched = matched || childMatched // at least one time it matched
consumed = childConsumed
}
}
if (!consumed) {
// if consumed we don't handle it anymore, as it was matched in a child, don't handle anymore
if (!consumed && !matched) {
const pullRequests = category.entries || []
matched = categorizePr(category, pr)
matched = matchesParent
if (matched) {
pullRequests.push(body) // if matched add the PR to the list
}
}
if (matched && category.consume) {
consumed = true
}
return [matched, consumed]
}
@@ -387,7 +389,7 @@ function categorizePr(category: Category, pr: PullRequestInfo): boolean {
}
function attachCategoryChangelog(changelog: string, category: Category, pullRequests: string[]): string {
if (pullRequests.length > 0) {
if (pullRequests.length > 0 || hasChildWithEntries(category)) {
if (category.title) {
changelog = `${changelog + category.title}\n\n`
}
@@ -682,3 +684,15 @@ function flatten(categories?: Category[]): Category[] {
return r.concat([i]).concat(flatten(i.categories))
}, [])
}
function hasChildWithEntries(category: Category): boolean {
const categories = category.categories
if (!categories || categories.length === 0) {
return (category.entries?.length || 0) > 0
}
let hasEntries = false
for (const cat of categories) {
hasEntries = hasEntries || hasChildWithEntries(cat)
}
return hasEntries
}