Skip to content

Commit

Permalink
feat: excluding removed 'files' at 'synchronize' (#44)
Browse files Browse the repository at this point in the history
* feat: excluding removed and renamed 'files'

* fix(chat): unnecessary comma
  • Loading branch information
jeonbyeongmin committed Mar 19, 2023
1 parent a472ee1 commit 7ee7c69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
35 changes: 19 additions & 16 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Context, Probot } from 'probot';

import { Chat } from './chat.js';

const OPENAI_API_KEY = 'OPENAI_API_KEY';
Expand Down Expand Up @@ -67,22 +68,20 @@ export const robot = (app: Probot) => {

let { files: changedFiles, commits } = data.data;

if (context.payload.action === 'synchronize') {
if (commits.length >= 2) {
const {
data: { files },
} = await context.octokit.repos.compareCommits({
owner: repo.owner,
repo: repo.repo,
base: commits[commits.length - 2].sha,
head: commits[commits.length - 1].sha,
});

const filesNames = files?.map((file) => file.filename) || [];
changedFiles = changedFiles?.filter((file) =>
filesNames.includes(file.filename)
);
}
if (context.payload.action === 'synchronize' && commits.length >= 2) {
const {
data: { files },
} = await context.octokit.repos.compareCommits({
owner: repo.owner,
repo: repo.repo,
base: commits[commits.length - 2].sha,
head: commits[commits.length - 1].sha,
});

const filesNames = files?.map((file) => file.filename) || [];
changedFiles = changedFiles?.filter((file) =>
filesNames.includes(file.filename)
);
}

if (!changedFiles?.length) {
Expand All @@ -95,6 +94,10 @@ export const robot = (app: Probot) => {
const file = changedFiles[i];
const patch = file.patch || '';

if(file.status !== 'modified' && file.status !== 'added') {
continue;
}

if (!patch || patch.length > MAX_PATCH_COUNT) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Chat {

private generatePrompt = (patch: string) => {
const answerLanguage = process.env.LANGUAGE
? `,Answer me in ${process.env.LANGUAGE},`
? `Answer me in ${process.env.LANGUAGE},`
: '';

return `Bellow is the code patch, please help me do a brief code review,${answerLanguage} if any bug risk and improvement suggestion are welcome
Expand Down

0 comments on commit 7ee7c69

Please sign in to comment.