Skip to content

Commit

Permalink
Merge branch 'main' into feat/onboarding-ai
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfdivyansh authored Dec 5, 2024
2 parents ebfa716 + d9181f3 commit bd8733e
Show file tree
Hide file tree
Showing 45 changed files with 1,343 additions and 286 deletions.
21 changes: 8 additions & 13 deletions .github/workflows/format-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Checkout the PR branch

- uses: pnpm/action-setup@v4
name: Install pnpm
Expand All @@ -41,27 +43,20 @@ jobs:
restore-keys: |
${{ runner.os }}-pnpm-
- name: Install dependencies
run: pnpm install
- name: Install dependencies & turbo
run: pnpm install && pnpm i -g turbo

- name: Check formatting with Prettier
id: format_check
run: |
if pnpm format:check; then
echo "Formatting is correct"
else
echo "Formatting required"
echo "formatting_required=true" >> $GITHUB_ENV
fi
- name: Format code with Prettier
run: turbo format:write

- name: Check for changes and push if needed
run: |
if [ -n "$(git status --porcelain)" ]; then
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore: format code with Prettier"
git push
git commit -m "format: make the code prettier"
git push origin ${{ github.head_ref }}
else
echo "No formatting changes to push."
fi
2 changes: 1 addition & 1 deletion apps/api/app/api/[[...route]]/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ app.use(
exposeHeaders: ["Content-Length"],
maxAge: 600,
credentials: true,
})
}),
);
app.get("/*", (c) => auth.handler(c.req.raw));
app.post("/*", (c) => auth.handler(c.req.raw));
Expand Down
11 changes: 11 additions & 0 deletions apps/api/app/api/[[...route]]/contributors.ts
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;
17 changes: 17 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,28 @@ 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
37 changes: 20 additions & 17 deletions apps/api/app/api/[[...route]]/user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Hono } from "hono";
import { prisma } from "@repo/db";
import {auth} from "@repo/auth"

import { auth } from "@repo/auth";

const app = new Hono()
.get("/self", async (c) => {
Expand All @@ -10,10 +9,13 @@ const app = new Hono()
});

if (!currentUser) {
return c.json({
message: "Not logged in",
status: 400,
},400);
return c.json(
{
message: "Not logged in",
status: 400,
},
400,
);
}

const user = await prisma.user.findUnique({
Expand All @@ -26,32 +28,34 @@ const app = new Hono()
{
user,
},
200
200,
);
})
.get("/all", async (c) => {
const cursor = c.req.query("cursor");
const take = c.req.query("take");
if (!c.req.url.includes("?cursor=")) {
return c.redirect("?cursor=");
return c.redirect("?cursor=");
}

const users = await prisma.user.findMany({
take: parseInt(take!) || 10,
skip: 1,
cursor: cursor ? {
id: cursor,
} :undefined
cursor: cursor
? {
id: cursor,
}
: undefined,
});

const nextCursor = users.length > 0 ? users[users.length - 1].id : null;

return c.json(
{
nextCursor,
users
users,
},
200
200,
);
})
.get("/:id", async (c) => {
Expand All @@ -71,9 +75,8 @@ const app = new Hono()
{
user,
},
200
200,
);
});


export default app;
export default app;
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;
4 changes: 3 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
"@hono/zod-validator": "^0.4.1",
"@prisma/client": "^5.22.0",
"@repo/auth": "workspace:*",
"@repo/cache": "workspace:*",
"@repo/db": "workspace:*",
"@repo/mail": "workspace:*",
"@repo/types": "workspace:*",
"@repo/cache": "workspace:*",
"@repo/crypt":"workspace:*",
"hono": "^4.6.9",
"next": "15.0.2",
"next": "15.0.3",
"prisma": "^5.22.0",
"react": "19.0.0-rc-02c0e824-20241028",
"react-dom": "19.0.0-rc-02c0e824-20241028",
Expand Down
5 changes: 3 additions & 2 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"lint:fix": "next lint --fix",
"typecheck": "tsc --noEmit",
"format:write": "prettier --write \"**/*.{ts,tsx,mdx}\" --cache",
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache"
"format:check": "prettier --check \"**/*.{ts,tsx,mdx}\" --cache",
"react-scan": "pnpm dlx react-scan@latest http://localhost:3002"
},
"dependencies": {
"@ai-sdk/google": "^1.0.4",
Expand Down Expand Up @@ -47,7 +48,7 @@
"input-otp": "^1.4.1",
"lucide-react": "^0.454.0",
"motion": "^11.12.0",
"next": "15.0.2",
"next": "15.0.3",
"next-themes": "^0.4.3",
"react": "19.0.0-rc-02c0e824-20241028",
"react-beautiful-dnd": "^13.1.1",
Expand Down
3 changes: 2 additions & 1 deletion apps/status/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev -p 3004 --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"react-scan": "pnpm dlx react-scan@latest http://localhost:3004"
},
"dependencies": {
"@radix-ui/react-accordion": "^1.2.1",
Expand Down
Binary file modified apps/status/public/images/plura-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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;
}
},
});
32 changes: 31 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,36 @@ 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 @@ -43,6 +72,7 @@ export default function About() {
/>
</Card>
</div>
<ContributorsGrid data={contributors} />
</section>
</div>
</section>
Expand Down
Loading

0 comments on commit bd8733e

Please sign in to comment.