fix(atlassian): tighten health checks and review coverage
This commit is contained in:
69
skills/atlassian/cursor/scripts/src/health.ts
Normal file
69
skills/atlassian/cursor/scripts/src/health.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { createJsonHeaders, createStatusError } from "./http.js";
|
||||
import type { AtlassianConfig, CommandOutput, FetchLike } from "./types.js";
|
||||
|
||||
type ProductHealth = {
|
||||
ok: boolean;
|
||||
status?: number;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
function buildUrl(baseUrl: string, path: string) {
|
||||
return new URL(path, `${baseUrl}/`).toString();
|
||||
}
|
||||
|
||||
export async function runHealthCheck(
|
||||
config: AtlassianConfig,
|
||||
fetchImpl: FetchLike | undefined,
|
||||
): Promise<CommandOutput<unknown>> {
|
||||
const client = fetchImpl ?? globalThis.fetch;
|
||||
|
||||
if (!client) {
|
||||
throw new Error("Fetch API is not available in this runtime");
|
||||
}
|
||||
|
||||
async function probe(product: "Jira" | "Confluence", url: string): Promise<ProductHealth> {
|
||||
try {
|
||||
const response = await client(url, {
|
||||
method: "GET",
|
||||
headers: createJsonHeaders(config, false),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = createStatusError(`${product} health check failed`, response);
|
||||
return {
|
||||
ok: false,
|
||||
status: response.status,
|
||||
message: error.message,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
status: response.status,
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
return {
|
||||
ok: false,
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const jira = await probe("Jira", buildUrl(config.jiraBaseUrl, "/rest/api/3/myself"));
|
||||
const confluence = await probe("Confluence", buildUrl(config.confluenceBaseUrl, "/wiki/api/v2/spaces?limit=1"));
|
||||
|
||||
return {
|
||||
ok: jira.ok && confluence.ok,
|
||||
data: {
|
||||
baseUrl: config.baseUrl,
|
||||
jiraBaseUrl: config.jiraBaseUrl,
|
||||
confluenceBaseUrl: config.confluenceBaseUrl,
|
||||
defaultProject: config.defaultProject,
|
||||
defaultSpace: config.defaultSpace,
|
||||
products: {
|
||||
jira,
|
||||
confluence,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user