Skip to content

fix: version endpoint #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LoaderCircle, CheckCircle2, XCircle } from "lucide-react";
import { HealthStatus } from "../lib/get-codegate-health";
import { HealthStatus } from "../types";

export const CodegateStatusHealth = ({
data: data,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoaderCircle, CheckCircle2, CircleAlert, XCircle } from "lucide-react";
import { VersionResponse } from "../lib/get-version-status";
import { Link, Tooltip, TooltipTrigger } from "@stacklok/ui-kit";
import { VersionResponse } from "../types";

export const CodegateStatusVersion = ({
data,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import { queryOptions, useQuery } from "@tanstack/react-query";

import { getCodeGateHealth } from "../lib/get-codegate-health";
import { getVersionStatus } from "../lib/get-version-status";
import {
PollingInterval,
POLLING_INTERVAl,
} from "../components/codegate-status-polling-control";
import { healthCheckHealthGet, v1VersionCheck } from "@/api/generated";
import { HealthStatus, VersionResponse } from "../types";

type HealthResponse = { status: "healthy" | unknown } | null;

const getCodeGateHealth = async (): Promise<HealthStatus | null> => {
const data = (await healthCheckHealthGet()).data;

if ((data as HealthResponse)?.status === "healthy")
return HealthStatus.HEALTHY;
if ((data as HealthResponse)?.status !== "healthy")
return HealthStatus.UNHEALTHY;

return null;
};

const getVersion = async (): Promise<VersionResponse | null> => {
return ((await v1VersionCheck()).data as VersionResponse) ?? null;
};

export function getQueryOptionsCodeGateStatus(
pollingInterval: PollingInterval,
) {
return queryOptions({
queryFn: async () => {
const health = await getCodeGateHealth();
const version = await getVersionStatus();
const version = await getVersion();

return {
health,
version,
version: version as VersionResponse | null,
};
},
queryKey: ["useHealthCheck", { pollingInterval }],
Expand Down
18 changes: 0 additions & 18 deletions src/features/dashboard-codegate-status/lib/get-codegate-health.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/features/dashboard-codegate-status/lib/get-version-status.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/features/dashboard-codegate-status/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum HealthStatus {
HEALTHY = "Healthy",
UNHEALTHY = "Unhealthy",
}

export type VersionResponse = {
current_version: string;
latest_version: string;
is_latest: boolean | null;
error: string | null;
} | null;
Loading