Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions changelog/submit/apply/scripts/post-failure-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.`,
Expand Down
Loading