-
Notifications
You must be signed in to change notification settings - Fork 425
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. y为佬会抱歉啊 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how it works There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议优化提示词为具体的规则,简化评论的内容 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks really verbose |
||
|
There was a problem hiding this comment.
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:
Overall, the changes appear to be valid and should not cause any problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hello
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nihoa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
me la pela
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
성지순례 왔습니다 🙇♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
성지순례22