From d7d532069a183573c4657ad8ac5e3e612adbd3ca Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Wed, 10 Sep 2025 14:50:16 +0200 Subject: [PATCH] fix: Make GitHub service optional and add debug logging - Make GitHub service work without REPO_URL environment variable - Add debug logging to ScriptsGrid to troubleshoot rendering issues - Improve error handling for missing GitHub configuration --- src/app/_components/ScriptsGrid.tsx | 8 ++++++++ src/server/services/github.ts | 28 +++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/app/_components/ScriptsGrid.tsx b/src/app/_components/ScriptsGrid.tsx index e6ea39c..30902d0 100644 --- a/src/app/_components/ScriptsGrid.tsx +++ b/src/app/_components/ScriptsGrid.tsx @@ -16,6 +16,14 @@ export function ScriptsGrid() { { enabled: !!selectedSlug } ); + // Debug logging + console.log('ScriptsGrid render:', { + isLoading, + error: error?.message, + scriptCardsData: scriptCardsData?.success, + cardsCount: scriptCardsData?.cards?.length + }); + const handleCardClick = (scriptCard: ScriptCardType) => { setSelectedSlug(scriptCard.slug); setIsModalOpen(true); diff --git a/src/server/services/github.ts b/src/server/services/github.ts index 93bd26e..53b41c2 100644 --- a/src/server/services/github.ts +++ b/src/server/services/github.ts @@ -12,18 +12,20 @@ export class GitHubService { this.branch = env.REPO_BRANCH; this.jsonFolder = env.JSON_FOLDER; - if (!this.repoUrl) { - throw new Error("REPO_URL environment variable is not set. Please set it to a valid GitHub repository URL."); + // Only validate GitHub URL if it's provided + if (this.repoUrl) { + // Extract owner and repo from the URL + const urlMatch = this.repoUrl.match(/github\.com\/([^\/]+)\/([^\/]+)/); + if (!urlMatch) { + throw new Error(`Invalid GitHub repository URL: ${this.repoUrl}`); + } + + const [, owner, repo] = urlMatch; + this.baseUrl = `https://api.github.com/repos/${owner}/${repo}`; + } else { + // Set a dummy base URL if no REPO_URL is provided + this.baseUrl = ""; } - - // Extract owner and repo from the URL - const urlMatch = this.repoUrl.match(/github\.com\/([^\/]+)\/([^\/]+)/); - if (!urlMatch) { - throw new Error(`Invalid GitHub repository URL: ${this.repoUrl}`); - } - - const [, owner, repo] = urlMatch; - this.baseUrl = `https://api.github.com/repos/${owner}/${repo}`; } private async fetchFromGitHub(endpoint: string): Promise { @@ -42,6 +44,10 @@ export class GitHubService { } async getJsonFiles(): Promise { + if (!this.repoUrl) { + throw new Error('REPO_URL environment variable is not set. Cannot fetch from GitHub.'); + } + try { const files = await this.fetchFromGitHub( `/contents/${this.jsonFolder}?ref=${this.branch}`