-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from ayushhunt/feat/collabsection
Feat/collabsection
- Loading branch information
Showing
13 changed files
with
283 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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
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
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,69 @@ | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger, | ||
} from "@/components/ui/tooltip"; | ||
import { Avatar, AvatarImage, AvatarFallback } from "@radix-ui/react-avatar"; | ||
|
||
type ContributorData = { | ||
login: string; | ||
id: number; | ||
avatar_url?: string; | ||
github_link: string; | ||
}; | ||
|
||
interface ContributorsGridProps { | ||
data: ContributorData[]; | ||
} | ||
|
||
export default function ContributorsGrid({ data }: ContributorsGridProps) { | ||
return ( | ||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 mt-6 px-6 md:px-12 mb-8"> | ||
<TooltipProvider> | ||
{data.map((contributor) => ( | ||
<Tooltip key={contributor.id}> | ||
<TooltipTrigger> | ||
<div className="flex items-center gap-4 p-4 rounded-lg shadow-sm hover:shadow-md transition-all"> | ||
<Avatar className="w-10 h-10"> | ||
<AvatarImage | ||
src={contributor.avatar_url} | ||
alt={contributor.login} | ||
className="rounded-full" | ||
/> | ||
<AvatarFallback> | ||
{contributor.login.charAt(0).toUpperCase()} | ||
</AvatarFallback> | ||
</Avatar> | ||
<p className="text-sm font-medium">{contributor.login}</p> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent className="w-64 p-4 bg-gray-800 text-white shadow-xl rounded-xl flex flex-col gap-2"> | ||
<span className="flex items-center gap-2"> | ||
<Avatar className="w-8 h-8"> | ||
<AvatarImage | ||
src={contributor.avatar_url} | ||
alt={contributor.login} | ||
className="rounded-full" | ||
/> | ||
<AvatarFallback> | ||
{contributor.login.charAt(0).toUpperCase()} | ||
</AvatarFallback> | ||
</Avatar> | ||
<p className="text-sm font-semibold">{contributor.login}</p> | ||
</span> | ||
<a | ||
href={contributor.github_link} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="text-blue-400 hover:text-blue-600 text-xs underline mt-2 mb-2" | ||
> | ||
View Profile | ||
</a> | ||
</TooltipContent> | ||
</Tooltip> | ||
))} | ||
</TooltipProvider> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
tsconfig.tsbuildinfo |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.