Skip to content
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

Merged
merged 1 commit into from
May 7, 2021

Conversation

ds300
Copy link
Contributor

@ds300 ds300 commented May 4, 2021

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:

  • In a danger rule to make sure folks are providing changelog information in their PR descriptions
  • In a changelog compiler that will automatically generate a CHANGELOG.md file for each platform, based on the PRs merged between releases.

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)

  • I have included screenshots or videos to illustrate my changes, or I have not changed anything that impacts the UI.
  • I have added tests for my changes, or my changes don't require testing, or I have included a link to a separate Jira ticket covering the tests.
  • I have documented any follow-up work that this PR will require, or it does not require any.
  • I have added an app state migration, or my changes do not require one. (What are migrations?)
  • I have added a CHANGELOG.yml entry or my changes do not require one.

@@ -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)"],
Copy link
Member

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" })
Copy link
Member

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", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice tests

Comment on lines +5 to +8
/**
* @param {string} description
* @returns {import('./changelog-types').ParseResult}
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐️

Comment on lines +66 to +98
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
}
Copy link
Member

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",
}
`)
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

Copy link
Contributor

@brainbicycle brainbicycle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tests!

@pvinis pvinis added the Squash On Green A label to indicate that Peril should squash-merge this PR when all statuses are green label May 7, 2021
@pvinis pvinis merged commit 9a1053c into master May 7, 2021
@pvinis pvinis deleted the ds300/pr-description-parser branch May 7, 2021 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Jira Synced Squash On Green A label to indicate that Peril should squash-merge this PR when all statuses are green
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants