* Fix: error building my application #1414 * fix for vite * Update vite.config.ts * Update root.tsx * fix the root.tsx and the debugtab * lm studio fix and fix for the api key * Update api.enhancer for prompt enhancement * bugfixes * Revert api.enhancer.ts back to original code * Update api.enhancer.ts * Update api.git-proxy.$.ts * Update api.git-proxy.$.ts * Update api.enhancer.ts
This commit is contained in:
@@ -1,138 +1,48 @@
|
||||
import type { LoaderFunction } from '@remix-run/cloudflare';
|
||||
import { json } from '@remix-run/cloudflare';
|
||||
import { execSync } from 'child_process';
|
||||
import { json, type LoaderFunction } from '@remix-run/cloudflare';
|
||||
|
||||
interface GitHubRepoInfo {
|
||||
name: string;
|
||||
full_name: string;
|
||||
default_branch: string;
|
||||
stargazers_count: number;
|
||||
forks_count: number;
|
||||
open_issues_count: number;
|
||||
parent?: {
|
||||
full_name: string;
|
||||
default_branch: string;
|
||||
stargazers_count: number;
|
||||
forks_count: number;
|
||||
interface GitInfo {
|
||||
local: {
|
||||
commitHash: string;
|
||||
branch: string;
|
||||
commitTime: string;
|
||||
author: string;
|
||||
email: string;
|
||||
remoteUrl: string;
|
||||
repoName: string;
|
||||
};
|
||||
github?: {
|
||||
currentRepo?: {
|
||||
fullName: string;
|
||||
defaultBranch: string;
|
||||
stars: number;
|
||||
forks: number;
|
||||
openIssues?: number;
|
||||
};
|
||||
};
|
||||
isForked?: boolean;
|
||||
}
|
||||
|
||||
const getLocalGitInfo = () => {
|
||||
try {
|
||||
return {
|
||||
commitHash: execSync('git rev-parse HEAD').toString().trim(),
|
||||
branch: execSync('git rev-parse --abbrev-ref HEAD').toString().trim(),
|
||||
commitTime: execSync('git log -1 --format=%cd').toString().trim(),
|
||||
author: execSync('git log -1 --format=%an').toString().trim(),
|
||||
email: execSync('git log -1 --format=%ae').toString().trim(),
|
||||
remoteUrl: execSync('git config --get remote.origin.url').toString().trim(),
|
||||
repoName: execSync('git config --get remote.origin.url')
|
||||
.toString()
|
||||
.trim()
|
||||
.replace(/^.*github.com[:/]/, '')
|
||||
.replace(/\.git$/, ''),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Failed to get local git info:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
// These values will be replaced at build time
|
||||
declare const __COMMIT_HASH: string;
|
||||
declare const __GIT_BRANCH: string;
|
||||
declare const __GIT_COMMIT_TIME: string;
|
||||
declare const __GIT_AUTHOR: string;
|
||||
declare const __GIT_EMAIL: string;
|
||||
declare const __GIT_REMOTE_URL: string;
|
||||
declare const __GIT_REPO_NAME: string;
|
||||
|
||||
const getGitHubInfo = async (repoFullName: string) => {
|
||||
try {
|
||||
// Add GitHub token if available
|
||||
const headers: Record<string, string> = {
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
};
|
||||
|
||||
const githubToken = process.env.GITHUB_TOKEN;
|
||||
|
||||
if (githubToken) {
|
||||
headers.Authorization = `token ${githubToken}`;
|
||||
}
|
||||
|
||||
console.log('Fetching GitHub info for:', repoFullName); // Debug log
|
||||
|
||||
const response = await fetch(`https://api.github.com/repos/${repoFullName}`, {
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('GitHub API error:', {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
repoFullName,
|
||||
});
|
||||
|
||||
// If we get a 404, try the main repo as fallback
|
||||
if (response.status === 404 && repoFullName !== 'stackblitz-labs/bolt.diy') {
|
||||
return getGitHubInfo('stackblitz-labs/bolt.diy');
|
||||
}
|
||||
|
||||
throw new Error(`GitHub API error: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('GitHub API response:', data); // Debug log
|
||||
|
||||
return data as GitHubRepoInfo;
|
||||
} catch (error) {
|
||||
console.error('Failed to get GitHub info:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const loader: LoaderFunction = async ({ request: _request }) => {
|
||||
const localInfo = getLocalGitInfo();
|
||||
console.log('Local git info:', localInfo); // Debug log
|
||||
|
||||
// If we have local info, try to get GitHub info for both our fork and upstream
|
||||
let githubInfo = null;
|
||||
|
||||
if (localInfo?.repoName) {
|
||||
githubInfo = await getGitHubInfo(localInfo.repoName);
|
||||
}
|
||||
|
||||
// If no local info or GitHub info, try the main repo
|
||||
if (!githubInfo) {
|
||||
githubInfo = await getGitHubInfo('stackblitz-labs/bolt.diy');
|
||||
}
|
||||
|
||||
const response = {
|
||||
local: localInfo || {
|
||||
commitHash: 'unknown',
|
||||
branch: 'unknown',
|
||||
commitTime: 'unknown',
|
||||
author: 'unknown',
|
||||
email: 'unknown',
|
||||
remoteUrl: 'unknown',
|
||||
repoName: 'unknown',
|
||||
export const loader: LoaderFunction = async () => {
|
||||
const gitInfo: GitInfo = {
|
||||
local: {
|
||||
commitHash: typeof __COMMIT_HASH !== 'undefined' ? __COMMIT_HASH : 'development',
|
||||
branch: typeof __GIT_BRANCH !== 'undefined' ? __GIT_BRANCH : 'main',
|
||||
commitTime: typeof __GIT_COMMIT_TIME !== 'undefined' ? __GIT_COMMIT_TIME : new Date().toISOString(),
|
||||
author: typeof __GIT_AUTHOR !== 'undefined' ? __GIT_AUTHOR : 'development',
|
||||
email: typeof __GIT_EMAIL !== 'undefined' ? __GIT_EMAIL : 'development@local',
|
||||
remoteUrl: typeof __GIT_REMOTE_URL !== 'undefined' ? __GIT_REMOTE_URL : 'local',
|
||||
repoName: typeof __GIT_REPO_NAME !== 'undefined' ? __GIT_REPO_NAME : 'bolt.diy',
|
||||
},
|
||||
github: githubInfo
|
||||
? {
|
||||
currentRepo: {
|
||||
fullName: githubInfo.full_name,
|
||||
defaultBranch: githubInfo.default_branch,
|
||||
stars: githubInfo.stargazers_count,
|
||||
forks: githubInfo.forks_count,
|
||||
openIssues: githubInfo.open_issues_count,
|
||||
},
|
||||
upstream: githubInfo.parent
|
||||
? {
|
||||
fullName: githubInfo.parent.full_name,
|
||||
defaultBranch: githubInfo.parent.default_branch,
|
||||
stars: githubInfo.parent.stargazers_count,
|
||||
forks: githubInfo.parent.forks_count,
|
||||
}
|
||||
: null,
|
||||
}
|
||||
: null,
|
||||
isForked: Boolean(githubInfo?.parent),
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
|
||||
console.log('Final response:', response);
|
||||
|
||||
// Debug log
|
||||
return json(response);
|
||||
return json(gitInfo);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user