diff --git a/changelog/submit/apply/scripts/post-failure-comment.js b/changelog/submit/apply/scripts/post-failure-comment.js index f77fb32..41ee66f 100644 --- a/changelog/submit/apply/scripts/post-failure-comment.js +++ b/changelog/submit/apply/scripts/post-failure-comment.js @@ -3,30 +3,32 @@ const { TITLE, upsertComment } = require('./comment-helper'); module.exports = async ({ github, context, core }) => { const prNumber = parseInt(process.env.PR_NUMBER, 10); const configFile = process.env.CONFIG_FILE || 'docs/changelog.yml'; - const labelRows = process.env.LABEL_TABLE || ''; - const productLabelRows = process.env.PRODUCT_LABEL_TABLE || ''; + const labelRows = (process.env.LABEL_TABLE || '').trim(); + const productLabelRows = (process.env.PRODUCT_LABEL_TABLE || '').trim(); const skipLabels = process.env.SKIP_LABELS || ''; - let labelSection; - if (labelRows.trim()) { - labelSection = [ - '', - '🔖 Add one of these **type** labels to your PR:', - '', - labelRows, - ].join('\n'); + const hasTypeIssue = !!labelRows; + const hasProductIssue = !!productLabelRows; + + let headline; + if (hasTypeIssue && hasProductIssue) { + headline = '⚠️ **Cannot generate changelog:** required type and product labels are missing on this PR.'; + } else if (hasProductIssue) { + headline = '⚠️ **Cannot generate changelog:** no matching product label found on this PR.'; } else { - labelSection = `\nAdd a type label that matches your \`pivot.types\` configuration in \`${configFile}\`.`; + headline = '⚠️ **Cannot generate changelog:** no matching type label found on this PR.'; + } + + const sections = []; + + if (hasTypeIssue) { + sections.push(['', '🔖 Add one of these **type** labels to your PR:', '', labelRows].join('\n')); + } else if (!hasProductIssue) { + sections.push(`\nAdd a type label that matches your \`pivot.types\` configuration in \`${configFile}\`.`); } - let productSection = ''; - if (productLabelRows.trim()) { - productSection = [ - '', - '📦 Add one or more **product** labels:', - '', - productLabelRows, - ].join('\n'); + if (hasProductIssue) { + sections.push(['', '📦 Add one or more **product** labels to your PR:', '', productLabelRows].join('\n')); } let skipSection; @@ -40,9 +42,8 @@ module.exports = async ({ github, context, core }) => { const body = [ TITLE, '', - '⚠️ **Cannot generate changelog:** no matching type label found on this PR.', - labelSection, - productSection, + headline, + ...sections, skipSection, '', `📄 See \`${configFile}\` for the full changelog configuration.`,