From e6b717afe7e27d1ca241c1e4788bde99c7cf500b Mon Sep 17 00:00:00 2001 From: paulczajka Date: Fri, 7 Oct 2022 14:54:27 -0700 Subject: [PATCH 1/2] Support handling for more variability in markdown title lines --- lib/issues.js | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/issues.js b/lib/issues.js index 07ec9de6..8413a7cf 100644 --- a/lib/issues.js +++ b/lib/issues.js @@ -50,6 +50,18 @@ exports.severityNames = { 'spec': 'Spec Breaking', } +// Final report title lines should have a single format: +// ## [H-1] Not good thing +// +// Markdown title lines have more variability: +// ### [H-1] Not good thing +// ## (H-1) Also not good +// **[G-1]** Gassy code +// +// This RegExps will select any of these formats +const ISSUE_TAG_RE = `[\\(\\[<](([CHMLQIG])-[0-9]+)[\\)\\]>]` +const TITLE_LINE_RE = `^(#{1,3} +)?\\*{0,2}${ISSUE_TAG_RE}\\*{0,2} +(.+)` + exports.statusNames = STATUSES exports.normalize = function normalizeIssue(issue) { @@ -70,7 +82,7 @@ exports.normalize = function normalizeIssue(issue) { } function parseTitleLine(titleLine) { - const [, tag, severity, title] = titleLine.match(/^## +\((([CHMLQIG])-[0-9]+)\) +(.+)/) + const [,, tag, severity, title] = titleLine.match(new RegExp(TITLE_LINE_RE)) return { tag, severity, title } } @@ -108,39 +120,46 @@ const IMPACT_LABEL_RE = /(?:\*\*)?Impact(?:\*\*)?:(?:\*\*)? ([^\n]+)?/ const CHANCE_LABEL_RE = /(?:\*\*)?Likelihood(?:\*\*)?:(?:\*\*)? ([^\n]+)?/ exports.parseNotionMarkdownIssues = function parseNotionMarkdownIssues(markdown) { - return markdown.split(/(?=##\s+\([CHMLQGI]-\d\))/) + return markdown.split(new RegExp(`(?=${TITLE_LINE_RE})`)) .filter(x => !x.match(/^[\s\n]*$/)) .map(issueContent => { - issueContent = issueContent.trim() let impact = '' let chance = '' - const { severity } = parseTitleLine(issueContent.split('\n')[0]) + const [firstLine, ...contentLines] = issueContent.trim().split('\n') + const { tag, severity, title } = parseTitleLine(firstLine) + + // Normalize markdown title format for the final report: + // ## [H-1] Not good thing + const issueTitle = `## [${tag}] ${title}` + let issueBody = contentLines.join('\n') // SORRY WINDOWS - const impactMatch = issueContent.match(IMPACT_LABEL_RE) + const impactMatch = issueBody.match(IMPACT_LABEL_RE) if (impactMatch) { impact = impactMatch[1].match(/spec/i) ? 'spec' : impactMatch[1].toLowerCase() if (!IMPACT_SEVERITIES.includes(impact)) { throw new Error(`Invalid impact: ${impact}`) } + issueBody = issueBody.replace(IMPACT_LABEL_RE, '') } - const chanceMatch = issueContent.match(CHANCE_LABEL_RE) + const chanceMatch = issueBody.match(CHANCE_LABEL_RE) if (chanceMatch) { chance = chanceMatch[1].toLowerCase() if (!CHANCE_SEVERITIES.includes(chance)) { throw new Error(`Invalid chance: ${chance}`) } + issueBody = issueBody.replace(CHANCE_LABEL_RE, '') } + + //Remove all empty leading lines + issueBody = issueBody.replace(/^( *\n)+(.*)$/gm, '$2') + return { impact, chance, severity, - content: issueContent - .replace(IMPACT_LABEL_RE, '') - .replace(CHANCE_LABEL_RE, '') - .replace(/(## [^\n]+)\n+/g, '$1\n\n') // Consolidate extra newlines - , + content: issueTitle + '\n\n' + issueBody, } }) } From 8a98121e1e90777d2f031c1c5003d146e9f453ec Mon Sep 17 00:00:00 2001 From: paulczajka Date: Fri, 7 Oct 2022 15:12:46 -0700 Subject: [PATCH 2/2] Update to match current final report format --- lib/issues.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/issues.js b/lib/issues.js index 8413a7cf..03ae4016 100644 --- a/lib/issues.js +++ b/lib/issues.js @@ -51,7 +51,7 @@ exports.severityNames = { } // Final report title lines should have a single format: -// ## [H-1] Not good thing +// ## (H-1) Not good thing // // Markdown title lines have more variability: // ### [H-1] Not good thing @@ -131,7 +131,7 @@ exports.parseNotionMarkdownIssues = function parseNotionMarkdownIssues(markdown) // Normalize markdown title format for the final report: // ## [H-1] Not good thing - const issueTitle = `## [${tag}] ${title}` + const issueTitle = `## (${tag}) ${title}` let issueBody = contentLines.join('\n') // SORRY WINDOWS