Skip to content
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

handle sync event #21

Merged
merged 2 commits into from
Feb 15, 2023
Merged
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"keywords": [
"probot",
"github",
"probot-app"
"probot-app",
"code review"
],
"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",
Copy link

Choose a reason for hiding this comment

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

with the code review

First, let's look at the changes made to the scripts:

  • The start script was changed from "node -r dotenv/config ./dist/lib/index.js" to "node -r dotenv/config ./dist/index.js". This change appears to be correct as it looks like the index file has been moved from the lib folder to the root dist folder.
  • The build script was changed from "rm -rf dist && rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript", which appears to be correct as it removes the previous build and creates a new one with the updated config.
  • Lastly, the deploy script was removed, which appears to be correct as it is no longer needed.

Overall, the changes appear to be valid and should not cause any problems.

Choose a reason for hiding this comment

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

1

Choose a reason for hiding this comment

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

你好

Copy link

Choose a reason for hiding this comment

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

你好

Choose a reason for hiding this comment

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

hello

Choose a reason for hiding this comment

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

你好

Choose a reason for hiding this comment

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

你好

Choose a reason for hiding this comment

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

nihoa

Choose a reason for hiding this comment

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

me la pela

Copy link

Choose a reason for hiding this comment

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

성지순례 왔습니다 🙇‍♂️

Copy link

Choose a reason for hiding this comment

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

from reviewing the code patch. Firstly, we should check if the keywords are added correctly and if there are any spelling mistakes. Then, we should check the scripts section to make sure the start and build command have been updated correctly. Lastly, we should check if the deploy command has been removed as it is no longer needed.

Choose a reason for hiding this comment

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

y为佬会抱歉啊

Expand Down
30 changes: 26 additions & 4 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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) {
Copy link

Choose a reason for hiding this comment

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

.

Firstly, the code looks well structured and organised, which is a good sign.

On line 28, it looks like a null check is missing on context.payload.pull_request. It would be better to add a null check to ensure that the code doesn't throw any errors if the payload is empty.

On line 30, a check is made to ensure that the pull request is not closed, locked or a draft. This is a good check, however, it may be better to add an else statement after this check to make the code easier to read.

On line 38, it looks like a null check is missing on the data.data.files array. It would be better to add a null check to ensure that the code doesn't throw any errors if the array is empty.

On line 43, a check is made to ensure that the changedFiles array has elements. It would be better to add a null check to ensure that the code doesn't throw any errors if the array is empty.

Finally, on line 53, it looks like there is no check to ensure that the patch is not empty. It would be better to add a check to ensure that the patch is not empty before trying to process it.

Overall, the code looks well structured and organized. However, there are a few minor improvements that can be made in terms of adding null checks and ensuring that the code is easier to read.

Choose a reason for hiding this comment

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

how it works

Choose a reason for hiding this comment

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

建议优化提示词为具体的规则,简化评论的内容

Copy link

Choose a reason for hiding this comment

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

It looks really verbose

Expand Down