Skip to content

Commit

Permalink
Merge pull request #94 from ayushhunt/feat/collabsection
Browse files Browse the repository at this point in the history
Feat/collabsection
  • Loading branch information
SkidGod4444 authored Dec 2, 2024
2 parents 8366f83 + 824e749 commit 1c66f00
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 54 deletions.
14 changes: 14 additions & 0 deletions apps/api/app/api/[[...route]]/contributors.ts
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;
18 changes: 18 additions & 0 deletions apps/api/app/api/[[...route]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import auth from "./auth";
import status from "./status";
import health from "./health";
import user from "./user";
import contributors from "./contributors"
import { cors } from "hono/cors";

export const runtime = "edge";

Expand All @@ -18,13 +20,29 @@ const app = new Hono<{
};
}>().basePath("/api");

const allowedOrigins = [
"http://localhost:3003",
"https://www.plura.pro",
"https://app.plura.pro",
];


app.use(
'*',
cors({
origin: allowedOrigins, // Allow requests from your frontend origin
allowMethods: ['GET', 'POST', 'OPTIONS'],
})
);

app.route("/health", health);
app.route("/session", session);
app.route("/test", test);
app.route("/mail", mail);
app.route("/auth", auth);
app.route("/status", status);
app.route("/user", user);
app.route("/contributors", contributors);

const GET = handle(app);
const POST = handle(app);
Expand Down
7 changes: 1 addition & 6 deletions apps/api/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

const nextConfig = {
reactStrictMode: true,
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},

}

module.exports = nextConfig;
6 changes: 3 additions & 3 deletions apps/triggers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"@repo/cache": "workspace:*",
"@repo/db": "workspace:*",
"@supabase/supabase-js": "^2.46.1",
"@trigger.dev/sdk": "^3.1.2"
"@trigger.dev/sdk": "3.3.1"
},
"devDependencies": {
"@trigger.dev/build": "^3.1.2"
"@trigger.dev/build": "3.3.1"
}
}
}
87 changes: 87 additions & 0 deletions apps/triggers/src/contributors.ts
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;
}
},
});
35 changes: 34 additions & 1 deletion apps/www/app/(routes)/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client"
import ContributorsGrid from "@/components/custom/contributors-grid";
import {
SectionHeader,
SectionHeaderDescription,
Expand All @@ -6,9 +8,38 @@ import {
import { Card } from "@/components/ui/card";
import { siteConfig } from "@/config/site.config";
import Image from "next/image";
import React from "react";
import React, { useEffect, useState } from "react";

type ContributorData = {
login: string;
id: number;
avatar_url?: string;
github_link: string;
};

export default function About() {
const [contributors, setContributors] = useState<ContributorData[]>([]);
const fetchUrl =
process.env.NODE_ENV === 'production'
? 'https://app.plura.pro/api/contributors'
: 'http://localhost:3001/api/contributors';

useEffect(() => {
const fetchContributors = async () => {
try{
const response = await fetch(fetchUrl);
const data = await response.json();
console.log(data);
setContributors(data.contributorsData);
}catch (e){
console.log(e);
}
};
fetchContributors();
}, []);



return (
<section className="flex flex-col items-center md:items-start justify-center overflow-hidden">
<div className="absolute inset-0 mx-auto h-full w-full bg-[radial-gradient(circle,rgba(211,211,211,0.1),rgba(18,20,22,0.05),rgba(18,20,22,0))] opacity-60" />
Expand Down Expand Up @@ -42,7 +73,9 @@ export default function About() {
className="m-20 transition-all duration-200 hover:brightness-[0.8] grayscale rounded-2xl hover:grayscale-0 object-cover object-center shadow-lg border-2 p-1 border-dashed"
/>
</Card>

</div>
<ContributorsGrid data={contributors}/>
</section>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion apps/www/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function RootLayout({
</ThemeProvider>
<Toaster />
</body>
</PosthogProvider>
</PosthogProvider>
</html>
);
}
69 changes: 69 additions & 0 deletions apps/www/components/custom/contributors-grid.tsx
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>
);
}
3 changes: 3 additions & 0 deletions apps/www/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const nextConfig: NextConfig = {
typescript: {
ignoreBuildErrors: true,
},
images: {
domains: ['avatars.githubusercontent.com'],
},
reactStrictMode: true,
};

Expand Down
3 changes: 2 additions & 1 deletion apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
"@radix-ui/react-switch": "^1.1.1",
"@radix-ui/react-tabs": "^1.1.1",
"@radix-ui/react-toast": "^1.2.2",
"@radix-ui/react-tooltip": "^1.1.3",
"@radix-ui/react-tooltip": "^1.1.4",
"@repo/auth": "workspace:*",
"@repo/cache": "workspace:*",
"@repo/db": "workspace:*",
"@repo/types": "workspace:*",
"@tabler/icons-react": "^3.21.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/crypt/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
tsconfig.tsbuildinfo
1 change: 1 addition & 0 deletions packages/crypt/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

Loading

0 comments on commit 1c66f00

Please sign in to comment.