Skip to content
Open
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
8 changes: 2 additions & 6 deletions src/registry/clients/github-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import type { HttpClient } from "#/core";
import type { ResolvedRegistry } from "../registry.types";
import type { ResolvedGitHubRegistry } from "../registry.types";
import type { RegistryBrowser, BrowseResult, BrowsedArtifact } from "../browse.types";
import { ArtifactManifestSchema } from "#/schemas";
import { parse as parseYaml } from "yaml";
Expand Down Expand Up @@ -48,11 +48,7 @@ export class GitHubRepositoryBrowser implements RegistryBrowser {
private token?: string;
private http: HttpClient;

constructor(registry: ResolvedRegistry, http: HttpClient) {
if (!registry.project) {
throw new Error("GitHub browser requires 'project' field (owner/repo format)");
}

constructor(registry: ResolvedGitHubRegistry, http: HttpClient) {
this.apiHost = resolveApiHost(registry.host);
this.token = registry.token;
this.http = http;
Expand Down
69 changes: 22 additions & 47 deletions src/registry/clients/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import {
createMockTarOperations,
jsonResponse,
} from "#/test-utils/mocks";
import type { ResolvedRegistry } from "../registry.types";
import type { ResolvedGitHubRegistry } from "../registry.types";

describe("GitHubRegistryClient", () => {
const createClient = (registry: Partial<ResolvedRegistry> = {}) => {
const fullRegistry: ResolvedRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
const defaultGitHubRegistry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
};

const createClient = (registry: Partial<ResolvedGitHubRegistry> = {}) => {
const fullRegistry: ResolvedGitHubRegistry = {
...defaultGitHubRegistry,
...registry,
};
const http = createMockHttpClient();
Expand All @@ -31,37 +35,8 @@ describe("GitHubRegistryClient", () => {
};
};

describe("constructor", () => {
test("throws when project field is missing", () => {
const registry: ResolvedRegistry = {
type: "github",
host: "ghcr.io",
// project is missing
};
const http = createMockHttpClient();
const fs = createMockFileSystem();
const shell = createMockShellExecutor();

expect(
() => new GitHubRegistryClient(registry, http, fs, shell, createMockTarOperations())
).toThrow("GitHub registry requires 'project' field in config");
});

test("accepts registry with project field", () => {
const registry: ResolvedRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
};
const http = createMockHttpClient();
const fs = createMockFileSystem();
const shell = createMockShellExecutor();

expect(
() => new GitHubRegistryClient(registry, http, fs, shell, createMockTarOperations())
).not.toThrow();
});
});
// constructor: project is now required by the type system (discriminated union)
// so runtime null checks are no longer needed

describe("prefix configuration", () => {
test("prepends prefix to repository name when configured", async () => {
Expand All @@ -78,7 +53,7 @@ describe("GitHubRegistryClient", () => {
return jsonResponse({ tags: [] });
};

const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand All @@ -104,7 +79,7 @@ describe("GitHubRegistryClient", () => {
return jsonResponse({ tags: [] });
};

const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand All @@ -130,7 +105,7 @@ describe("GitHubRegistryClient", () => {
return jsonResponse({ tags: [] });
};

const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand Down Expand Up @@ -175,7 +150,7 @@ describe("GitHubRegistryClient", () => {
const shell = createMockShellExecutor({ tar: "" });
fs.files.set("/target/file.md", { content: "content", isDirectory: false });

const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand All @@ -201,7 +176,7 @@ describe("GitHubRegistryClient", () => {
return jsonResponse({});
};

const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand All @@ -221,7 +196,7 @@ describe("GitHubRegistryClient", () => {
return jsonResponse({});
};

const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand Down Expand Up @@ -290,7 +265,7 @@ describe("GitHubRegistryClient", () => {
});
};

const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand Down Expand Up @@ -362,7 +337,7 @@ describe("GitHubRegistryClient", () => {
return new Response("Forbidden", { status: 403 });
};

const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand Down Expand Up @@ -395,7 +370,7 @@ describe("GitHubRegistryClient", () => {
});

test("returns error when oras is not installed", async () => {
const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand Down Expand Up @@ -426,7 +401,7 @@ describe("GitHubRegistryClient", () => {
});

test("passes relative tarball path to oras", async () => {
const registry: ResolvedRegistry = {
const registry: ResolvedGitHubRegistry = {
type: "github",
host: "ghcr.io",
project: "myorg",
Expand Down
10 changes: 2 additions & 8 deletions src/registry/clients/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { relative } from "path";
import { validateTarballContents, generateSecureTempPath, type FileSystem, type HttpClient, type ShellExecutor, type TarOperations } from "#/core";
import type {
RegistryClient,
ResolvedRegistry,
ResolvedGitHubRegistry,
DownloadResult,
PublishResult,
RegistryArtifactInfo,
Expand All @@ -38,18 +38,12 @@ export class GitHubRegistryClient implements RegistryClient {
private ociClient: OciClient;

constructor(
registry: ResolvedRegistry,
registry: ResolvedGitHubRegistry,
http: HttpClient,
fs: FileSystem,
shell: ShellExecutor,
tar: TarOperations
) {
if (!registry.project) {
throw new Error(
"GitHub registry requires 'project' field in config (your GHCR namespace, e.g., 'myorg' for ghcr.io/myorg/*)"
);
}

this.host = registry.host || DEFAULT_GHCR_HOST;
this.token = registry.token;
this.prefix = registry.prefix;
Expand Down
8 changes: 2 additions & 6 deletions src/registry/clients/gitlab-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import type { HttpClient } from "#/core";
import type { ResolvedRegistry } from "../registry.types";
import type { ResolvedGitLabRegistry } from "../registry.types";
import type { RegistryBrowser, BrowseResult, BrowsedArtifact } from "../browse.types";
import { ArtifactManifestSchema } from "#/schemas";
import { parse as parseYaml } from "yaml";
Expand All @@ -34,11 +34,7 @@ export class GitLabRepositoryBrowser implements RegistryBrowser {
private token?: string;
private http: HttpClient;

constructor(registry: ResolvedRegistry, http: HttpClient) {
if (!registry.project) {
throw new Error("GitLab browser requires 'project' field in config");
}

constructor(registry: ResolvedGitLabRegistry, http: HttpClient) {
this.host = normalizeHost(registry.host);
this.encodedProject = encodeURIComponent(normalizeProject(registry.project));
this.token = registry.token;
Expand Down
Loading