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:
@@ -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);
|
||||
|
||||
@@ -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}`
|
||||
|
||||
Reference in New Issue
Block a user