From 3609bf89a9abea7556b12469b7dc15dc75b7f602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 18 Apr 2025 11:51:18 +0200 Subject: [PATCH 1/4] chore: Add bot to comment on PRs --- .github/workflows/pull_request_labels.yaml | 25 ++++++++++ tools/label_pull_request.js | 53 ++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 .github/workflows/pull_request_labels.yaml create mode 100644 tools/label_pull_request.js diff --git a/.github/workflows/pull_request_labels.yaml b/.github/workflows/pull_request_labels.yaml new file mode 100644 index 0000000000..35a40213d0 --- /dev/null +++ b/.github/workflows/pull_request_labels.yaml @@ -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 }) diff --git a/tools/label_pull_request.js b/tools/label_pull_request.js new file mode 100644 index 0000000000..d27fef3073 --- /dev/null +++ b/tools/label_pull_request.js @@ -0,0 +1,53 @@ +// Copyright 2018-2025 the Deno authors. MIT license. + +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 the PR! + +Once you are done, please request a review from 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"); + + 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 +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); + } +}; From 832019c678530a55e537d1ec9c10009d4ccf74f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 18 Apr 2025 12:05:52 +0200 Subject: [PATCH 2/4] Update tools/label_pull_request.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Bartek IwaƄczuk --- tools/label_pull_request.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/label_pull_request.js b/tools/label_pull_request.js index d27fef3073..cd82b2502f 100644 --- a/tools/label_pull_request.js +++ b/tools/label_pull_request.js @@ -5,10 +5,9 @@ async function createComment(context, github) { issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: `Thanks the PR! + body: `Thanks for the PR! -Once you are done, please request a review from Deno team member.`, - }); +Once you are done, please request a review from a Deno team member.`, } async function updateLabels(context, github) { From 4dfffc40ad0f0dd0622414e1ae6558af86945c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 18 Apr 2025 13:43:54 +0200 Subject: [PATCH 3/4] fix copilot suggestion --- tools/label_pull_request.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/label_pull_request.js b/tools/label_pull_request.js index cd82b2502f..f555d84981 100644 --- a/tools/label_pull_request.js +++ b/tools/label_pull_request.js @@ -8,6 +8,7 @@ async function createComment(context, github) { body: `Thanks for the PR! Once you are done, please request a review from a Deno team member.`, + }); } async function updateLabels(context, github) { From ea2b6707e99d2179c6251d4c58854edc3bafaaa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 18 Apr 2025 17:37:00 +0200 Subject: [PATCH 4/4] lint --- tools/label_pull_request.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/label_pull_request.js b/tools/label_pull_request.js index f555d84981..c89d408ff5 100644 --- a/tools/label_pull_request.js +++ b/tools/label_pull_request.js @@ -1,5 +1,7 @@ // 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,