@coderook/cli 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,9 @@ exports.applyMerge = applyMerge;
11
11
  exports.cancelMerge = cancelMerge;
12
12
  exports.aiAccess = aiAccess;
13
13
  exports.setAiAccess = setAiAccess;
14
+ exports.updateProject = updateProject;
14
15
  exports.versions = versions;
16
+ exports.markRelease = markRelease;
15
17
  exports.issues = issues;
16
18
  exports.createIssue = createIssue;
17
19
  exports.releases = releases;
@@ -31,7 +33,7 @@ const config_js_1 = require("./config.js");
31
33
  async function call(route, options = {}) {
32
34
  const token = await (0, config_js_1.loadToken)();
33
35
  if (!token) {
34
- throw new Error("Not signed in. Run: coderook sign-in");
36
+ throw new Error("Not signed in. Run: cbx sign-in");
35
37
  }
36
38
  const response = await fetch(`${(0, config_js_1.apiOrigin)()}${route}`, {
37
39
  method: options.method ?? "GET",
@@ -48,7 +50,7 @@ async function call(route, options = {}) {
48
50
  const body = text ? JSON.parse(text) : {};
49
51
  if (!response.ok) {
50
52
  if (response.status === 401) {
51
- throw new Error("That token was not accepted. Run: coderook sign-in");
53
+ throw new Error("That token was not accepted. Run: cbx sign-in");
52
54
  }
53
55
  throw new Error(body?.error?.message ?? `${route} failed (${response.status})`);
54
56
  }
@@ -67,6 +69,7 @@ async function projects() {
67
69
  slug: String(row.slug ?? ""),
68
70
  name: String(row.displayName || row.slug || "Untitled"),
69
71
  visibility: String(row.visibility ?? "private"),
72
+ defaultBranch: String(row.defaultBranch || "main"),
70
73
  versionCount: Number(row.versionCount ?? 0),
71
74
  fileCount: Number(row.fileCount ?? 0),
72
75
  storedBytes: Number(row.storedSize ?? 0),
@@ -148,6 +151,18 @@ async function setAiAccess(repositoryId, change) {
148
151
  body: change,
149
152
  });
150
153
  }
154
+ /**
155
+ * Change what a project says about itself.
156
+ *
157
+ * The same PATCH the AI switches use, which is where these live: a handful of
158
+ * columns on the repository rather than a resource of their own.
159
+ */
160
+ async function updateProject(repositoryId, change) {
161
+ await call(`/v1/repositories/${encodeURIComponent(repositoryId)}`, {
162
+ method: "PATCH",
163
+ body: change,
164
+ });
165
+ }
151
166
  /** Every saved version of a project, newest first. */
152
167
  async function versions(repositoryId) {
153
168
  const body = await call(`/v1/repositories/${encodeURIComponent(repositoryId)}/versions`);
@@ -158,8 +173,31 @@ async function versions(repositoryId) {
158
173
  fileCount: Number(row.fileCount ?? 0),
159
174
  storedSize: Number(row.storedSize ?? row.sourceSize ?? 0),
160
175
  createdAt: String(row.createdAt ?? ""),
176
+ parentVersionIds: Array.isArray(row.parentVersionIds)
177
+ ? row.parentVersionIds.map(String)
178
+ : [],
179
+ authorName: String(row.author?.displayName ?? ""),
161
180
  }));
162
181
  }
182
+ /**
183
+ * Give a version a name, which is all a release is.
184
+ *
185
+ * Used to carry a pushed git tag across. `markRelease` on the service side is
186
+ * an update on the version row rather than a new object, so this is idempotent
187
+ * — pushing the same tag twice renames the same version to the same thing
188
+ * rather than making a second release.
189
+ */
190
+ async function markRelease(repositoryId, versionId, name, notes) {
191
+ const body = await call(`/v1/repositories/${encodeURIComponent(repositoryId)}` +
192
+ `/versions/${encodeURIComponent(versionId)}/release`,
193
+ // `call` serialises the body itself; handing it a string would send a
194
+ // JSON-encoded string where the service expects an object.
195
+ { method: "PUT", body: { name, ...(notes ? { notes } : {}) } });
196
+ return {
197
+ name: String(body.release?.name ?? name),
198
+ versionId: String(body.release?.versionId ?? versionId),
199
+ };
200
+ }
163
201
  async function issues(repositoryId) {
164
202
  const body = await call(`/v1/repositories/${encodeURIComponent(repositoryId)}/issues`);
165
203
  return {
@@ -188,6 +226,7 @@ async function createIssue(repositoryId, input) {
188
226
  async function releases(repositoryId) {
189
227
  const body = await call(`/v1/repositories/${encodeURIComponent(repositoryId)}/releases`);
190
228
  return (body.releases ?? []).map((row) => ({
229
+ versionId: String(row.versionId ?? ""),
191
230
  sequence: Number(row.sequence ?? 0),
192
231
  name: String(row.name ?? ""),
193
232
  notes: String(row.notes ?? ""),