diff --git a/scripts/src/github-api.test.ts b/scripts/src/github-api.test.ts index af28f6f..7b3a4a6 100644 --- a/scripts/src/github-api.test.ts +++ b/scripts/src/github-api.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { isSuccessComment, isPRModificationFailureComment } from './github-api'; +import { isSuccessComment, isPRModificationFailureComment, isBotComment, isStartWorkComment } from './github-api'; import type { GitHubComment } from './types'; describe('Comment detection', () => { @@ -24,4 +24,37 @@ describe('Comment detection', () => { }; expect(isPRModificationFailureComment(comment)).toBe(true); }); + + it('should detect openhands-ai[bot] as a bot', () => { + const comment: GitHubComment = { + id: 1, + html_url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-1', + created_at: '2023-11-28T00:01:00Z', + user: { login: 'openhands-ai[bot]', type: 'Bot' }, + body: 'Openhands is working, @neubig can click here to continue refining the PR', + }; + expect(isBotComment(comment)).toBe(true); + }); + + it('should detect new start work format', () => { + const comment: GitHubComment = { + id: 1, + html_url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-1', + created_at: '2023-11-28T00:01:00Z', + user: { login: 'openhands-ai[bot]', type: 'Bot' }, + body: 'Openhands is working, @neubig can click here to continue refining the PR', + }; + expect(isStartWorkComment(comment)).toBe(true); + }); + + it('should detect new success format', () => { + const comment: GitHubComment = { + id: 1, + html_url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-1', + created_at: '2023-11-28T00:01:00Z', + user: { login: 'openhands-ai[bot]', type: 'Bot' }, + body: '@neubig can click here to [continue refining the PR](https://app.all-hands.dev/conversations/e06b225de3a24fea97504511c80afc44)', + }; + expect(isSuccessComment(comment)).toBe(true); + }); }); \ No newline at end of file diff --git a/scripts/src/github-api.ts b/scripts/src/github-api.ts index 82da724..dda7fac 100644 --- a/scripts/src/github-api.ts +++ b/scripts/src/github-api.ts @@ -103,6 +103,7 @@ async function fetchAllPages<T>(url: string): Promise<T[]> { export function isBotComment(comment: GitHubComment): boolean { return comment.user.login === 'openhands-agent' || + comment.user.login === 'openhands-ai[bot]' || (comment.user.login === 'github-actions[bot]' && comment.user.type === 'Bot'); } @@ -110,7 +111,8 @@ export function isStartWorkComment(comment: GitHubComment): boolean { if (!isBotComment(comment)) return false; const lowerBody = comment.body.toLowerCase(); return lowerBody.includes('started fixing the') || - lowerBody.includes('openhands started fixing'); + lowerBody.includes('openhands started fixing') || + lowerBody.includes('openhands is working'); } export function isSuccessComment(comment: GitHubComment): boolean { @@ -122,7 +124,8 @@ export function isSuccessComment(comment: GitHubComment): boolean { const isSuccess = lowerBody.includes('a potential fix has been generated') || lowerBody.includes('openhands made the following changes to resolve the issues') || lowerBody.includes('successfully fixed') || - lowerBody.includes('updated pull request'); + lowerBody.includes('updated pull request') || + lowerBody.includes('can click here to [continue refining the pr]'); fs.appendFileSync('github-api.log', `[${new Date().toISOString()}] COMMENT CHECK: Bot comment - Success: ${String(isSuccess)}\nBody: ${comment.body}\n`); return isSuccess; }