-
Notifications
You must be signed in to change notification settings - Fork 576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add PR description parser for changelog generation #4707
Conversation
@@ -8,7 +8,7 @@ module.exports = { | |||
"@images/(.*)": "<rootDir>/images/$1", | |||
"@relay/(.*)": "<rootDir>/src/lib/relay/$1", | |||
}, | |||
testMatch: ["<rootDir>/src/**/__tests__/*tests.(ts|tsx|js)"], | |||
testMatch: ["<rootDir>/src/**/__tests__/*tests.(ts|tsx|js)", "<rootDir>/scripts/**/*tests.(ts|tsx|js)"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
} | ||
|
||
fileContents = fileContents.replace(regex, this.generateChangelogSectionTemplate()) | ||
fileContents = prettier.format(fileContents, { parser: "markdown" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very thoughtful 🙌
const ERROR: PRDescriptionParseResult = { type: "error" } | ||
const NO_CHANGES: PRDescriptionParseResult = { type: "no_changes" } | ||
|
||
describe("parsePRDescription", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice tests
/** | ||
* @param {string} description | ||
* @returns {import('./changelog-types').ParseResult} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⭐️
function groupItems(lines) { | ||
/** | ||
* @type {string[]} | ||
*/ | ||
const result = [] | ||
|
||
/** | ||
* @type {string[]} | ||
*/ | ||
let group = [] | ||
|
||
for (const line of lines) { | ||
if (line.startsWith("-") || line.startsWith("*")) { | ||
if (group.length) { | ||
result.push(group.join("\n")) | ||
} | ||
group = [line.slice(1).trim()] | ||
} else if (line.match(/^\s*$/)) { | ||
// paragraph | ||
if (group.length) { | ||
result.push(group.join("\n")) | ||
} | ||
group = [] | ||
} else { | ||
group.push(line.trim()) | ||
} | ||
} | ||
if (group.length) { | ||
result.push(group.join("\n")) | ||
} | ||
|
||
return result | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is perfection 😌
"type": "changes", | ||
} | ||
`) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great tests!
This PR resolves CX-1211
Description
This creates a parser for PR descriptions, to extract the changelog information that folks will be able to add soon. See the RFC #4499 for more info.
This parser will be used in two places:
I implemented the parser in plain JS with JSDoc-based type annotations, checked by
tsc
.Because the parser depends on the exact wording of the PR template header descriptions, I added a function which can be used to update the PR template file. This could then be used on CI to check that the PR template file is in sync with the parser. I'll show this stuff off in Knowledge Share today.
PR Checklist (tick all before merging)