From 17a2e9092663f459711ef03dda2ffa41555cc041 Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 10 Dec 2024 22:31:16 +0000 Subject: [PATCH 1/4] fix: Remove direct GitHub API calls from frontend The frontend was making direct calls to the GitHub API to check PR status, which was causing 403 errors. This change removes those direct API calls since the PR status is already included in the cached data that's built by the backend. --- src/services/github.ts | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/services/github.ts b/src/services/github.ts index 098a0d0..fd1183f 100644 --- a/src/services/github.ts +++ b/src/services/github.ts @@ -1,25 +1,6 @@ import { BotActivity, IssueActivityStatus } from '../types'; -async function checkPRStatus(prUrl: string): Promise { - try { - const response = await fetch(prUrl); - if (!response.ok) { - return 'no_pr'; - } - const pr = await response.json(); - - if (pr.merged) { - return 'pr_merged'; - } else if (pr.state === 'closed') { - return 'pr_closed'; - } else { - return 'pr_open'; - } - } catch (error) { - console.error('Error checking PR status:', error); - return 'no_pr'; - } -} +// PR status is now included in the cached data, no need to fetch it export async function fetchBotActivities(since?: string): Promise { try { @@ -39,18 +20,8 @@ export async function fetchBotActivities(since?: string): Promise ); } - // Process issue activities to determine PR status - const processedActivities = await Promise.all(activities.map(async activity => { - if (activity.type === 'issue') { - if (activity.prUrl) { - const prStatus = await checkPRStatus(activity.prUrl); - return { ...activity, status: prStatus }; - } else { - return { ...activity, status: 'no_pr' as IssueActivityStatus }; - } - } - return activity; - })); + // PR status is already included in the cached data + const processedActivities = activities; // Sort by timestamp in descending order return processedActivities.sort((a, b) => From 4bcd143d964a1697a43798f1d2f21b10435137a2 Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 10 Dec 2024 22:36:51 +0000 Subject: [PATCH 2/4] test: Update tests to use cached PR status The tests were expecting the frontend to fetch PR status directly from GitHub API, but now that we've moved that logic to the backend, we need to update the tests to use the PR status from the cache instead. --- src/services/github.test.ts | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/services/github.test.ts b/src/services/github.test.ts index 2a9638c..76f3997 100644 --- a/src/services/github.test.ts +++ b/src/services/github.test.ts @@ -39,7 +39,7 @@ describe('GitHub Service', () => { activities: [{ id: 'issue-1-2', type: 'issue', - status: 'success', + status: 'pr_open', timestamp: '2023-11-28T00:01:00Z', url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-2', prUrl: 'https://api.github.com/repos/All-Hands-AI/OpenHands/pulls/2', @@ -47,11 +47,6 @@ describe('GitHub Service', () => { }], lastUpdated: '2023-11-28T00:01:00Z' }); - } else if (url === 'https://api.github.com/repos/All-Hands-AI/OpenHands/pulls/2') { - return createMockResponse({ - state: 'open', - merged: false - }); } throw new Error(`Unexpected URL: ${url}`); }); @@ -78,7 +73,7 @@ describe('GitHub Service', () => { activities: [{ id: 'issue-1-2', type: 'issue', - status: 'failure', + status: 'no_pr', timestamp: '2023-11-28T00:01:00Z', url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-2', description: 'The workflow to fix this issue encountered an error. Openhands failed to create any code changes.' @@ -143,7 +138,7 @@ describe('GitHub Service', () => { activities: [{ id: 'issue-1-2', type: 'issue', - status: 'success', + status: 'no_pr', timestamp: '2023-11-28T00:01:00Z', url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-2', description: 'Working on the issue...' @@ -173,7 +168,7 @@ describe('GitHub Service', () => { activities: [{ id: 'issue-1-2', type: 'issue', - status: 'success', + status: 'pr_open', timestamp: '2023-11-28T00:01:00Z', url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-2', prUrl: 'https://api.github.com/repos/All-Hands-AI/OpenHands/pulls/2', @@ -181,11 +176,6 @@ describe('GitHub Service', () => { }], lastUpdated: '2023-11-28T00:01:00Z' }); - } else if (url === 'https://api.github.com/repos/All-Hands-AI/OpenHands/pulls/2') { - return createMockResponse({ - state: 'open', - merged: false - }); } throw new Error(`Unexpected URL: ${url}`); }); @@ -209,7 +199,7 @@ describe('GitHub Service', () => { activities: [{ id: 'issue-1-2', type: 'issue', - status: 'success', + status: 'pr_merged', timestamp: '2023-11-28T00:01:00Z', url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-2', prUrl: 'https://api.github.com/repos/All-Hands-AI/OpenHands/pulls/2', @@ -217,11 +207,6 @@ describe('GitHub Service', () => { }], lastUpdated: '2023-11-28T00:01:00Z' }); - } else if (url === 'https://api.github.com/repos/All-Hands-AI/OpenHands/pulls/2') { - return createMockResponse({ - state: 'closed', - merged: true - }); } throw new Error(`Unexpected URL: ${url}`); }); @@ -245,7 +230,7 @@ describe('GitHub Service', () => { activities: [{ id: 'issue-1-2', type: 'issue', - status: 'success', + status: 'pr_closed', timestamp: '2023-11-28T00:01:00Z', url: 'https://github.com/All-Hands-AI/OpenHands/issues/1#comment-2', prUrl: 'https://api.github.com/repos/All-Hands-AI/OpenHands/pulls/2', @@ -253,11 +238,6 @@ describe('GitHub Service', () => { }], lastUpdated: '2023-11-28T00:01:00Z' }); - } else if (url === 'https://api.github.com/repos/All-Hands-AI/OpenHands/pulls/2') { - return createMockResponse({ - state: 'closed', - merged: false - }); } throw new Error(`Unexpected URL: ${url}`); }); From 685c556d5a1098fff59653926cf2b974357a4139 Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 10 Dec 2024 23:33:11 +0000 Subject: [PATCH 3/4] fix: Remove unused IssueActivityStatus import --- src/services/github.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/github.ts b/src/services/github.ts index fd1183f..0c83ed5 100644 --- a/src/services/github.ts +++ b/src/services/github.ts @@ -1,4 +1,4 @@ -import { BotActivity, IssueActivityStatus } from '../types'; +import { BotActivity } from '../types'; // PR status is now included in the cached data, no need to fetch it From 6a4ec10725058a9668fa46b572c7f572d90ac6db Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 10 Dec 2024 23:34:47 +0000 Subject: [PATCH 4/4] trigger: vercel deployment