Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add basic functionality of analyzing tech stack from repository #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/admin/actions/check-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use server"

import { z } from "zod"
import { getRepoOwnerAndName } from "~/lib/repositories"
import { authedProcedure } from "~/lib/safe-actions"
import { GitHubTechStackAnalyzer } from "~/lib/tech-stack-analyzer"
import { prisma } from "~/services/prisma"

export const analyzeRepository = authedProcedure
.createServerAction()
.input(z.object({ id: z.string() }))
.handler(async ({ input: { id } }) => {
const { repository } = await prisma.tool.findUniqueOrThrow({ where: { id } })
const repo = getRepoOwnerAndName(repository)

if (!repo) return null

const github = new GitHubTechStackAnalyzer()
const analysis = await github.analyzeTechStack(repo.owner, repo.name)
return analysis
})
16 changes: 16 additions & 0 deletions apps/admin/app/(dashboard)/tools/_components/tool-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type React from "react"
import { useState } from "react"
import { toast } from "sonner"
import { useServerAction } from "zsa-react"
import { analyzeRepository } from "~/actions/check-repository"
import { ToolScheduleDialog } from "~/app/(dashboard)/tools/_components/tool-schedule-dialog"
import { ToolsDeleteDialog } from "~/app/(dashboard)/tools/_components/tools-delete-dialog"
import { reuploadToolAssets } from "~/app/(dashboard)/tools/_lib/actions"
Expand Down Expand Up @@ -42,6 +43,17 @@ export const ToolActions = ({ tool, row, className, ...props }: ToolActionsProps
},
})

const { execute: analyzeRepositoryAction } = useServerAction(analyzeRepository, {
onSuccess: ({ data }) => {
console.log(data)
toast.success("Repository analyzed")
},

onError: ({ err }) => {
toast.error(err.message)
},
})

const handleDialogSuccess = () => {
setShowDeleteDialog(false)
row?.toggleSelected(false)
Expand Down Expand Up @@ -103,6 +115,10 @@ export const ToolActions = ({ tool, row, className, ...props }: ToolActionsProps
Reupload Assets
</DropdownMenuItem>

<DropdownMenuItem onSelect={() => analyzeRepositoryAction({ id: tool.id })}>
Analyze Repository
</DropdownMenuItem>

<DropdownMenuSeparator />

<DropdownMenuItem asChild>
Expand Down
Loading