Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/pull_request_labels.yaml
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 })
55 changes: 55 additions & 0 deletions tools/label_pull_request.js
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.`,
Copy link
Member Author

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"

});
}

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

Choose a reason for hiding this comment

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

Create this label before landing

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to work well like below.

tools/package.json
{
  "type": "module"
}

https://github.com/actions/github-script/blob/e7aeb8c663f696059ebb5f9ab1425ed2ef511bdb/README.md#use-esm-import

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

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);
}
};
Loading