-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connect github app to our web app
- Loading branch information
1 parent
a974c1b
commit 1352ae8
Showing
10 changed files
with
235 additions
and
99 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,7 @@ | ||
"use server" | ||
|
||
import { selectRepository } from "@/github/services/repository" | ||
|
||
export const selectRepoActions = async (id: string) => { | ||
return await selectRepository(id) | ||
} |
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,13 @@ | ||
import { DashboardHeader } from "@/components/header" | ||
import { DashboardShell } from "@/components/shell" | ||
|
||
export default function DashboardSettingsLoading() { | ||
return ( | ||
<DashboardShell> | ||
<DashboardHeader | ||
heading="Open issues" | ||
text="Comment on these issues to get assigned to work on them." | ||
/> | ||
</DashboardShell> | ||
) | ||
} |
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,43 @@ | ||
import { redirect } from "next/navigation" | ||
import { getRepositoriesForUser } from "@/github/services/repository" | ||
|
||
import { authOptions } from "@/lib/auth" | ||
import { db } from "@/lib/db" | ||
import { getCurrentUser } from "@/lib/session" | ||
import { DashboardHeader } from "@/components/header" | ||
import { RepoSelector } from "@/components/repo-selecor" | ||
import { DashboardShell } from "@/components/shell" | ||
|
||
import { selectRepoActions } from "./actions" | ||
|
||
export const metadata = { | ||
title: "Connect a Repository", | ||
description: "Comment on these issues to get assigned to work on them.", | ||
} | ||
|
||
export default async function SettingsPage() { | ||
const user = await getCurrentUser() | ||
if (!user) { | ||
redirect(authOptions?.pages?.signIn || "/login") | ||
} | ||
|
||
const repos = await getRepositoriesForUser(user.id) | ||
|
||
return ( | ||
<DashboardShell> | ||
<DashboardHeader | ||
heading="Connect a Repository" | ||
text="Select the repository you want to integrate oss.gg with." | ||
/> | ||
<div className="space-y-2"> | ||
{repos.map((repo) => ( | ||
<RepoSelector | ||
key={repo.id} | ||
repo={repo} | ||
selectRepoAction={selectRepoActions} | ||
/> | ||
))} | ||
</div> | ||
</DashboardShell> | ||
) | ||
} |
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,21 @@ | ||
"use client" | ||
|
||
import { useToast } from "@/components/ui/use-toast" | ||
|
||
export const RepoSelector = ({ repo, selectRepoAction }) => { | ||
const { toast } = useToast() | ||
return ( | ||
<div | ||
className="rounded-md p-3 flex space-x-3 items-center hover:bg-slate-10 hover:scale-102 border border-transparent hover:border-slate-200 transition-all hover:cursor-pointer ease-in-out duration-150" | ||
onClick={() => { | ||
selectRepoAction(repo.id) | ||
toast({ | ||
title: `${repo.name} selected`, | ||
description: "Next steps to be built", | ||
}) | ||
}} | ||
> | ||
{repo.name} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { db } from "@/lib/db" | ||
|
||
export const selectRepository = async (id: string) => { | ||
try { | ||
const selectedRepository = await db.repository.update({ | ||
where: { | ||
id, | ||
}, | ||
data: { | ||
configured: true, | ||
}, | ||
}) | ||
return selectedRepository | ||
} catch (error) { | ||
throw new Error(`Failed to select repository: ${error}`) | ||
} | ||
} | ||
|
||
export const getRepositoriesForUser = async (userId: string) => { | ||
try { | ||
const installationIds = await db.membership.findMany({ | ||
where: { | ||
userId, | ||
}, | ||
}) | ||
|
||
const repos = await db.repository.findMany({ | ||
where: { | ||
installationId: { | ||
in: installationIds.map((id) => id.installationId), | ||
}, | ||
configured: false, | ||
}, | ||
}) | ||
repos.sort((a, b) => a.name.localeCompare(b.name)) | ||
return repos | ||
} catch (error) { | ||
throw new Error(`Failed to get repositories for user: ${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
3 changes: 3 additions & 0 deletions
3
prisma/migrations/20240206044011_connect_repo_to_our_model/migration.sql
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,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "repositories" ADD COLUMN "configured" BOOLEAN NOT NULL DEFAULT false, | ||
ALTER COLUMN "default_branch" DROP NOT NULL; |
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