Skip to content

Commit

Permalink
chore: setup project linting (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Balastrong authored Aug 11, 2024
1 parent 97489ae commit 6b62ee1
Show file tree
Hide file tree
Showing 112 changed files with 1,617 additions and 1,578 deletions.
1 change: 1 addition & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
titleOnly: true
26 changes: 26 additions & 0 deletions .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check code style

on:
pull_request:
branches:
- main

jobs:
run-checks:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4.0.0
- name: Setup Node
uses: actions/setup-node@v4.0.3
with:
node-version-file: .nvmrc
- run: pnpm i --frozen-lockfile

- name: Checking format
run: pnpm run format:check
- name: Run lint
run: pnpm run lint
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.15.1
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"semi": false,
"plugins": ["prettier-plugin-tailwindcss"]
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"name": "myntenance",
"version": "0.1.0",
"private": true,
"packageManager": "pnpm@9.6.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"format": "prettier --write .",
"format:check": "prettier --check ./src",
"format:fix": "prettier --write ./src",
"supabase-types-gen": "supabase gen types typescript --project-id bqlqcmtccbsiocjopvas > src/lib/supabase/types.gen.ts"
},
"dependencies": {
Expand Down
32 changes: 16 additions & 16 deletions src/app/api/github/actions.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"use server";
import { getServerOctokit } from "@/lib/github/server";
import { createClient } from "@/lib/supabase/server";
import { revalidatePath } from "next/cache";
"use server"
import { getServerOctokit } from "@/lib/github/server"
import { createClient } from "@/lib/supabase/server"
import { revalidatePath } from "next/cache"

export async function storeRepository(fullName: string) {
"use server";
"use server"

try {
const [owner, repo] = fullName.split("/");
const [owner, repo] = fullName.split("/")

const {
data: { user },
} = await createClient().auth.getUser();
} = await createClient().auth.getUser()

if (!user) {
throw new Error("User not found");
throw new Error("User not found")
}

const { data: existingRepo } = await createClient()
Expand All @@ -24,16 +24,16 @@ export async function storeRepository(fullName: string) {
.eq("ownerLogin", owner)
.eq("user", user.id)
.limit(1)
.maybeSingle();
.maybeSingle()

if (existingRepo) {
throw new Error("Repository already exists");
throw new Error("Repository already exists")
}

const { data } = await getServerOctokit().rest.repos.get({
owner,
repo,
});
})

await createClient()
.from("projects")
Expand All @@ -44,16 +44,16 @@ export async function storeRepository(fullName: string) {
visibility: data.private ? "private" : "public",
stars: data.stargazers_count,
openIssues: data.open_issues_count,
});
})

revalidatePath("/", "layout");
return { message: "Repository stored", error: false };
revalidatePath("/", "layout")
return { message: "Repository stored", error: false }
} catch (error) {
const errorMessage =
error instanceof Error
? error?.message
: (undefined ?? "An error occurred");
: (undefined ?? "An error occurred")

return { message: errorMessage, error: true };
return { message: errorMessage, error: true }
}
}
44 changes: 22 additions & 22 deletions src/app/auth/actions.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
"use server";
"use server"

import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache"
import { redirect } from "next/navigation"

import { createClient } from "@/lib/supabase/server";
import { cookies, headers } from "next/headers";
import { createClient } from "@/lib/supabase/server"
import { cookies, headers } from "next/headers"
import {
GITHUB_REFRESH_TOKEN_COOKIE,
GITHUB_ACCESS_TOKEN_COOKIE,
} from "@/lib/supabase/cookies";
} from "@/lib/supabase/cookies"

export async function login() {
"use server";
const origin = headers().get("origin");
const supabase = createClient();
"use server"
const origin = headers().get("origin")
const supabase = createClient()

const { error, data } = await supabase.auth.signInWithOAuth({
provider: "github",
options: {
redirectTo: `${origin}/auth/callback`,
},
});
})

if (error) {
redirect("/error");
redirect("/error")
}

revalidatePath("/", "layout");
redirect(data.url);
revalidatePath("/", "layout")
redirect(data.url)
}

export async function logout() {
"use server";
const supabase = createClient();
"use server"
const supabase = createClient()

const {
data: { user },
} = await supabase.auth.getUser();
} = await supabase.auth.getUser()

if (user) {
await supabase.auth.signOut();
await supabase.auth.signOut()
}

const cookieStore = cookies();
cookieStore.delete(GITHUB_ACCESS_TOKEN_COOKIE);
cookieStore.delete(GITHUB_REFRESH_TOKEN_COOKIE);
const cookieStore = cookies()
cookieStore.delete(GITHUB_ACCESS_TOKEN_COOKIE)
cookieStore.delete(GITHUB_REFRESH_TOKEN_COOKIE)

