Skip to content

Commit

Permalink
Fixed importLinks, adjusted syncGithub query to include more orgs/repos
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisischris committed Jun 9, 2024
1 parent dd59bc8 commit a53efb9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion routes/internal/importLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const importLinks = async () => {
await client.connect();
const links = event?.links ?? event?.queryStringParameters?.links?.split(',');
for (const link of links) {
const id = link?.split('id=')?.[1];
const id = isNaN(link) ? link?.split('id=')?.[1] : link;
const data = await (await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`)).json();

/*
Expand Down
13 changes: 7 additions & 6 deletions routes/scheduled/syncGithub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export const syncGithub = async () => {
const response = await (await fetch('https://api.github.com/graphql', {
method: 'POST',
body: JSON.stringify({
query: `{search(query: "org:${organization}", type: REPOSITORY, last: 20) {
query: `{search(query: "org:${organization}", type: REPOSITORY, last: 50) {
nodes {
... on Repository {
name
url
owner {
avatarUrl
}
refs(refPrefix: "refs/heads/", first: 5) {
refs(refPrefix: "refs/heads/", first: 10) {
edges {
node {
... on Ref {
Expand Down Expand Up @@ -75,11 +75,12 @@ export const syncGithub = async () => {

await client.connect();
for (const row of responseArray) {
await client.query(`
INSERT INTO "commits"("created_at", "repo", "repo_url", "branch", "commit", "commit_url", "image", "additions", "deletions", "changed_files") VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT DO NOTHING
`, [row?.date, row?.repo, row?.repoUrl, row?.branch, row?.commit, row?.commitUrl, row?.image, row?.additions, row?.deletions, row?.changed_files]);
await client.query(`INSERT INTO "commits"
("created_at", "repo", "repo_url", "branch", "commit", "commit_url", "image", "additions", "deletions", "changed_files")
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT DO NOTHING
`, [row?.date, row?.repo, row?.repoUrl, row?.branch, row?.commit, row?.commitUrl, row?.image, row?.additions, row?.deletions, row?.changed_files]);
}
await client.clean();

return { success: true, updated: responseArray?.length, repo: responseArray?.filter(obj => obj.repo.startsWith('longbow')) };
return { success: true, updated: responseArray?.length };
};

0 comments on commit a53efb9

Please sign in to comment.