Update naming of project(s) to repo(s)

This commit is contained in:
Sebastian Martinez
2024-08-22 09:43:06 +02:00
parent 4fda686bad
commit cf08c83913
67 changed files with 891 additions and 921 deletions
+15 -15
View File
@@ -2,9 +2,9 @@ import type { BaseUrl } from "./lib/fetcher.js";
import type {
Blob,
DiffResponse,
Project,
ProjectListQuery,
Remote,
Repo,
RepoListQuery,
Tree,
TreeStats,
} from "./lib/project.js";
@@ -41,7 +41,7 @@ import type { ZodSchema } from "zod";
import { z, array, literal, number, object, string, union } from "zod";
import * as project from "./lib/project.js";
import * as repo from "./lib/project.js";
import { Fetcher } from "./lib/fetcher.js";
import {
nodeConfigSchema,
@@ -73,15 +73,15 @@ export type {
Merge,
Patch,
PatchState,
Project,
ProjectListQuery,
Reaction,
Remote,
Repo,
RepoListQuery,
Review,
Revision,
SeedingPolicy,
TreeStats,
Tree,
TreeStats,
Verdict,
};
@@ -156,13 +156,13 @@ export class HttpdClient {
#fetcher: Fetcher;
public baseUrl: BaseUrl;
public project: project.Client;
public repo: repo.Client;
public constructor(baseUrl: BaseUrl) {
this.baseUrl = baseUrl;
this.#fetcher = new Fetcher(this.baseUrl);
this.project = new project.Client(this.#fetcher);
this.repo = new repo.Client(this.#fetcher);
}
public changePort(port: number): void {
@@ -213,14 +213,14 @@ export class HttpdClient {
);
}
public async getPolicyById(
id: string,
public async getPolicyByRid(
rid: string,
options?: RequestOptions,
): Promise<SeedingPolicy> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `node/policies/repos/${id}`,
path: `node/policies/repos/${rid}`,
options,
},
seedingPolicySchema,
@@ -239,13 +239,13 @@ export class HttpdClient {
}
public async getNodeIdentity(
id: string,
nid: string,
options?: RequestOptions,
): Promise<NodeIdentity> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `nodes/${id}`,
path: `nodes/${nid}`,
options,
},
nodeIdentitySchema,
@@ -253,13 +253,13 @@ export class HttpdClient {
}
public async getNodeInventory(
id: string,
nid: string,
options?: RequestOptions,
): Promise<string[]> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `nodes/${id}/inventory`,
path: `nodes/${nid}/inventory`,
options,
},
array(string()),
+49 -47
View File
@@ -27,11 +27,13 @@ import {
import { issueSchema, issuesSchema } from "./project/issue.js";
import { patchSchema, patchesSchema } from "./project/patch.js";
const projectSchema = object({
id: string(),
name: string(),
description: string(),
defaultBranch: string(),
const repoSchema = object({
rid: string(),
"xyz.radicle.project": object({
name: string(),
description: string(),
defaultBranch: string(),
}),
delegates: array(object({ id: string(), alias: optional(string()) })),
head: string(),
threshold: number(),
@@ -51,9 +53,9 @@ const projectSchema = object({
}),
seeding: number(),
});
const projectsSchema = array(projectSchema);
const reposSchema = array(repoSchema);
export type Project = z.infer<typeof projectSchema>;
export type Repo = z.infer<typeof repoSchema>;
const activitySchema = object({
activity: array(number()),
@@ -116,7 +118,7 @@ const diffResponseSchema = object({
files: record(string(), diffBlobSchema),
});
export type ProjectListQuery = {
export type RepoListQuery = {
page?: number;
perPage?: number;
show?: "pinned" | "all";
@@ -130,54 +132,54 @@ export class Client {
public async getByDelegate(
delegateId: string,
query?: ProjectListQuery,
query?: RepoListQuery,
options?: RequestOptions,
): Promise<Project[]> {
): Promise<Repo[]> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `delegates/${delegateId}/projects`,
path: `delegates/${delegateId}/repos`,
query,
options,
},
projectsSchema,
reposSchema,
);
}
public async getById(id: string, options?: RequestOptions): Promise<Project> {
public async getByRid(rid: string, options?: RequestOptions): Promise<Repo> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}`,
path: `repos/${rid}`,
options,
},
projectSchema,
repoSchema,
);
}
public async getAll(
query?: ProjectListQuery,
query?: RepoListQuery,
options?: RequestOptions,
): Promise<Project[]> {
): Promise<Repo[]> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: "projects",
path: "repos",
query,
options,
},
projectsSchema,
reposSchema,
);
}
public async getActivity(
id: string,
rid: string,
options?: RequestOptions,
): Promise<Activity> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/activity`,
path: `repos/${rid}/activity`,
options,
},
activitySchema,
@@ -185,14 +187,14 @@ export class Client {
}
public async getReadme(
id: string,
rid: string,
sha: string,
options?: RequestOptions,
): Promise<Blob> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/readme/${sha}`,
path: `repos/${rid}/readme/${sha}`,
options,
},
blobSchema,
@@ -200,7 +202,7 @@ export class Client {
}
public async getBlob(
id: string,
rid: string,
sha: string,
path: string,
options?: RequestOptions,
@@ -208,7 +210,7 @@ export class Client {
const blob = await this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/blob/${sha}/${path}`,
path: `repos/${rid}/blob/${sha}/${path}`,
options,
},
blobSchema,
@@ -217,7 +219,7 @@ export class Client {
}
public async getTree(
id: string,
rid: string,
sha: string,
path?: string,
options?: RequestOptions,
@@ -225,7 +227,7 @@ export class Client {
const tree = await this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/tree/${sha}/${path ?? ""}`,
path: `repos/${rid}/tree/${sha}/${path ?? ""}`,
options,
},
treeSchema,
@@ -234,14 +236,14 @@ export class Client {
}
public async getTreeStatsBySha(
id: string,
rid: string,
sha: string,
options?: RequestOptions,
): Promise<TreeStats> {
const tree = await this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/stats/tree/${sha}`,
path: `repos/${rid}/stats/tree/${sha}`,
options,
},
treeStatsSchema,
@@ -250,13 +252,13 @@ export class Client {
}
public async getAllRemotes(
id: string,
rid: string,
options?: RequestOptions,
): Promise<Remote[]> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/remotes`,
path: `repos/${rid}/remotes`,
options,
},
remotesSchema,
@@ -264,14 +266,14 @@ export class Client {
}
public async getRemoteByPeer(
id: string,
rid: string,
peer: string,
options?: RequestOptions,
): Promise<Remote> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/remotes/${peer}`,
path: `repos/${rid}/remotes/${peer}`,
options,
},
remoteSchema,
@@ -279,7 +281,7 @@ export class Client {
}
public async getAllCommits(
id: string,
rid: string,
query?: {
parent?: string;
since?: number;
@@ -292,7 +294,7 @@ export class Client {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/commits`,
path: `repos/${rid}/commits`,
query,
options,
},
@@ -301,14 +303,14 @@ export class Client {
}
public async getCommitBySha(
id: string,
rid: string,
sha: string,
options?: RequestOptions,
): Promise<Commit> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/commits/${sha}`,
path: `repos/${rid}/commits/${sha}`,
options,
},
commitSchema,
@@ -316,7 +318,7 @@ export class Client {
}
public async getDiff(
id: string,
rid: string,
revisionBase: string,
revisionOid: string,
options?: RequestOptions,
@@ -324,7 +326,7 @@ export class Client {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/diff/${revisionBase}/${revisionOid}`,
path: `repos/${rid}/diff/${revisionBase}/${revisionOid}`,
options,
},
diffResponseSchema,
@@ -332,14 +334,14 @@ export class Client {
}
public async getIssueById(
id: string,
rid: string,
issueId: string,
options?: RequestOptions,
): Promise<Issue> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/issues/${issueId}`,
path: `repos/${rid}/issues/${issueId}`,
options,
},
issueSchema,
@@ -347,7 +349,7 @@ export class Client {
}
public async getAllIssues(
id: string,
rid: string,
query?: {
page?: number;
perPage?: number;
@@ -358,7 +360,7 @@ export class Client {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/issues`,
path: `repos/${rid}/issues`,
query,
options,
},
@@ -367,14 +369,14 @@ export class Client {
}
public async getPatchById(
id: string,
rid: string,
patchId: string,
options?: RequestOptions,
): Promise<Patch> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/patches/${patchId}`,
path: `repos/${rid}/patches/${patchId}`,
options,
},
patchSchema,
@@ -382,7 +384,7 @@ export class Client {
}
public async getAllPatches(
id: string,
rid: string,
query?: {
page?: number;
perPage?: number;
@@ -393,7 +395,7 @@ export class Client {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `projects/${id}/patches`,
path: `repos/${rid}/patches`,
query,
options,
},
+37 -40
View File
@@ -9,7 +9,7 @@ import {
sourceBrowsingRid,
} from "@tests/support/fixtures.js";
describe("project", () => {
describe("repo", () => {
const api = new HttpdClient({
hostname: "127.0.0.1",
port: defaultHttpdPort,
@@ -17,59 +17,56 @@ describe("project", () => {
});
test("#getByDelegate(delegateId)", async () => {
await api.project.getByDelegate(aliceRemote);
await api.repo.getByDelegate(aliceRemote);
});
test("#getAll()", async () => {
await api.project.getAll();
await api.repo.getAll();
});
test("#getById(id)", async () => {
await api.project.getById(sourceBrowsingRid);
test("#getByRid(rid)", async () => {
await api.repo.getByRid(sourceBrowsingRid);
});
test("#getActivity(id)", async () => {
await api.project.getActivity(sourceBrowsingRid);
test("#getActivity(rid)", async () => {
await api.repo.getActivity(sourceBrowsingRid);
});
test("#getReadme(id, sha)", async () => {
await api.project.getReadme(sourceBrowsingRid, aliceMainHead);
test("#getReadme(rid, sha)", async () => {
await api.repo.getReadme(sourceBrowsingRid, aliceMainHead);
});
test("#getBlob(id, sha, path)", async () => {
await api.project.getBlob(sourceBrowsingRid, aliceMainHead, "src/true.c");
test("#getBlob(rid, sha, path)", async () => {
await api.repo.getBlob(sourceBrowsingRid, aliceMainHead, "src/true.c");
});
test("#getTree(id, sha)", async () => {
await api.project.getTree(sourceBrowsingRid, aliceMainHead);
test("#getTree(rid, sha)", async () => {
await api.repo.getTree(sourceBrowsingRid, aliceMainHead);
});
test("#getTreeStats(id, sha)", async () => {
await api.project.getTreeStatsBySha(sourceBrowsingRid, aliceMainHead);
test("#getTreeStats(rid, sha)", async () => {
await api.repo.getTreeStatsBySha(sourceBrowsingRid, aliceMainHead);
});
test("#getTree(id, sha, path)", async () => {
await api.project.getTree(sourceBrowsingRid, aliceMainHead, "src");
test("#getTree(rid, sha, path)", async () => {
await api.repo.getTree(sourceBrowsingRid, aliceMainHead, "src");
});
test("#getAllRemotes(id)", async () => {
await api.project.getAllRemotes(sourceBrowsingRid);
test("#getAllRemotes(rid)", async () => {
await api.repo.getAllRemotes(sourceBrowsingRid);
});
test("#getRemoteByPeer(id, peer)", async () => {
await api.project.getRemoteByPeer(
sourceBrowsingRid,
aliceRemote.substring(8),
);
test("#getRemoteByPeer(rid, peer)", async () => {
await api.repo.getRemoteByPeer(sourceBrowsingRid, aliceRemote.substring(8));
});
test("#getAllCommits(id)", async () => {
await api.project.getAllCommits(sourceBrowsingRid);
test("#getAllCommits(rid)", async () => {
await api.repo.getAllCommits(sourceBrowsingRid);
});
// TODO: test since/until properly.
test("#getAllCommits(id, {parent, since, until, page, perPage})", async () => {
await api.project.getAllCommits(sourceBrowsingRid, {
test("#getAllCommits(rid, {parent, since, until, page, perPage})", async () => {
await api.repo.getAllCommits(sourceBrowsingRid, {
parent: aliceMainHead,
since: 1679065819581,
until: 1679065819590,
@@ -78,41 +75,41 @@ describe("project", () => {
});
});
test("#getCommitBySha(id, sha)", async () => {
await api.project.getCommitBySha(sourceBrowsingRid, aliceMainHead);
test("#getCommitBySha(rid, sha)", async () => {
await api.repo.getCommitBySha(sourceBrowsingRid, aliceMainHead);
});
test("#getDiff(id, revisionBase, revisionOid)", async () => {
await api.project.getDiff(
test("#getDiff(rid, revisionBase, revisionOid)", async () => {
await api.repo.getDiff(
sourceBrowsingRid,
"90f6d058ece12f75f349bc7bbe88142187fe0379",
aliceMainHead,
);
});
test("#getIssueById(id, issueId)", async () => {
await api.project.getIssueById(
test("#getIssueById(rid, issueId)", async () => {
await api.repo.getIssueById(
cobRid,
"d481fe6e562dd78129589d4738f171a8380fcb19",
);
});
test("#getAllIssues(id)", async () => {
await api.project.getAllIssues(cobRid, {
test("#getAllIssues(rid)", async () => {
await api.repo.getAllIssues(cobRid, {
page: 0,
perPage: 5,
status: "open",
});
});
test("#getPatchById(id, patchId)", async () => {
await api.project.getPatchById(
test("#getPatchByOid(rid, patchId)", async () => {
await api.repo.getPatchById(
cobRid,
"59a0821edc73630bce540596cffc7854da557365",
);
});
test("#getAllPatches(id)", async () => {
await api.project.getAllPatches(cobRid);
test("#getAllPatches(rid)", async () => {
await api.repo.getAllPatches(cobRid);
});
});
+2 -2
View File
@@ -12,7 +12,7 @@ export async function assertIssue(
) {
expect(
//@prettier-ignore looks more readable than what prettier suggests.
isMatch(await api.project.getIssueById(cobRid, oid), change),
isMatch(await api.repo.getIssueById(cobRid, oid), change),
).toBe(true);
}
@@ -23,6 +23,6 @@ export async function assertPatch(
) {
expect(
//@prettier-ignore looks more readable than what prettier suggests.
isMatch(await api.project.getPatchById(cobRid, oid), change),
isMatch(await api.repo.getPatchById(cobRid, oid), change),
).toBe(true);
}