-
Notifications
You must be signed in to change notification settings - Fork 5.6k
chore: add bot to comment on PRs #28953
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
base: main
Are you sure you want to change the base?
Changes from all commits
3609bf8
832019c
f032d24
4dfffc4
ea2b670
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Add labels to pull requests | ||
|
||
on: | ||
pull_request_target: | ||
types: [ | ||
opened, | ||
reopened, | ||
review_requested, | ||
] | ||
pull_request_review: | ||
types: [submitted, edited, dismissed] | ||
|
||
jobs: | ||
pull_request_labels: | ||
runs-on: ubuntu-22.04 | ||
if: github.repository == 'denoland/deno' | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Label pull request | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
require('./tools/label_pull_request.js')({ context, github }) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2018-2025 the Deno authors. MIT license. | ||
|
||
// deno-lint-ignore-file no-console camelcase | ||
|
||
async function createComment(context, github) { | ||
await github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `Thanks for the PR! | ||
|
||
Once you are done, please request a review from a Deno team member.`, | ||
}); | ||
} | ||
|
||
async function updateLabels(context, github) { | ||
const result = await github.rest.issues | ||
.listLabelsOnIssue({ | ||
issue_number: context.payload.pull_request.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}); | ||
const labelNames = result.data.map((label) => label.name); | ||
labelNames.push("pr:needs-review"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create this label before landing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to actually add a label, once a review is requested |
||
|
||
return github.rest.issues.setLabels({ | ||
issue_number: context.payload.pull_request.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: labelNames, | ||
}); | ||
} | ||
|
||
// TODO(bartlomieju): figure out how to use ES modules in GH Actions scripts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to work well like below. tools/package.json
{
"type": "module"
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it may work well with just |
||
module.exports = async ({ context, github }) => { | ||
const eventHandlers = { | ||
opened: createComment, | ||
reopened: createComment, | ||
review_requested: updateLabels, | ||
}; | ||
|
||
const eventName = context.payload.action; | ||
const eventHandler = eventHandlers[eventName]; | ||
|
||
if (!eventHandler) { | ||
console.log(`::warning::'${eventName}' event has no handler, skipping.`); | ||
return; | ||
} | ||
|
||
try { | ||
await eventHandler(context, github); | ||
} catch (error) { | ||
console.log("::warning::Error, during update, bailing out: ", error); | ||
} | ||
}; |
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.
"If this PR is not ready for a review, please mark it as a draft"