Skip to content

An open-source, faster Devin alternative

TypeScript

opencomputer push: the organization's automations repository (work 067)

Mohamed Habib via Computer377bb9c0194b
diff --git a/cli/src/api.ts b/cli/src/api.ts
index c66eadb4..2b1bf99d 100644
--- a/cli/src/api.ts
+++ b/cli/src/api.ts
@@ -1,6 +1,6 @@
import { createHash } from "node:crypto";
-import type { ProjectRepositoryCredential } from "./push.js";
+import type { AutomationsRepositoryCredential } from "./push.js";
import type { ResolvedConfig } from "./config.js";
import type { MemoryDeclaration, ProjectResourceManifest } from "./project.js";
@@ -662,9 +662,9 @@ export class OpenComputerClient {
}
/** A one-hour push credential for the project's automation repository (work 067). */
- projectRepositoryCredential(projectId: string) {
- return this.request<ProjectRepositoryCredential>(
- `/api/managed-agents/projects/${encodeURIComponent(projectId)}/repository/credentials`,
+ automationsRepositoryCredential() {
+ return this.request<AutomationsRepositoryCredential>(
+ "/api/managed-agents/automations/repository/credentials",
{ method: "POST" },
);
}
diff --git a/cli/src/commands.ts b/cli/src/commands.ts
index 91913a4a..534b0f7c 100644
--- a/cli/src/commands.ts
+++ b/cli/src/commands.ts
@@ -73,7 +73,7 @@ import {
materializeTemplateCheckout,
} from "./template-local.js";
import { materializeProjectArchive } from "./project-local.js";
-import { pushToProjectRepository } from "./push.js";
+import { pushToAutomationsRepository } from "./push.js";
import { spawnSync } from "node:child_process";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
@@ -1005,25 +1005,15 @@ export async function runCommand(
}
if (command === "push") {
- const projectReference = option(args, "--project");
const ref = args.shift();
- if (args.length) {
- throw new Error("Usage: opencomputer push [<ref>] [--project <id|slug>]");
- }
- const root = await findOpenComputerProjectRoot(process.cwd());
- const projectId = projectReference
- ? (
- (await client.projects()).find(
- (candidate) =>
- candidate.id === projectReference ||
- candidate.slug === projectReference,
- ) ?? { id: undefined }
- ).id
- : (await ensureProjectBinding(client, config, root)).projectId;
- if (!projectId) throw new Error(`Project ${projectReference} was not found.`);
- const credential = await client.projectRepositoryCredential(projectId);
- pushToProjectRepository({ credential, directory: root, ...(ref ? { ref } : {}) });
- if (globals.json) printJSON({ projectId, remoteUrl: credential.remoteUrl });
+ if (args.length) throw new Error("Usage: opencomputer push [<ref>]");
+ const credential = await client.automationsRepositoryCredential();
+ pushToAutomationsRepository({
+ credential,
+ directory: process.cwd(),
+ ...(ref ? { ref } : {}),
+ });
+ if (globals.json) printJSON({ remoteUrl: credential.remoteUrl });
else process.stdout.write(`Pushed to ${credential.remoteUrl}\n`);
return;
}
diff --git a/cli/src/index.ts b/cli/src/index.ts
index c59ac305..20e441d5 100644
--- a/cli/src/index.ts
+++ b/cli/src/index.ts
@@ -56,7 +56,7 @@ Usage:
opencomputer template deploy <repository-url> [--project-name <name>] [--directory <path>] [--refresh]
opencomputer template clone <repository-url> --commit <sha> --project <id> [--directory <path>]
opencomputer project clone <project-id> [--directory <path>]
- opencomputer push [<ref>] [--project <id|slug>]
+ opencomputer push [<ref>]
opencomputer link (--project <id|slug> | --create-project <name>)
opencomputer doctor
opencomputer deploy --watch [--project <id|slug> | --create-project <name>]
diff --git a/cli/src/push.test.ts b/cli/src/push.test.ts
index 08e5019a..d09a193f 100644
--- a/cli/src/push.test.ts
+++ b/cli/src/push.test.ts
@@ -4,10 +4,10 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import assert from "node:assert/strict";
import { test } from "node:test";
-import { gitPushEnvironment, pushToProjectRepository } from "./push.js";
+import { gitPushEnvironment, pushToAutomationsRepository } from "./push.js";
const credential = {
- remoteUrl: "https://acme.code.storage/automation-prj_1.git",
+ remoteUrl: "https://acme.code.storage/automations-acct.git",
username: "t",
password: "jwt",
expiresAt: "2026-10-16T02:00:00.000Z",
@@ -46,14 +46,14 @@ test("pushes HEAD to main and refuses to drop commits already there", () => {
return directory;
};
const computer = work("computer");
- pushToProjectRepository({ credential: local, directory: computer });
+ pushToAutomationsRepository({ credential: local, directory: computer });
assert.equal(
git(remote, "rev-parse", "main"),
git(computer, "rev-parse", "HEAD"),
);
assert.throws(
() =>
- pushToProjectRepository({ credential: local, directory: work("laptop") }),
+ pushToAutomationsRepository({ credential: local, directory: work("laptop") }),
/fetch and merge/,
);
});
diff --git a/cli/src/push.ts b/cli/src/push.ts
index ba04a7cd..545f2a37 100644
--- a/cli/src/push.ts
+++ b/cli/src/push.ts
@@ -1,7 +1,7 @@
import { spawnSync } from "node:child_process";
-/** A one-hour push credential for a project's automation repository (work 067). */
-export interface ProjectRepositoryCredential {
+/** A one-hour push credential for the organization's automations repository (work 067). */
+export interface AutomationsRepositoryCredential {
remoteUrl: string;
username: string;
password: string;
@@ -14,7 +14,7 @@ export interface ProjectRepositoryCredential {
* config file.
*/
export function gitPushEnvironment(
- credential: ProjectRepositoryCredential,
+ credential: AutomationsRepositoryCredential,
): Record<string, string> {
const authorization = Buffer.from(
`${credential.username}:${credential.password}`,
@@ -29,11 +29,11 @@ export function gitPushEnvironment(
/**
* Pushes `ref` (HEAD by default) of the git repository at `directory` to the
- * automation repository's `main`. Git refuses a push that would drop commits
+ * automations repository's `main`. Git refuses a push that would drop commits
* already there, so a person and the computer cannot overwrite each other.
*/
-export function pushToProjectRepository(input: {
- credential: ProjectRepositoryCredential;
+export function pushToAutomationsRepository(input: {
+ credential: AutomationsRepositoryCredential;
directory: string;
ref?: string;
}): void {
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.ts
index 19703bc5..71c6181d 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts
@@ -359,14 +359,14 @@ describe("managed agents proxy", () => {
).resolves.toBe(true);
});
- it("passes a project repository credential through uncached", async () => {
+ it("passes an automations repository credential through uncached", async () => {
const fetchSpy = vi.fn(async (target: RequestInfo | URL, init?: RequestInit) => {
expect(String(target)).toBe(
- "https://managedagents.test/v1/projects/prj_test/repository/credentials",
+ "https://managedagents.test/v1/automations/repository/credentials",
);
expect(init?.method).toBe("POST");
return Response.json({
- remoteUrl: "https://acme.code.storage/automation-prj_test.git",
+ remoteUrl: "https://acme.code.storage/automations-org_test.git",
username: "t",
password: "jwt",
expiresAt: "2026-10-16T02:00:00.000Z",
@@ -377,7 +377,7 @@ describe("managed agents proxy", () => {
const response = await proxyManagedAgents(
new Request(
- "https://mo-oc-dev.com/api/managed-agents/projects/prj_test/repository/credentials",
+ "https://mo-oc-dev.com/api/managed-agents/automations/repository/credentials",
{ method: "POST" },
),
{
@@ -391,7 +391,7 @@ describe("managed agents proxy", () => {
expect(response.status).toBe(200);
expect(response.headers.get("cache-control")).toBe("no-store");
expect(await response.json()).toEqual({
- remoteUrl: "https://acme.code.storage/automation-prj_test.git",
+ remoteUrl: "https://acme.code.storage/automations-org_test.git",
username: "t",
password: "jwt",
expiresAt: "2026-10-16T02:00:00.000Z",
diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.ts
index 5392a155..7ad88a7b 100644
--- a/cloudflare-workers/api-edge/src/managed_agents.ts
+++ b/cloudflare-workers/api-edge/src/managed_agents.ts
@@ -2337,9 +2337,9 @@ function publicSuccessBody(
}
return { url: url.toString(), expiresAt: body.expiresAt };
}
- if (method === "POST" && PROJECT_REPOSITORY_CREDENTIAL_ROUTE.test(suffix)) {
- // A one-hour push credential for the project's automation repository
- // (work 067): the remote carries no credential of its own.
+ if (method === "POST" && AUTOMATIONS_REPOSITORY_CREDENTIAL_ROUTE.test(suffix)) {
+ // A one-hour push credential for the organization's automations
+ // repository (work 067): the remote carries no credential of its own.
const remote =
typeof body.remoteUrl === "string" ? new URL(body.remoteUrl) : null;
if (
@@ -2351,7 +2351,7 @@ function publicSuccessBody(
typeof body.password !== "string" ||
typeof body.expiresAt !== "string"
) {
- throw new Error("Invalid project repository credential");
+ throw new Error("Invalid automations repository credential");
}
return {
remoteUrl: remote.toString(),
@@ -2363,8 +2363,8 @@ function publicSuccessBody(
throw new Error("Unsupported managed agents response");
}
-const PROJECT_REPOSITORY_CREDENTIAL_ROUTE =
- /^\/projects\/[^/]+\/repository\/credentials$/;
+const AUTOMATIONS_REPOSITORY_CREDENTIAL_ROUTE =
+ /^\/automations\/repository\/credentials$/;
function publicWorkspaceFile(value: unknown): Record<string, unknown> {
const file = record(value) ?? {};
@@ -2476,7 +2476,7 @@ async function publicSuccessResponse(
suffix.includes("/event-subscriptions") ||
suffix.startsWith("/channels/slack/setups") ||
isLinearRouteSuffix(suffix) ||
- PROJECT_REPOSITORY_CREDENTIAL_ROUTE.test(suffix)
+ AUTOMATIONS_REPOSITORY_CREDENTIAL_ROUTE.test(suffix)
) {
headers.set("cache-control", "no-store");
}
@@ -2718,7 +2718,7 @@ function isAllowedManagedAgentsRoute(method: string, suffix: string): boolean {
if (method === "GET" && /^\/projects\/[^/]+\/source-archive$/.test(suffix)) {
return true;
}
- if (method === "POST" && PROJECT_REPOSITORY_CREDENTIAL_ROUTE.test(suffix)) {
+ if (method === "POST" && AUTOMATIONS_REPOSITORY_CREDENTIAL_ROUTE.test(suffix)) {
return true;
}
if (