fix(git-sources): return 200 for stacks without a Git source (#1294)

The dashboard probes GET /api/stacks/<name>/git-source for every stack to
decide whether to show a Git badge. For a stack with no Git source attached
the endpoint answered 404, so a fleet of unlinked stacks painted a red 404
per stack in the browser console.

Return 200 { linked: false } when the stack exists but has no Git source,
and reserve 404 for the genuine "stack does not exist" case (mirroring the
existence guard the PUT handler already uses). The two consumers that read
this endpoint now treat the { linked: false } sentinel as unlinked rather
than as a configured source.
This commit is contained in:
Anso
2026-06-02 22:02:49 -04:00
committed by GitHub
parent c68f0b494c
commit ae0b9d166c
6 changed files with 213 additions and 22 deletions
@@ -76,29 +76,38 @@ export function GitSourcePanel({
const { runWithLog } = useDeployFeedback();
const applyMode = deriveApplyMode(source, applyModeOverride);
const resetToUnlinked = useCallback(() => {
setSource(null);
setRepoUrl('');
setBranch('main');
setComposePath('compose.yaml');
setSyncEnv(false);
setAuthType('none');
setToken('');
setApplyModeOverride(null);
}, []);
const load = useCallback(async () => {
setLoading(true);
try {
const res = await apiFetch(`/stacks/${encodeURIComponent(stackName)}/git-source`);
if (res.ok) {
const data: GitSource = await res.json();
setSource(data);
setRepoUrl(data.repo_url);
setBranch(data.branch);
setComposePath(data.compose_path);
setSyncEnv(data.sync_env);
setAuthType(data.auth_type);
setToken('');
setApplyModeOverride(null);
const data: GitSource | { linked: false } = await res.json();
// An existing stack with no Git source attached answers 200 { linked: false }.
if ('linked' in data) {
resetToUnlinked();
} else {
setSource(data);
setRepoUrl(data.repo_url);
setBranch(data.branch);
setComposePath(data.compose_path);
setSyncEnv(data.sync_env);
setAuthType(data.auth_type);
setToken('');
setApplyModeOverride(null);
}
} else if (res.status === 404) {
setSource(null);
setRepoUrl('');
setBranch('main');
setComposePath('compose.yaml');
setSyncEnv(false);
setAuthType('none');
setToken('');
setApplyModeOverride(null);
resetToUnlinked();
} else if (res.status === 403) {
setSource(null);
toast.error('You do not have permission to view this stack\'s Git source.');
@@ -111,7 +120,7 @@ export function GitSourcePanel({
} finally {
setLoading(false);
}
}, [stackName]);
}, [stackName, resetToUnlinked]);
useEffect(() => {
if (open) {