From bebf94cdd42dd2acef0a14bfca262b22a11fb213 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Fri, 2 Jan 2026 01:44:14 +0800 Subject: [PATCH 1/7] add workflow --- .github/workflows/suggest-fill-prurl.yml | 23 +++++++ tools/actions/suggest-fill-prurl.mjs | 76 ++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 .github/workflows/suggest-fill-prurl.yml create mode 100755 tools/actions/suggest-fill-prurl.mjs diff --git a/.github/workflows/suggest-fill-prurl.yml b/.github/workflows/suggest-fill-prurl.yml new file mode 100644 index 00000000000000..3c43db540d5e51 --- /dev/null +++ b/.github/workflows/suggest-fill-prurl.yml @@ -0,0 +1,23 @@ +name: Suggest PR URL + +on: + pull_request: + types: [opened] + +permissions: + pull-requests: write + +jobs: + suggest-fill-prurl: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + persist-credentials: false + - run: ./tools/actions/suggest-fill-prurl.mjs + env: + # GH_TOKEN: ${{ secrets.GH_USER_TOKEN } + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.number }} + REPO: ${{ github.repository }} + SHA: ${{ github.sha }} diff --git a/tools/actions/suggest-fill-prurl.mjs b/tools/actions/suggest-fill-prurl.mjs new file mode 100755 index 00000000000000..4fd30736233f97 --- /dev/null +++ b/tools/actions/suggest-fill-prurl.mjs @@ -0,0 +1,76 @@ +#!/usr/bin/env node + +// Replaces: +// pr-url: https://github.com/nodejs/node/pull/FILLME +// With: +// pr-url: https://github.com/nodejs/node/pull/ACTUAL_PR_NUMBER +// And posts it as ```suggestion``` on pull request on GitHub + +import { env } from 'node:process'; + +const { GH_TOKEN, PR_NUMBER, REPO, SHA } = env; +if (!GH_TOKEN || !PR_NUMBER || !REPO || !SHA) { + throw new Error('Missing required environment variables'); +} + +const PLACEHOLDER = 'FILLME'; +const placeholderReg = new RegExp(`^\\+.*${RegExp.escape(`https://github.com/${REPO}/pull/${PLACEHOLDER}`)}`); + +const headers = new Headers({ + 'Accept': 'application/vnd.github+json', + 'Authorization': `Bearer ${GH_TOKEN}`, + 'User-Agent': 'nodejs-bot', + 'X-GitHub-Api-Version': '2022-11-28', +}); + +// https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests-files +const res = await fetch( + new URL(`repos/${REPO}/pulls/${PR_NUMBER}/files`, 'https://api.github.com'), + { headers }, +); +if (!res.ok) { + throw new Error(`Failed to fetch PR files, status=${res.status}`); +} + +const files = await res.json(); + +const comments = files.flatMap(({ status, filename, patch }) => { + if (!patch || !['added', 'modified'].includes(status)) { + return []; + } + + return patch.split('\n').map((line, position) => { + if (!placeholderReg.test(line)) { + return false; + } + const suggestion = line + .slice(1) + .replace(`https://github.com/${REPO}/pull/${PLACEHOLDER}`, `https://github.com/${REPO}/pull/${PR_NUMBER}`); + return { + path: filename, + position, + body: `Replace ${PLACEHOLDER} with PR number ${PR_NUMBER}\n` + + '```suggestion\n' + + `${suggestion}\n` + + '```\n', + }; + }).filter(Boolean); +}); + +if (comments.length) { + const payload = { + comments, + commit_id: SHA, + event: 'COMMENT', + }; + + // https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request + await fetch( + new URL(`repos/${REPO}/pulls/${PR_NUMBER}/reviews`, 'https://api.github.com'), + { + method: 'POST', + headers, + body: JSON.stringify(payload), + }, + ); +} From 220709ac73edfd3d0d4a45bd4a1b610f5f81f93e Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Fri, 2 Jan 2026 01:48:20 +0800 Subject: [PATCH 2/7] adjust workflow --- .github/workflows/suggest-fill-prurl.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/suggest-fill-prurl.yml b/.github/workflows/suggest-fill-prurl.yml index 3c43db540d5e51..b249dc33623570 100644 --- a/.github/workflows/suggest-fill-prurl.yml +++ b/.github/workflows/suggest-fill-prurl.yml @@ -2,7 +2,7 @@ name: Suggest PR URL on: pull_request: - types: [opened] + types: [opened, synchronize, reopened, ready_for_review] permissions: pull-requests: write @@ -17,7 +17,7 @@ jobs: - run: ./tools/actions/suggest-fill-prurl.mjs env: # GH_TOKEN: ${{ secrets.GH_USER_TOKEN } - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.number }} REPO: ${{ github.repository }} SHA: ${{ github.sha }} From c958c445635626bfe1de4fc2a7ed150d40a95d0b Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Fri, 2 Jan 2026 01:53:14 +0800 Subject: [PATCH 3/7] welp --- .github/workflows/suggest-fill-prurl.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/suggest-fill-prurl.yml b/.github/workflows/suggest-fill-prurl.yml index b249dc33623570..cdee8fc25a1525 100644 --- a/.github/workflows/suggest-fill-prurl.yml +++ b/.github/workflows/suggest-fill-prurl.yml @@ -14,6 +14,7 @@ jobs: - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 with: persist-credentials: false + - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 - run: ./tools/actions/suggest-fill-prurl.mjs env: # GH_TOKEN: ${{ secrets.GH_USER_TOKEN } From f582a8a407eb01c12e31eebaacaacbcf15ac5511 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Fri, 2 Jan 2026 01:55:44 +0800 Subject: [PATCH 4/7] ... --- .github/workflows/suggest-fill-prurl.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/suggest-fill-prurl.yml b/.github/workflows/suggest-fill-prurl.yml index cdee8fc25a1525..2fc8e169148eb5 100644 --- a/.github/workflows/suggest-fill-prurl.yml +++ b/.github/workflows/suggest-fill-prurl.yml @@ -15,6 +15,8 @@ jobs: with: persist-credentials: false - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version: latest - run: ./tools/actions/suggest-fill-prurl.mjs env: # GH_TOKEN: ${{ secrets.GH_USER_TOKEN } From 86292c3bc9b52028c0c23cae90ede478425a0862 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Fri, 2 Jan 2026 01:58:44 +0800 Subject: [PATCH 5/7] ... --- tools/actions/suggest-fill-prurl.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/actions/suggest-fill-prurl.mjs b/tools/actions/suggest-fill-prurl.mjs index 4fd30736233f97..e5e6b96718cbc6 100755 --- a/tools/actions/suggest-fill-prurl.mjs +++ b/tools/actions/suggest-fill-prurl.mjs @@ -33,12 +33,13 @@ if (!res.ok) { } const files = await res.json(); +console.log(files); const comments = files.flatMap(({ status, filename, patch }) => { if (!patch || !['added', 'modified'].includes(status)) { return []; } - +console.log(patch); return patch.split('\n').map((line, position) => { if (!placeholderReg.test(line)) { return false; @@ -56,7 +57,7 @@ const comments = files.flatMap(({ status, filename, patch }) => { }; }).filter(Boolean); }); - +console.log(comments); if (comments.length) { const payload = { comments, From d866070c3ba31b74ad51ab08a39191ad42e05855 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Fri, 2 Jan 2026 02:13:42 +0800 Subject: [PATCH 6/7] ... --- .github/workflows/linters.yml | 19 +++++++++++++++++ .github/workflows/suggest-fill-prurl.yml | 26 ------------------------ tools/actions/suggest-fill-prurl.mjs | 5 ++--- 3 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 .github/workflows/suggest-fill-prurl.yml diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 78344490800cf0..c926ca4e035fcf 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -247,6 +247,25 @@ jobs: sparse-checkout-cone-mode: false # GH Actions squashes all PR commits, HEAD^ refers to the base branch. - run: git diff HEAD^ HEAD -G"pr-url:" -- "*.md" | ./tools/lint-pr-url.mjs ${{ github.event.pull_request.html_url }} + suggest-fill-prurl: + needs: lint-pr-url + if: ${{ needs.lint-pr-url.result == 'failure' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + persist-credentials: false + sparse-checkout: /tools/actions/suggest-fill-prurl.mjs + sparse-checkout-cone-mode: false + - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version: latest + - run: node tools/actions/suggest-fill-prurl.mjs + env: + GH_TOKEN: ${{ secrets.GH_USER_TOKEN } + PR_NUMBER: ${{ github.event.number }} + REPO: ${{ github.repository }} + SHA: ${{ github.sha }} lint-readme: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/suggest-fill-prurl.yml b/.github/workflows/suggest-fill-prurl.yml deleted file mode 100644 index 2fc8e169148eb5..00000000000000 --- a/.github/workflows/suggest-fill-prurl.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Suggest PR URL - -on: - pull_request: - types: [opened, synchronize, reopened, ready_for_review] - -permissions: - pull-requests: write - -jobs: - suggest-fill-prurl: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 - with: - persist-credentials: false - - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 - with: - node-version: latest - - run: ./tools/actions/suggest-fill-prurl.mjs - env: - # GH_TOKEN: ${{ secrets.GH_USER_TOKEN } - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUMBER: ${{ github.event.number }} - REPO: ${{ github.repository }} - SHA: ${{ github.sha }} diff --git a/tools/actions/suggest-fill-prurl.mjs b/tools/actions/suggest-fill-prurl.mjs index e5e6b96718cbc6..4fd30736233f97 100755 --- a/tools/actions/suggest-fill-prurl.mjs +++ b/tools/actions/suggest-fill-prurl.mjs @@ -33,13 +33,12 @@ if (!res.ok) { } const files = await res.json(); -console.log(files); const comments = files.flatMap(({ status, filename, patch }) => { if (!patch || !['added', 'modified'].includes(status)) { return []; } -console.log(patch); + return patch.split('\n').map((line, position) => { if (!placeholderReg.test(line)) { return false; @@ -57,7 +56,7 @@ console.log(patch); }; }).filter(Boolean); }); -console.log(comments); + if (comments.length) { const payload = { comments, From 65026f648889bbcae95b96ad483f5f37fe2dd034 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Thu, 1 Jan 2026 22:31:39 +0800 Subject: [PATCH 7/7] doc: change something --- doc/api/buffer.md | 3 +++ doc/api/fs.md | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 981c053ac40f0c..681e3eab1eeeed 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -237,6 +237,9 @@ the characters.