Skip to content

Commit

Permalink
fix: check for updates does not look for commit.json now
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodacus committed Dec 21, 2024
1 parent 63abf52 commit 4d0ac1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
30 changes: 21 additions & 9 deletions app/components/settings/debug/DebugTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,25 @@ const versionTag = connitJson.version;
const GITHUB_URLS = {
original: 'https://api.github.com/repos/stackblitz-labs/bolt.diy/commits/main',
fork: 'https://api.github.com/repos/Stijnus/bolt.new-any-llm/commits/main',
commitJson: (branch: string) =>
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/${branch}/app/commit.json`,
commitJson: async (branch: string) => {
try {
const response = await fetch(`https://api.github.com/repos/stackblitz-labs/bolt.diy/commits/${branch}`);
const data: { sha: string } = await response.json();

const packageJsonResp = await fetch(
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/${branch}/package.json`,
);
const packageJson: { version: string } = await packageJsonResp.json();

return {
commit: data.sha.slice(0, 7),
version: packageJson.version,
};
} catch (error) {
console.log('Failed to fetch local commit info:', error);
throw new Error('Failed to fetch local commit info');
}
},
};

function getSystemInfo(): SystemInfo {
Expand Down Expand Up @@ -373,14 +390,9 @@ export default function DebugTab() {
const branchToCheck = isLatestBranch ? 'main' : 'stable';
console.log(`[Debug] Checking for updates against ${branchToCheck} branch`);

const localCommitResponse = await fetch(GITHUB_URLS.commitJson(branchToCheck));

if (!localCommitResponse.ok) {
throw new Error('Failed to fetch local commit info');
}
const latestCommitResp = await GITHUB_URLS.commitJson(branchToCheck);

const localCommitData = (await localCommitResponse.json()) as CommitData;
const remoteCommitHash = localCommitData.commit;
const remoteCommitHash = latestCommitResp.commit;
const currentCommitHash = versionHash;

if (remoteCommitHash !== currentCommitHash) {
Expand Down
14 changes: 4 additions & 10 deletions app/lib/hooks/useSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ export function useSettings() {
// Function to check if we're on stable version
const checkIsStableVersion = async () => {
try {
const stableResponse = await fetch(
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/refs/tags/v${versionData.version}/app/commit.json`,
const response = await fetch(
`https://api.github.com/repos/stackblitz-labs/bolt.diy/git/refs/tags/v${versionData.version}`,
);
const data: { object: { sha: string } } = await response.json();

if (!stableResponse.ok) {
console.warn('Failed to fetch stable commit info');
return false;
}

const stableData = (await stableResponse.json()) as CommitData;

return versionData.commit === stableData.commit;
return versionData.commit.slice(0, 7) === data.object.sha.slice(0, 7);
} catch (error) {
console.warn('Error checking stable version:', error);
return false;
Expand Down

0 comments on commit 4d0ac1d

Please sign in to comment.