-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository.ts
More file actions
42 lines (37 loc) · 976 Bytes
/
repository.ts
File metadata and controls
42 lines (37 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as z from "zod/mini";
import { NotFoundRequestError, request } from "../lib/request";
const RepositorySchema = z.object({
quotas: z.optional(
z.object({
sliceMachineEnabled: z.boolean(),
}),
),
});
export type Repository = z.infer<typeof RepositorySchema>;
export async function getRepository(config: {
repo: string;
token: string | undefined;
host: string;
}): Promise<Repository> {
const { repo, token, host } = config;
const url = getRepositoryServiceUrl(host);
url.searchParams.set("repository", repo);
try {
const response = await request(url, {
headers: {
Authorization: `Bearer ${token}`,
repository: repo,
},
schema: RepositorySchema,
});
return response;
} catch (error) {
if (error instanceof NotFoundRequestError) {
error.message = `Repository not found: ${repo}`;
}
throw error;
}
}
function getRepositoryServiceUrl(host: string): URL {
return new URL(`https://api.internal.${host}/repository/`);
}