From 5a28a46e8506300ad4edc35294d5f29cad942f36 Mon Sep 17 00:00:00 2001 From: Sstark97 Date: Wed, 6 Nov 2024 21:17:00 +0000 Subject: [PATCH] :sparkles: Add a button to drop all repos in local --- app/page.tsx | 31 ++++++++++++++++++++-------- src/backend/gitRepositoryManager.ts | 32 +++++++++++++++++++++++++++++ src/backend/server.ts | 6 +++++- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 5b396cf..68df2dd 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,11 +1,13 @@ -import { Textarea } from "@/components/ui/textarea" -import { Button } from "@/components/ui/button" -import { Card, CardContent } from "@/components/ui/card" -import { Label } from "@/components/ui/label" -import { Code2, Shuffle } from "lucide-react" -import {OpenAnonymousRandomRepositoryServerAction} from "@/src/backend/server"; +import {Textarea} from "@/components/ui/textarea" +import {Button} from "@/components/ui/button" +import {Card, CardContent} from "@/components/ui/card" +import {Label} from "@/components/ui/label" +import {Code2, Shuffle} from "lucide-react" +import {deleteAllRepositoriesServerAction, openAnonymousRandomRepositoryServerAction} from "@/src/backend/server"; export default function CodeReviewQuiz() { + const isLocal = process.env.NODE_ENV === 'development' + return (

¡Deja que el azar elija tu próxima revisión de código!

-
+
+
+ {isLocal ? ( +
+ +
+ ) + : <> + }
diff --git a/src/backend/gitRepositoryManager.ts b/src/backend/gitRepositoryManager.ts index 508cdc8..a0fef30 100644 --- a/src/backend/gitRepositoryManager.ts +++ b/src/backend/gitRepositoryManager.ts @@ -88,4 +88,36 @@ export class GitRepositoryManager implements RepositoryManager { console.error('Error al subir el código al nuevo repositorio:', error); } } + + async deleteAllReposInOrg(org: string) { + const octokit = new Octokit({ + auth: process.env.GITHUB_TOKEN, + }); + try { + // Obtener todos los repositorios de la organización + const repos = await octokit.paginate(octokit.rest.repos.listForOrg, { + org, + per_page: 100, + }); + + console.log(`Repositorios encontrados en la organización "${org}": ${repos.length}`); + + // Eliminar cada repositorio + for (const repo of repos) { + try { + await octokit.rest.repos.delete({ + owner: org, + repo: repo.name, + }); + console.log(`Repositorio eliminado: ${repo.name}`); + } catch (error) { + console.error(`Error al eliminar el repositorio ${repo.name}:`, error); + } + } + + console.log('Todos los repositorios han sido eliminados.'); + } catch (error) { + console.error('Error al obtener repositorios:', error); + } + } } \ No newline at end of file diff --git a/src/backend/server.ts b/src/backend/server.ts index 330fcb3..0b5e6a5 100644 --- a/src/backend/server.ts +++ b/src/backend/server.ts @@ -9,13 +9,17 @@ import {v4 as uuidv4} from 'uuid'; import {RepositoryManager} from "@/src/backend/repositoryManager"; import {randomInt} from "node:crypto"; -export async function OpenAnonymousRandomRepositoryServerAction(formData: FormData) { +export async function openAnonymousRandomRepositoryServerAction(formData: FormData) { const urls = formData.get("urls") as string const urlList = urls.split("\n").filter(url => url.trim() !== "").map(url => url.replace("\r", "")) console.log(urlList) await execute(urlList, new GitRepositoryManager()); } +export async function deleteAllRepositoriesServerAction() { + await new GitRepositoryManager().deleteAllReposInOrg("anonymous-code-review"); +} + export async function execute(repos: string[], repositoryManager: RepositoryManager) { const tmpDir = os.tmpdir(); const repoUrl = getRandomFrom(repos);