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
This commit is contained in:
Michel Roegl-Brunner
2025-09-10 14:50:16 +02:00
parent 78144d2641
commit d7d532069a
2 changed files with 25 additions and 11 deletions

View File

@@ -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);

View File

@@ -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<T>(endpoint: string): Promise<T> {
@@ -42,6 +44,10 @@ export class GitHubService {
}
async getJsonFiles(): Promise<GitHubFile[]> {
if (!this.repoUrl) {
throw new Error('REPO_URL environment variable is not set. Cannot fetch from GitHub.');
}
try {
const files = await this.fetchFromGitHub<GitHubFile[]>(
`/contents/${this.jsonFolder}?ref=${this.branch}`