diff --git a/functions/issue-scraper.ts b/functions/issue-scraper.ts index e9f79a83..b558f90b 100644 --- a/functions/issue-scraper.ts +++ b/functions/issue-scraper.ts @@ -7,113 +7,112 @@ import plainTextPlugin from "markdown-it-plain-text"; import { validatePOST } from "./validators"; interface MarkdownItWithPlainText extends markdownit { - plainText: string; - } - + plainText: string; +} + interface IssueMetadata { - nodeId: string; - number: number; - title: string; - body: string; - state: string; - repositoryName: string; - repositoryId: number; - assignees: string[]; - authorId: number; - createdAt: string; - closedAt: string | null; - stateReason: string | null; - updatedAt: string; - } - - interface IssueNode { + nodeId: string; + number: number; + title: string; + body: string; + state: string; + repositoryName: string; + repositoryId: number; + assignees: string[]; + authorId: number; + createdAt: string; + closedAt: string | null; + stateReason: string | null; + updatedAt: string; +} + +interface IssueNode { + id: string; + number: number; + title: string; + body: string; + state: string; + stateReason: string | null; + createdAt: string; + updatedAt: string; + closedAt: string | null; + author: { + login: string; + } | null; + assignees: { + nodes: Array<{ + login: string; + }>; + }; + repository: { id: string; - number: number; - title: string; - body: string; - state: string; - stateReason: string | null; - createdAt: string; - updatedAt: string; - closedAt: string | null; - author: { + name: string; + owner: { login: string; - } | null; - assignees: { - nodes: Array<{ - login: string; - }>; }; - repository: { - id: string; - name: string; - owner: { - login: string; - }; - }; - } - - interface GraphQlSearchResponse { - search: { - pageInfo: { - hasNextPage: boolean; - endCursor: string | null; - }; - nodes: Array; + }; +} + +interface GraphQlSearchResponse { + search: { + pageInfo: { + hasNextPage: boolean; + endCursor: string | null; }; - } + nodes: Array; + }; +} export const corsHeaders = { - "Access-Control-Allow-Origin": "*", - "Access-Control-Allow-Methods": "GET", - "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET", + "Access-Control-Allow-Headers": "Content-Type", }; export async function onRequest(ctx: Context): Promise { - const { request, env } = ctx; + const { request, env } = ctx; - try { - switch (request.method) { - case "POST": { - const result = await validatePOST(request); - if (!result.isValid || !result.gitHubUserId) { - return new Response("Unauthorized", { - headers: corsHeaders, - status: 400, - }); - } - try { - const supabase = new SupabaseClient(env.SUPABASE_URL, env.SUPABASE_ANON_KEY); - const response = await issueScraper(result.gitHubUserId, supabase, env.VOYAGEAI_API_KEY, result.authToken); - return new Response(response, { - headers: corsHeaders, - status: 200, - }); - } catch (error) { - console.error("Error processing request:", error); - return new Response("Internal Server Error", { - headers: corsHeaders, - status: 500, - }); - } - } - - default: - return new Response("Method Not Allowed", { - headers: corsHeaders, - status: 405, - }); + try { + switch (request.method) { + case "POST": { + const result = await validatePOST(request); + if (!result.isValid || !result.gitHubUserId) { + return new Response("Unauthorized", { + headers: corsHeaders, + status: 400, + }); } - } catch (error) { - console.error("Error processing request:", error); - return new Response("Internal Server Error", { + try { + const supabase = new SupabaseClient(env.SUPABASE_URL, env.SUPABASE_ANON_KEY); + const response = await issueScraper(result.gitHubUserId, supabase, env.VOYAGEAI_API_KEY, result.authToken); + return new Response(response, { + headers: corsHeaders, + status: 200, + }); + } catch (error) { + console.error("Error processing request:", error); + return new Response("Internal Server Error", { headers: corsHeaders, status: 500, + }); + } + } + + default: + return new Response("Method Not Allowed", { + headers: corsHeaders, + status: 405, }); } + } catch (error) { + console.error("Error processing request:", error); + return new Response("Internal Server Error", { + headers: corsHeaders, + status: 500, + }); + } } - function markdownToPlainText(markdown: string | null): string | null { if (!markdown) return markdown; const md = markdownit() as MarkdownItWithPlainText; @@ -122,7 +121,6 @@ function markdownToPlainText(markdown: string | null): string | null { return md.plainText; } - const SEARCH_ISSUES_QUERY = ` query SearchIssues($searchText: String!, $after: String) { search( @@ -209,7 +207,6 @@ async function fetchUserIssues(octokit: InstanceType, username: // Pulls issues from GitHub and stores them in Supabase async function issueScraper(username: string, supabase: SupabaseClient, voyageApiKey: string, token?: string): Promise { try { - if (!username) { throw new Error("Username is required"); } diff --git a/src/home/getters/get-github-access-token.ts b/src/home/getters/get-github-access-token.ts index c5303f81..c0c686dc 100644 --- a/src/home/getters/get-github-access-token.ts +++ b/src/home/getters/get-github-access-token.ts @@ -9,9 +9,9 @@ import { getLocalStore } from "./get-local-store"; export async function isOrgMemberWithoutScope() { const octokit = new Octokit({ auth: await getGitHubAccessToken() }); try { - await octokit.orgs.getMembershipForAuthenticatedUser({ - org: "ubiquity", - }); + // await octokit.orgs.getMembershipForAuthenticatedUser({ + // org: "ubiquity", + // }); } catch (e) { if (e && typeof e === "object" && "status" in e && e.status === 404) { return false; diff --git a/src/home/scraper/issue-scraper.ts b/src/home/scraper/issue-scraper.ts index 9c969a54..519d6826 100644 --- a/src/home/scraper/issue-scraper.ts +++ b/src/home/scraper/issue-scraper.ts @@ -14,7 +14,7 @@ export async function startIssueScraper(username: string) { message: "Skipping fetch - last fetch was less than 24 hours ago", }); } - + const response = await fetch("/issue-scraper", { method: "POST", headers: { @@ -37,4 +37,4 @@ export async function startIssueScraper(username: string) { message: `Failed to fetch issues. Status: ${response.status}`, }); } -} \ No newline at end of file +}