From 94c1799201d975f883df03a22dcefea0f926dc3a Mon Sep 17 00:00:00 2001 From: anc95 <1481988258@qq.com> Date: Wed, 15 Feb 2023 10:08:04 +0000 Subject: [PATCH 1/2] handle sync event --- package.json | 5 ++--- src/bot.ts | 30 ++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 282a994..181f6a7 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,9 @@ "probot-app" ], "scripts": { - "start": "node -r dotenv/config ./dist/lib/index.js", + "start": "node -r dotenv/config ./dist/index.js", "test": "jest", - "build": "rm -rf dist && rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript", - "deploy": "node -r dotenv/config" + "build": "rm -rf dist && rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript" }, "dependencies": { "@vercel/edge": "^0.2.7", diff --git a/src/bot.ts b/src/bot.ts index 8110d83..cc5cba9 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -26,6 +26,11 @@ export const robot = (app: Probot) => { app.on(['pull_request.opened', 'pull_request.synchronize'], async (context) => { const repo = context.repo(); const chat = await loadChat(context); + const pull_request = context.payload.pull_request; + + if (pull_request.state === 'closed' || pull_request.locked || pull_request.draft) { + return; + } const data = await context.octokit.request( `GET /repos/{owner}/{repo}/compare/{basehead}`, @@ -36,14 +41,31 @@ export const robot = (app: Probot) => { } ); - const { files, commits } = data.data; + let { files: changedFiles, commits } = data.data; + + if (context.payload.action === 'synchronize') { + if (commits.length >= 2) { + const { data: { files } } = await context.octokit.request( + `GET /repos/{owner}/{repo}/compare/{basehead}`, + { + owner: repo.owner, + repo: repo.repo, + basehead: `${commits[commits.length - 2].sha}...${commits[commits.length - 1].sha}`, + } + ); + + const filesNames = files?.map(file => file.filename) || []; + changedFiles = changedFiles?.filter(file => filesNames.includes(file.filename)) + } + } + - if (!files?.length) { + if (!changedFiles?.length) { return; } - for (let i = 0; i < files.length; i++) { - const file = files[i]; + for (let i = 0; i < changedFiles.length; i++) { + const file = changedFiles[i]; const patch = file.patch || ''; if (!patch || patch.length > MAX_PATCH_COUNT) { From 86d6c3d3d600ee4c6da2031a660e5c82b98180e1 Mon Sep 17 00:00:00 2001 From: anc95 <1481988258@qq.com> Date: Wed, 15 Feb 2023 10:12:26 +0000 Subject: [PATCH 2/2] add code review keyword --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 181f6a7..4652a17 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "keywords": [ "probot", "github", - "probot-app" + "probot-app", + "code review" ], "scripts": { "start": "node -r dotenv/config ./dist/index.js",