revalidatePath("/", "layout");
redirect("/");
revalidatePath("/", "layout")
redirect("/")
}
36 changes: 18 additions & 18 deletions src/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import {
GITHUB_REFRESH_TOKEN_COOKIE,
GITHUB_ACCESS_TOKEN_COOKIE,
} from "@/lib/supabase/cookies";
import { createClient } from "@/lib/supabase/server";
import { createServerClient } from "@supabase/ssr";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
} from "@/lib/supabase/cookies"
import { createClient } from "@/lib/supabase/server"
import { createServerClient } from "@supabase/ssr"
import { cookies } from "next/headers"
import { NextResponse } from "next/server"

export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url);
const code = searchParams.get("code");
const { searchParams, origin } = new URL(request.url)
const code = searchParams.get("code")
// if "next" is in param, use it as the redirect URL
const next = searchParams.get("next") ?? "/dashboard";
const next = searchParams.get("next") ?? "/dashboard"

if (code) {
const cookieStore = cookies();
const supabase = createClient();
const cookieStore = cookies()
const supabase = createClient()

supabase.auth.onAuthStateChange((event, session) => {
if (session && session.provider_token) {
cookieStore.set(GITHUB_ACCESS_TOKEN_COOKIE, session.provider_token);
cookieStore.set(GITHUB_ACCESS_TOKEN_COOKIE, session.provider_token)
}

if (session && session.provider_refresh_token) {
cookieStore.set(
GITHUB_REFRESH_TOKEN_COOKIE,
session.provider_refresh_token,
{ expires: new Date().setMonth(new Date().getMonth() + 3) },
);
)
}

if (event === "SIGNED_OUT") {
cookieStore.delete(GITHUB_ACCESS_TOKEN_COOKIE);
cookieStore.delete(GITHUB_REFRESH_TOKEN_COOKIE);
cookieStore.delete(GITHUB_ACCESS_TOKEN_COOKIE)
cookieStore.delete(GITHUB_REFRESH_TOKEN_COOKIE)
}
});
})

const { error } = await supabase.auth.exchangeCodeForSession(code);
const { error } = await supabase.auth.exchangeCodeForSession(code)
if (!error) {
return NextResponse.redirect(`${origin}${next}`);
return NextResponse.redirect(`${origin}${next}`)
}
}

// return the user to an error page with instructions
return NextResponse.redirect(`${origin}/auth/auth-code-error`);
return NextResponse.redirect(`${origin}/auth/auth-code-error`)
}
10 changes: 5 additions & 5 deletions src/app/auth/signout/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createClient } from "@/lib/supabase/server";
import { NextResponse } from "next/server";
import { createClient } from "@/lib/supabase/server"
import { NextResponse } from "next/server"

export async function GET(request: Request) {
await createClient().auth.signOut();
await createClient().auth.signOut()

const { origin } = new URL(request.url);
const { origin } = new URL(request.url)

return NextResponse.redirect(origin);
return NextResponse.redirect(origin)
}
24 changes: 12 additions & 12 deletions src/app/dashboard/[projectId]/@modal/(.)task/[taskId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { RouteModal } from "@/components/RouteModal";
import { DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { getTask } from "@/services/tasks/api";
import TaskDetailComponent from "../../../task/[taskId]/TaskDetail";
import { getProject } from "@/services/project/api";
import { createClient } from "@/lib/supabase/server";
import { RouteModal } from "@/components/RouteModal"
import { DialogHeader, DialogTitle } from "@/components/ui/dialog"
import { getTask } from "@/services/tasks/api"
import TaskDetailComponent from "../../../task/[taskId]/TaskDetail"
import { getProject } from "@/services/project/api"
import { createClient } from "@/lib/supabase/server"

export default async function Page({
params: { taskId, projectId },
}: {
params: { taskId: string; projectId: string };
params: { taskId: string; projectId: string }
}) {
const { data: task } = await getTask({ projectId, taskId });
const { data: task } = await getTask({ projectId, taskId })

if (!task) {
return <RouteModal>Task not found</RouteModal>;
return <RouteModal>Task not found</RouteModal>
}

const project = await getProject(projectId, createClient());
const project = await getProject(projectId, createClient())

if (!project) {
return <div>Project not found</div>;
return <div>Project not found</div>
}

return (
Expand All @@ -32,5 +32,5 @@ export default async function Page({
repositoryFullName={`${project?.ownerLogin}/${project?.name}`}
/>
</RouteModal>
);
)
}
2 changes: 1 addition & 1 deletion src/app/dashboard/[projectId]/@modal/default.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function Default() {
return null;
return null
}
6 changes: 3 additions & 3 deletions src/app/dashboard/[projectId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ export default function Layout({
children,
modal,
}: Readonly<{
children: React.ReactNode;
modal: React.ReactNode;
children: React.ReactNode
modal: React.ReactNode
}>) {
return (
<>
{children}
{modal}
</>
);
)
}
Loading

0 comments on commit 6b62ee1

Please sign in to comment.