- 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:
+27
-13
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user