From 824074213528873268c4cab307d6bd3747207c53 Mon Sep 17 00:00:00 2001 From: Martin Robledo Date: Tue, 5 Sep 2023 11:50:00 -0500 Subject: [PATCH 01/12] feat: adding the githubactivity end point and schema --- .../GitHub/GitHubActivity/index.tsx | 29 +++++++++++++++++++ app/routes/api/github/get-proyectActivity.tsx | 11 +++++++ app/routes/projects/$projectId/index.tsx | 6 ++++ .../migration.sql | 14 +++++++++ prisma/schema.prisma | 11 +++++++ 5 files changed, 71 insertions(+) create mode 100644 app/core/components/GitHub/GitHubActivity/index.tsx create mode 100644 app/routes/api/github/get-proyectActivity.tsx create mode 100644 prisma/migrations/20230904212433_git_hub_activity/migration.sql diff --git a/app/core/components/GitHub/GitHubActivity/index.tsx b/app/core/components/GitHub/GitHubActivity/index.tsx new file mode 100644 index 00000000..b8dc31ce --- /dev/null +++ b/app/core/components/GitHub/GitHubActivity/index.tsx @@ -0,0 +1,29 @@ +import { Card, CardHeader, CardContent } from "@mui/material"; +import { useMemo, useState } from "react"; +import { getActivity } from "~/routes/api/github/get-proyectActivity"; + + +export default function GitHubActivity({ repoName }: { repoName: string }) { + const [activityList, setActivityList] = useState(); + + useMemo( + () => + getActivity(repoName) + .then((data) => { + const commitData = data.data; + console.log(data); + commitData ? setActivityList(commitData) : setActivityList([]); + }) + .catch((error) => console.log(error)), + [repoName] + ); + + return ( + <> + + + + + + ); +} \ No newline at end of file diff --git a/app/routes/api/github/get-proyectActivity.tsx b/app/routes/api/github/get-proyectActivity.tsx new file mode 100644 index 00000000..6e341289 --- /dev/null +++ b/app/routes/api/github/get-proyectActivity.tsx @@ -0,0 +1,11 @@ +import { Octokit } from "@octokit/core"; +import { env } from "process"; +const octokit = new Octokit({ auth: env.GITHUB_KEY }); + +export const getActivity = async (repo: string) => { + const owner = "wizeline"; + return await octokit.request(`GET /repos/{owner}/{repo}/events`, { + owner, + repo, + }); +}; \ No newline at end of file diff --git a/app/routes/projects/$projectId/index.tsx b/app/routes/projects/$projectId/index.tsx index 9559db75..e5a1cbef 100644 --- a/app/routes/projects/$projectId/index.tsx +++ b/app/routes/projects/$projectId/index.tsx @@ -56,6 +56,7 @@ import { checkPermission } from "~/models/authorization.server"; import type { Roles } from "~/models/authorization.server"; import GitHub from '@mui/icons-material/GitHub'; import { validateNavigationRedirect } from '~/utils'; +import GitHubActivity from "~/core/components/GitHub/GitHubActivity"; export function links() { return [ @@ -607,6 +608,11 @@ export default function ProjectDetailsPage() { project={project} /> )} + + + + + ); } diff --git a/prisma/migrations/20230904212433_git_hub_activity/migration.sql b/prisma/migrations/20230904212433_git_hub_activity/migration.sql new file mode 100644 index 00000000..61d7e858 --- /dev/null +++ b/prisma/migrations/20230904212433_git_hub_activity/migration.sql @@ -0,0 +1,14 @@ +-- CreateTable +CREATE TABLE "GitHubActivity" ( + "id" SERIAL NOT NULL, + "typeEvent" TEXT NOT NULL, + "created_at" TEXT NOT NULL, + "author" TEXT NOT NULL, + "avatar_url" TEXT NOT NULL, + "projectId" TEXT, + + CONSTRAINT "GitHubActivity_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "GitHubActivity" ADD CONSTRAINT "GitHubActivity_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Projects"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index f49c3f31..dac5dbe8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -223,6 +223,7 @@ model Projects { resources Resource[] projectBoard String? applicants Applicant[] + githubActivity GitHubActivity[] // here also the change of name for map @@index([ownerId], map: "projects_owner_id_idx") @@ -435,3 +436,13 @@ model Experience{ profileId String? profile Profiles? @relation(fields: [profileId], references: [id], onDelete: SetNull, onUpdate: Cascade) } + +model GitHubActivity { + id Int @id @default(autoincrement()) + typeEvent String + created_at String + author String + avatar_url String + projectId String? + project Projects? @relation(fields: [projectId], references: [id], onDelete: SetNull, onUpdate: Cascade) +} From dd95b28b225d73adccfdf246ffb5ed40fbeabc9d Mon Sep 17 00:00:00 2001 From: Martin Robledo Date: Thu, 14 Sep 2023 11:19:58 -0500 Subject: [PATCH 02/12] feat: git hub activity section --- .../GitHub/GitHubActivity/index.tsx | 64 ++++++++++++------- app/models/githubactivity.server.ts | 34 ++++++++++ app/routes/api/github/get-proyectActivity.tsx | 23 +++++-- .../projects/$projectId/github-info/index.tsx | 63 ++++++++++++++---- app/routes/projects/$projectId/index.tsx | 8 +-- .../migration.sql | 4 +- prisma/schema.prisma | 4 +- 7 files changed, 147 insertions(+), 53 deletions(-) create mode 100644 app/models/githubactivity.server.ts rename prisma/migrations/{20230904212433_git_hub_activity => 20230913223350_github_activity}/migration.sql (86%) diff --git a/app/core/components/GitHub/GitHubActivity/index.tsx b/app/core/components/GitHub/GitHubActivity/index.tsx index b8dc31ce..3e02ba21 100644 --- a/app/core/components/GitHub/GitHubActivity/index.tsx +++ b/app/core/components/GitHub/GitHubActivity/index.tsx @@ -1,29 +1,47 @@ -import { Card, CardHeader, CardContent } from "@mui/material"; -import { useMemo, useState } from "react"; -import { getActivity } from "~/routes/api/github/get-proyectActivity"; +import { Card, CardContent, TableContainer, Table, TableHead, TableRow, TableCell, TableBody } from "@mui/material"; +interface gitHubActivitySchema { + id: string, + typeEvent: string, + created_at: Date, + author: string, + avatar_url:string, + projectId:string | null, +} -export default function GitHubActivity({ repoName }: { repoName: string }) { - const [activityList, setActivityList] = useState(); - - useMemo( - () => - getActivity(repoName) - .then((data) => { - const commitData = data.data; - console.log(data); - commitData ? setActivityList(commitData) : setActivityList([]); - }) - .catch((error) => console.log(error)), - [repoName] - ); - +export default function GitHubActivity({ repoName, projectId, activityData }: { repoName: string, projectId: string, activityData: gitHubActivitySchema[] }) { return ( - <> - - - + + + + + + + Event Type + Author + Created At + + + + + { + activityData && activityData.map(event => ( + + + {event.typeEvent} + + {event.author} + { event.created_at.toDateString()} + + )) + } + +
+
+
- ); } \ No newline at end of file diff --git a/app/models/githubactivity.server.ts b/app/models/githubactivity.server.ts new file mode 100644 index 00000000..415d2e8a --- /dev/null +++ b/app/models/githubactivity.server.ts @@ -0,0 +1,34 @@ +import { prisma } from "~/db.server"; + +export async function saveACtivity( + id: string, + typeEvent: string, + created_at: string, + author: string, + avatar_url: string, + projectId: string + ){ + + const activityRegister = await prisma.gitHubActivity.findFirst({ where: { id } }); + + if(!activityRegister) { + + return await prisma.gitHubActivity.create({ + data: { + id, + typeEvent, + created_at: new Date(created_at), + author, + avatar_url, + projectId + } + }) + + } + } + + +export async function getGitActivityData(projectId: string) { + return await prisma.gitHubActivity.findMany({ where: { projectId }, orderBy: { id: "desc" }}); +} + diff --git a/app/routes/api/github/get-proyectActivity.tsx b/app/routes/api/github/get-proyectActivity.tsx index 6e341289..44adfddb 100644 --- a/app/routes/api/github/get-proyectActivity.tsx +++ b/app/routes/api/github/get-proyectActivity.tsx @@ -1,11 +1,24 @@ import { Octokit } from "@octokit/core"; import { env } from "process"; +import { saveACtivity } from "~/models/githubactivity.server"; const octokit = new Octokit({ auth: env.GITHUB_KEY }); -export const getActivity = async (repo: string) => { +export const getActivity = async (repo: string, projectId: string) => { const owner = "wizeline"; - return await octokit.request(`GET /repos/{owner}/{repo}/events`, { - owner, - repo, - }); + if(repo != ''){ + const repoActivity = await octokit.request(`GET /repos/{owner}/{repo}/events`, { + owner, + repo, + }); + + repoActivity.data.forEach( activity => { + saveACtivity(activity.id , + activity.type?.replace(/([a-z0-9])([A-Z])/g, '$1 $2') as string, //this is for separe the string with camel case into pieces + activity.created_at as string, activity.actor.display_login as string, + activity.actor.avatar_url as string, projectId ); + return; + }); + }else{ + return; + } }; \ No newline at end of file diff --git a/app/routes/projects/$projectId/github-info/index.tsx b/app/routes/projects/$projectId/github-info/index.tsx index 84f4f3eb..b2b2a315 100644 --- a/app/routes/projects/$projectId/github-info/index.tsx +++ b/app/routes/projects/$projectId/github-info/index.tsx @@ -1,36 +1,51 @@ -import { CircularProgress, Container, Grid, Paper, Stack, Typography } from "@mui/material"; +import { Button, Container, Grid, Paper, Typography } from "@mui/material"; import type { LoaderArgs } from "@remix-run/server-runtime"; import { typedjson, useTypedLoaderData } from "remix-typedjson"; import invariant from "tiny-invariant"; import Header from "~/core/layouts/Header"; import { getProject } from "~/models/project.server"; -import GitHub from '@mui/icons-material/GitHub'; import GoBack from "~/core/components/GoBack"; +import { GitHub, Refresh } from "@mui/icons-material"; +import type { Repos } from "@prisma/client"; +import GitHubActivity from "~/core/components/GitHub/GitHubActivity"; +import { getGitActivityData } from "~/models/githubactivity.server"; +// import { getActivity } from "~/routes/api/github/get-proyectActivity"; export const loader = async ({ request, params }: LoaderArgs) => { invariant(params.projectId, "projectId not found"); const projectId = params.projectId; - const project = await getProject({ id: params.projectId }); if (!project) { throw new Response("Not Found", { status: 404 }); } + // await getActivity('remix-project-lab',projectId); + const activityData = await getGitActivityData(projectId); return typedjson({ project, - projectId + projectId, + activityData }); }; - + + +const cleanURL = (repoInfo: Repos[]):string => { + + if (repoInfo[0] && repoInfo[0].url !== '') { + return repoInfo[0].url.substring(repoInfo[0].url.lastIndexOf("/") + 1); + } else { + return ""; + } +} export default function GitHubInfo() { const { - project,projectId + project,projectId, activityData } = useTypedLoaderData(); - + return <>
@@ -46,20 +61,40 @@ export default function GitHubInfo() {

{project.name}

- Last commit: + Last commit:
- - -

We are working in this section

- - - + +
+ + + + + + + Project Participation + +