Skip to content

Commit a32cb69

Browse files
feat: Add package info to PR comments
I've modified the GitHub App to include package information from `package.json` in the comments it posts on new pull requests. The package name and version are now displayed at the top of the comment, formatted in a style similar to the output of the `apt` package manager. I've also wrapped the existing pull request guidelines in a collapsible `<details>` tag to improve the presentation.
1 parent 71928c1 commit a32cb69

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

app.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ const privateKeyPath = process.env.PRIVATE_KEY_PATH
1313
const privateKey = fs.readFileSync(privateKeyPath, 'utf8')
1414
const secret = process.env.WEBHOOK_SECRET
1515
const enterpriseHostname = process.env.ENTERPRISE_HOSTNAME
16-
const messageForNewPRs = fs.readFileSync('./message.md', 'utf8')
16+
const messageTemplate = fs.readFileSync('./message.md', 'utf8')
17+
const { name, version } = JSON.parse(fs.readFileSync('./package.json', 'utf8'))
18+
19+
const GREETING_MESSAGE = `\`\`\`
20+
Package: ${name}
21+
Version: ${version}
22+
\`\`\`
23+
24+
${messageTemplate}`
1725

1826
// Create an authenticated Octokit client authenticated as a GitHub App
1927
const app = new App({
@@ -43,7 +51,7 @@ app.webhooks.on('pull_request.opened', async ({ octokit, payload }) => {
4351
owner: payload.repository.owner.login,
4452
repo: payload.repository.name,
4553
issue_number: payload.pull_request.number,
46-
body: messageForNewPRs
54+
body: GREETING_MESSAGE
4755
})
4856
} catch (error) {
4957
if (error.response) {

message.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
<details>
2+
<summary>PR guidelines</summary>
3+
14
👋 Hi there!
25

36
Thanks for opening a new PR. Please, consider following this [guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) to make your PR easier to review.
47

58
Also, check this new feature to [use markdown helpers](https://github.blog/changelog/2023-03-15-introducing-the-github-markdown-helpers-public-beta/) in your PR.
9+
10+
</details>

0 commit comments

Comments
 (0)