-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from wizeline/feat/210/GITHUB-weekly-particip…
…ation-by-project Feat/210/GitHub weekly participation by project
- Loading branch information
Showing
12 changed files
with
8,000 additions
and
24,673 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,51 @@ | ||
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, projectId, activityData }: { repoName: string, projectId: string, activityData: gitHubActivitySchema[] }) { | ||
return ( | ||
<Card sx={{ width: 1, overflowY: 'scroll', height: 600 }}> | ||
<CardContent> | ||
<TableContainer > | ||
<Table> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell align="left">Event Type</TableCell> | ||
<TableCell align="right">Author</TableCell> | ||
<TableCell align="right">Created At</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
|
||
{ | ||
activityData && activityData.map(event => ( | ||
<TableRow | ||
key={event.id} | ||
sx={{ '&:last-child td, &:last-child th': { border: 0 } }} | ||
> | ||
<TableCell component="th" scope="row"> | ||
{event.typeEvent} | ||
</TableCell> | ||
<TableCell align="right">{event.author}</TableCell> | ||
<TableCell align="right">{ new Intl.DateTimeFormat([], { | ||
year: "numeric", | ||
month: "long", | ||
day: "2-digit", | ||
}).format(new Date(event.created_at))}</TableCell> | ||
</TableRow> | ||
)) | ||
} | ||
</TableBody> | ||
</Table> | ||
</TableContainer> | ||
</CardContent> | ||
</Card> | ||
); | ||
} |
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,31 @@ | ||
import { getActivity } from "./routes/api/github/get-proyectActivity"; | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
const db = new PrismaClient(); | ||
|
||
|
||
// export async function searchLastUpdateProjects() { | ||
|
||
// const lastUpdate = await prisma.$queryRaw<any[]>`SELECT DISTINCT p."id", p."name", p."projectBoard", MAX(ga.created_at) from "Projects" p | ||
// RIGHT JOIN "GitHubActivity" ga on p."id" = ga."projectId" | ||
// WHERE p."isArchived" = FALSE | ||
// GROUP BY p."id", p."name", p."projectBoard" | ||
// `; | ||
|
||
|
||
// } I will use it later jeje | ||
|
||
export async function getGitHubActivity() { | ||
const projectsBoards = await db.$queryRaw<any[]>` | ||
SELECT p."id", p."name", r.url from "Projects" p | ||
RIGHT JOIN "Repos" r on p."id" = r."projectId" | ||
WHERE p."isArchived" = FALSE and r."url" is not null | ||
`; | ||
|
||
try{ | ||
projectsBoards.map(async board => await getActivity(board.url, board.id).catch((e) => {throw(e)}) ) | ||
}catch(e){ | ||
throw (e); | ||
} | ||
|
||
} |
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,47 @@ | ||
import { prisma } from "../db.server"; | ||
import type { PrismaClient } from "@prisma/client"; | ||
|
||
interface gitHubActivityChartType { | ||
count: number, | ||
typeEvent: string, | ||
} | ||
|
||
export async function saveActivity( | ||
id: string, | ||
typeEvent: string, | ||
created_at: string, | ||
author: string, | ||
avatar_url: string, | ||
projectId: string, | ||
db?: PrismaClient | ||
){ | ||
|
||
const dbConnection = db ? db : prisma; | ||
|
||
const activityRegister = await dbConnection.gitHubActivity.findFirst({ where: { id } }); | ||
|
||
if(!activityRegister) { | ||
|
||
return await dbConnection.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" }}); | ||
} | ||
|
||
export const getActivityStadistic = async (week: number) => { | ||
return await prisma.$queryRaw<gitHubActivityChartType[]>`SELECT Count(*)::int, "typeEvent" FROM "GitHubActivity" where date_part('week', "created_at")=${week} GROUP BY "typeEvent"`; | ||
|
||
} | ||
|
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,48 @@ | ||
import { Octokit } from "@octokit/core"; | ||
import { env } from "process"; | ||
import { saveActivity } from "../../../models/githubactivity.server"; | ||
import { PrismaClient } from "@prisma/client"; | ||
const octokit = new Octokit({ auth: env.GITHUB_KEY }); | ||
|
||
const db = new PrismaClient(); | ||
|
||
function cleanUrlRepo(repoInfo: string) { | ||
if (repoInfo) { | ||
return repoInfo.substring(repoInfo.lastIndexOf("/") + 1); | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
export const getActivity = async (repo: string, projectId: string) => { | ||
|
||
const owner = "wizeline"; | ||
const repoUrlClean = cleanUrlRepo(repo); | ||
if(repo != ''){ | ||
try{ | ||
const repoActivity = await octokit.request(`GET /repos/${owner}/${repoUrlClean}/events`, { | ||
owner, | ||
repo, | ||
}).catch((e) => { throw(e)}); | ||
|
||
|
||
if(repoActivity.data.length){ | ||
repoActivity.data?.forEach( (activity: { id: string; type: string; created_at: string; actor: { display_login: string; avatar_url: string; }; }) => { | ||
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, db ); | ||
return; | ||
}); | ||
} | ||
|
||
|
||
}catch(e){ | ||
console.error(e); | ||
} | ||
|
||
}else{ | ||
return; | ||
} | ||
}; | ||
|
Oops, something went wrong.