-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/onboarding-ai
- Loading branch information
Showing
45 changed files
with
1,343 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Hono } from "hono"; | ||
import { cache } from "@repo/cache"; | ||
|
||
const app = new Hono().get("/", async (c) => { | ||
const contributorsData = await cache.lrange("contributors", 0, -1); | ||
return c.json({ | ||
contributorsData, | ||
}); | ||
}); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { cache } from '@repo/cache'; | ||
import { logger, schedules } from '@trigger.dev/sdk/v3'; | ||
|
||
type ContributorData = { | ||
login: string; | ||
id: number; | ||
avatar_url?: string; | ||
html_url: string; | ||
}; | ||
|
||
export const publishContributorsTask = schedules.task({ | ||
id: "publish-contributors", | ||
cron: "0 0 * * 0", // Runs every Sunday at midnight | ||
maxDuration: 60, | ||
run: async () => { | ||
const owner = 'SkidGod4444'; // Replace with the repository owner's username | ||
const repo = 'plura'; // Replace with the repository name | ||
const GITHUB_TOKEN = process.env.GITHUB_TOKEN; | ||
|
||
let contributors: ContributorData[] = []; | ||
let page = 1; | ||
const MAX_PAGES = 10; // Limit total pages to prevent excessive API calls | ||
try { | ||
do { | ||
if (page > MAX_PAGES) { | ||
logger.warn(`Reached maximum page limit of ${MAX_PAGES}`); | ||
break; | ||
} | ||
const response = await fetch( | ||
`https://api.github.com/repos/${owner}/${repo}/contributors?per_page=100&page=${page}`, | ||
{ | ||
headers: { | ||
Authorization: `token ${GITHUB_TOKEN}`, | ||
Accept: 'application/vnd.github.v3+json', | ||
}, | ||
} | ||
); | ||
const rateLimit = response.headers.get('x-ratelimit-remaining'); | ||
if (rateLimit === '0') { | ||
logger.error('GitHub API rate limit exceeded'); | ||
return; | ||
} | ||
if (!response.ok) { | ||
logger.error(`GitHub API request failed with status ${response.status}`); | ||
return; | ||
} | ||
|
||
const data = await response.json(); | ||
|
||
if (data.length === 0) { | ||
break; | ||
} | ||
|
||
contributors = contributors.concat(data); | ||
page += 1; | ||
} while (page <=MAX_PAGES); | ||
|
||
// Filter out bots based on type or if 'bot' appears in their login | ||
const filteredContributors = contributors.filter( | ||
(contributor) => | ||
!contributor.login.toLowerCase().includes('bot') | ||
); | ||
|
||
// Prepare data: list of { login, id, avatar_url, html_url } | ||
const contributorData = filteredContributors.map((contributor) => ({ | ||
login: contributor.login, | ||
id: contributor.id, | ||
avatar_url: contributor.avatar_url, | ||
github_link: contributor.html_url, | ||
})); | ||
|
||
// Store data in Redis under a fixed key | ||
const redisKey = 'contributors'; | ||
try { | ||
await cache.del(redisKey); | ||
await cache.rpush(redisKey, ...contributorData.map((c) => JSON.stringify(c))); | ||
} catch (error) { | ||
logger.error('Failed to store contributors in Redis', { error }); | ||
throw error; | ||
} | ||
logger.log('Published contributors data', { contributorData }); | ||
} catch (error) { | ||
logger.error('Error fetching contributors from GitHub', { error }); | ||
throw error; | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.