Skip to content

Commit 80b4cbf

Browse files
refactor(cli): fold GitHub account connect into the existing git group
Replaces the separate github command group with three subcommands under the existing git group, so all GitHub functionality lives in one place: git accounts (list connected + connectable), git connect-account (connect an already-installed account from another workspace), git install (install link). git connect/disconnect keep owning the repo-to-project link. Reuses the existing source-repository API seam and install-intent helper; error codes are GIT_ACCOUNT_REQUIRED / GIT_ACCOUNT_NOT_FOUND / GIT_CONNECT_FAILED.
1 parent 3f65382 commit 80b4cbf

15 files changed

Lines changed: 575 additions & 695 deletions

File tree

docs/product/command-spec.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -894,61 +894,65 @@ prisma-cli git disconnect --project proj_123
894894
prisma-cli git disconnect --json
895895
```
896896

897-
## `prisma-cli github list`
897+
## `prisma-cli git accounts`
898898

899899
Purpose:
900900

901-
- show the active workspace's GitHub connection state
901+
- show the active workspace's GitHub account connections
902902

903903
Behavior:
904904

905+
- requires auth
905906
- lists GitHub accounts connected to the active workspace (login, account type, numeric installation id, suspension state)
906907
- lists accounts connectable without a GitHub round trip: installations of other workspaces the user belongs to, deduplicated per GitHub account with the newest installation winning
907-
- suggests `github connect <account>` as a next step when connectable accounts exist
908+
- suggests `git connect-account <account>` as a next step when connectable accounts exist
908909

909910
Examples:
910911

911912
```bash
912-
prisma-cli github list
913-
prisma-cli github list --json
913+
prisma-cli git accounts
914+
prisma-cli git accounts --json
914915
```
915916

916-
## `prisma-cli github connect [account]`
917+
## `prisma-cli git connect-account [account]`
917918

918919
Purpose:
919920

920-
- connect a GitHub account that already has the Prisma GitHub App installed to the active workspace, without a GitHub round trip
921+
- connect a GitHub account that already has the Prisma GitHub App installed (via another workspace) to the active workspace, without a GitHub round trip
921922

922923
Behavior:
923924

925+
- requires auth
924926
- resolves `[account]` by login or numeric installation id among the connectable accounts
925-
- without `[account]`, fails with `GITHUB_ACCOUNT_REQUIRED`; the connectable accounts are listed in `error.meta.connectable` and as runnable next steps, so agents can pick without prompting
926-
- an unknown account fails with `GITHUB_ACCOUNT_NOT_FOUND` and the same machine-readable options
927-
- authorization is enforced by the platform: the user must be a member of a workspace the installation is already actively connected to
928-
- if GitHub reports the installation gone, fails with `GITHUB_CONNECT_FAILED` after the platform cleans up its stale records
927+
- without `[account]`, fails with `GIT_ACCOUNT_REQUIRED`; the connectable accounts are listed in `error.meta.connectable` and as runnable next steps, so agents can pick without prompting
928+
- an unknown account fails with `GIT_ACCOUNT_NOT_FOUND` and the same machine-readable options
929+
- authorization is enforced by the platform: a full user session whose user is a member of a workspace the installation is already actively connected to
930+
- if GitHub reports the installation gone, fails with `GIT_CONNECT_FAILED` after the platform cleans up its stale records
931+
- this is the account-level connection; link a repository to a project with `git connect`
929932

930933
Examples:
931934

932935
```bash
933-
prisma-cli github connect acme-org
934-
prisma-cli github connect 555003
936+
prisma-cli git connect-account acme-org
937+
prisma-cli git connect-account 555003
935938
```
936939

937-
## `prisma-cli github install`
940+
## `prisma-cli git install`
938941

939942
Purpose:
940943

941-
- get the GitHub App install link for connecting a brand-new GitHub account
944+
- get the Prisma GitHub App install link for a brand-new GitHub account
942945

943946
Behavior:
944947

948+
- requires auth
945949
- prints a single-use, time-limited install URL bound to the active workspace
946-
- the install completes in the browser; the Console callback finishes the connection
950+
- the install completes in the browser; then connect a repository with `git connect`
947951

948952
Examples:
949953

950954
```bash
951-
prisma-cli github install
955+
prisma-cli git install
952956
```
953957

954958
## `prisma-cli branch list`

docs/product/error-conventions.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,9 @@ These codes are the minimum stable set for the MVP:
181181
- `LOCAL_STATE_WRITE_FAILED`
182182
- `LOCAL_STATE_STALE`
183183
- `BRANCH_NOT_DEPLOYABLE`
184-
- `GITHUB_ACCOUNT_REQUIRED`
185-
- `GITHUB_ACCOUNT_NOT_FOUND`
186-
- `GITHUB_CONNECT_FAILED`
187-
- `GITHUB_API_ERROR`
184+
- `GIT_ACCOUNT_REQUIRED`
185+
- `GIT_ACCOUNT_NOT_FOUND`
186+
- `GIT_CONNECT_FAILED`
188187
- `COMPUTE_CONFIG_INVALID`
189188
- `COMPUTE_CONFIG_TARGET_REQUIRED`
190189
- `COMPUTE_CONFIG_TARGET_UNKNOWN`
@@ -258,10 +257,9 @@ Recommended meanings:
258257
- `LOCAL_STATE_WRITE_FAILED`: the CLI could not save local Project binding state such as `.prisma/local.json` or the matching `.gitignore` entry; callers should fix directory permissions or filesystem state before retrying
259258
- `LOCAL_STATE_STALE`: local Project pin no longer matches platform data and continuing would be ambiguous
260259
- `BRANCH_NOT_DEPLOYABLE`: command tried to deploy to a non-deployable branch context
261-
- `GITHUB_ACCOUNT_REQUIRED`: `github connect` needs a GitHub account argument; connectable accounts are listed in `error.meta.connectable` and as next steps
262-
- `GITHUB_ACCOUNT_NOT_FOUND`: the requested GitHub account is not connectable to the active workspace
263-
- `GITHUB_CONNECT_FAILED`: GitHub reports the installation no longer exists; stale platform records were cleaned up
264-
- `GITHUB_API_ERROR`: a GitHub-related Management API request failed without a more specific CLI error code
260+
- `GIT_ACCOUNT_REQUIRED`: `git connect-account` needs a GitHub account argument; connectable accounts are listed in `error.meta.connectable` and as next steps
261+
- `GIT_ACCOUNT_NOT_FOUND`: the requested GitHub account is not connectable to the active workspace
262+
- `GIT_CONNECT_FAILED`: GitHub reports the installation no longer exists; stale platform records were cleaned up
265263
- `COMPUTE_CONFIG_INVALID`: `prisma.compute.ts` failed to load or validate
266264
- `COMPUTE_CONFIG_TARGET_REQUIRED`: a multi-app compute config needs an `[app]` target and none was given or inferred
267265
- `COMPUTE_CONFIG_TARGET_UNKNOWN`: the `[app]` target matches no configured app

packages/cli/src/cli.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { createBranchCommand } from "./commands/branch";
99
import { createBuildCommand } from "./commands/build";
1010
import { createDatabaseCommand } from "./commands/database";
1111
import { createGitCommand } from "./commands/git";
12-
import { createGithubCommand } from "./commands/github";
1312
import { createInitCommand } from "./commands/init";
1413
import { createProjectCommand } from "./commands/project";
1514
import { createVersionCommand } from "./commands/version";
@@ -91,7 +90,6 @@ export function createProgram(runtime: CliRuntime): Command {
9190
program.addCommand(createProjectCommand(runtime));
9291
program.addCommand(createGitCommand(runtime));
9392
program.addCommand(createBranchCommand(runtime));
94-
program.addCommand(createGithubCommand(runtime));
9593
program.addCommand(createBuildCommand(runtime));
9694
program.addCommand(createDatabaseCommand(runtime));
9795
program.addCommand(createAppCommand(runtime));

packages/cli/src/commands/git/index.ts

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import { Command } from "commander";
22

3-
import { runGitConnect, runGitDisconnect } from "../../controllers/project";
43
import {
4+
runGitAccounts,
5+
runGitConnect,
6+
runGitConnectAccount,
7+
runGitDisconnect,
8+
runGitInstall,
9+
} from "../../controllers/project";
10+
import {
11+
renderGitAccounts,
512
renderGitConnect,
13+
renderGitConnectAccount,
614
renderGitDisconnect,
15+
renderGitInstall,
16+
serializeGitAccounts,
17+
serializeGitConnectAccount,
18+
serializeGitInstall,
719
} from "../../presenters/project";
820
import { attachCommandDescriptor } from "../../shell/command-meta";
921
import { runCommand } from "../../shell/command-runner";
@@ -12,7 +24,12 @@ import {
1224
addGlobalFlags,
1325
} from "../../shell/global-flags";
1426
import { type CliRuntime, configureRuntimeCommand } from "../../shell/runtime";
15-
import type { ProjectRepositoryConnectionResult } from "../../types/project";
27+
import type {
28+
GitAccountsResult,
29+
GitConnectAccountResult,
30+
GitInstallResult,
31+
ProjectRepositoryConnectionResult,
32+
} from "../../types/project";
1633

1734
export function createGitCommand(runtime: CliRuntime): Command {
1835
const git = attachCommandDescriptor(
@@ -24,6 +41,9 @@ export function createGitCommand(runtime: CliRuntime): Command {
2441

2542
git.addCommand(createGitConnectCommand(runtime));
2643
git.addCommand(createGitDisconnectCommand(runtime));
44+
git.addCommand(createGitAccountsCommand(runtime));
45+
git.addCommand(createGitConnectAccountCommand(runtime));
46+
git.addCommand(createGitInstallCommand(runtime));
2747

2848
return git;
2949
}
@@ -86,3 +106,82 @@ function createGitDisconnectCommand(runtime: CliRuntime): Command {
86106

87107
return command;
88108
}
109+
110+
function createGitAccountsCommand(runtime: CliRuntime): Command {
111+
const command = attachCommandDescriptor(
112+
configureRuntimeCommand(new Command("accounts"), runtime),
113+
"git.accounts",
114+
);
115+
116+
addGlobalFlags(command);
117+
118+
command.action(async (options) => {
119+
await runCommand<GitAccountsResult>(
120+
runtime,
121+
"git.accounts",
122+
options as Record<string, unknown>,
123+
(context) => runGitAccounts(context),
124+
{
125+
renderHuman: (context, descriptor, result) =>
126+
renderGitAccounts(context, descriptor, result),
127+
renderJson: (result) => serializeGitAccounts(result),
128+
},
129+
);
130+
});
131+
132+
return command;
133+
}
134+
135+
function createGitConnectAccountCommand(runtime: CliRuntime): Command {
136+
const command = attachCommandDescriptor(
137+
configureRuntimeCommand(new Command("connect-account"), runtime),
138+
"git.connect-account",
139+
);
140+
141+
command.argument(
142+
"[account]",
143+
"GitHub account login or numeric installation id",
144+
);
145+
addGlobalFlags(command);
146+
147+
command.action(async (account: string | undefined, options) => {
148+
await runCommand<GitConnectAccountResult>(
149+
runtime,
150+
"git.connect-account",
151+
options as Record<string, unknown>,
152+
(context) => runGitConnectAccount(context, account),
153+
{
154+
renderHuman: (context, descriptor, result) =>
155+
renderGitConnectAccount(context, descriptor, result),
156+
renderJson: (result) => serializeGitConnectAccount(result),
157+
},
158+
);
159+
});
160+
161+
return command;
162+
}
163+
164+
function createGitInstallCommand(runtime: CliRuntime): Command {
165+
const command = attachCommandDescriptor(
166+
configureRuntimeCommand(new Command("install"), runtime),
167+
"git.install",
168+
);
169+
170+
addGlobalFlags(command);
171+
172+
command.action(async (options) => {
173+
await runCommand<GitInstallResult>(
174+
runtime,
175+
"git.install",
176+
options as Record<string, unknown>,
177+
(context) => runGitInstall(context),
178+
{
179+
renderHuman: (context, descriptor, result) =>
180+
renderGitInstall(context, descriptor, result),
181+
renderJson: (result) => serializeGitInstall(result),
182+
},
183+
);
184+
});
185+
186+
return command;
187+
}

packages/cli/src/commands/github/index.ts

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)