Skip to content

Commit

Permalink
fix: removing org subs check temp
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Jan 4, 2025
1 parent fb03b1f commit 6f49eba
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 96 deletions.
179 changes: 88 additions & 91 deletions functions/issue-scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IssueNode>;
};
}

interface GraphQlSearchResponse {
search: {
pageInfo: {
hasNextPage: boolean;
endCursor: string | null;
};
}
nodes: Array<IssueNode>;
};
}

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<Response> {
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;
Expand All @@ -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(
Expand Down Expand Up @@ -209,7 +207,6 @@ async function fetchUserIssues(octokit: InstanceType<typeof Octokit>, username:
// Pulls issues from GitHub and stores them in Supabase
async function issueScraper(username: string, supabase: SupabaseClient, voyageApiKey: string, token?: string): Promise<string> {
try {

if (!username) {
throw new Error("Username is required");
}
Expand Down
6 changes: 3 additions & 3 deletions src/home/getters/get-github-access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/home/scraper/issue-scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -37,4 +37,4 @@ export async function startIssueScraper(username: string) {
message: `Failed to fetch issues. Status: ${response.status}`,
});
}
}
}

0 comments on commit 6f49eba

Please sign in to comment.