Skip to content

✨ feat(cli): add GIT managment - #395

Draft
vincent-psarga wants to merge 13 commits into
mainfrom
feat/cli-manage-git
Draft

✨ feat(cli): add GIT managment #395
vincent-psarga wants to merge 13 commits into
mainfrom
feat/cli-manage-git

Conversation

@vincent-psarga

Copy link
Copy Markdown
Contributor

Introduce a set of gitsubcommands to manage git providers (called connection, like in the app) and repos.

Could be a first step to manage marketplaces from the cli

Introduce a `git` command group with a `connection list` subcommand that
lists the organization's git providers via the existing
GET /organizations/:orgId/git/providers endpoint.

Wires a new GitGateway into PackmindGateway and exposes
listGitConnections() on the CLI facade.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds CLI commands for administering Git connections and repositories, restricts provider/repository creation to organization administrators, and changes distribution tracking to use repositories configured beforehand.

  • Adds git connection list/add and git repo list/add CLI command groups with API gateway integration and documentation.
  • Maps organization-admin authorization failures to HTTP 403 responses and user-facing CLI messages.
  • Stops distribution notifications from implicitly provisioning Git providers or repositories, returning nullable deployment identifiers when no configured repository matches.
  • Updates unit, integration, CLI end-to-end, and application end-to-end coverage for the new workflows.

Confidence Score: 5/5

The pull request appears safe to merge because no blocking failure eligible for this follow-up review remains.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/cli/src/infra/commands/git/addGitRepoHandler.ts Adds repository parsing, default-branch discovery, repository creation, and permission-aware error reporting.
apps/cli/src/infra/repositories/GitGateway.ts Adds the CLI HTTP adapter for listing and creating Git providers and repositories.
apps/api/src/app/organizations/git/providers/git-providers.controller.ts Maps organization-admin authorization failures from provider and repository creation to HTTP 403.
apps/api/src/app/organizations/git/repositories/git-repositories.controller.ts Maps organization-admin authorization failures during repository creation to HTTP 403.
packages/git/src/application/useCases/addGitProvider/AddGitProviderUseCase.ts Changes Git provider creation from member-authorized to administrator-authorized execution.
packages/git/src/application/useCases/addGitRepo/AddGitRepoUseCase.ts Changes managed-repository creation from member-authorized to administrator-authorized execution.
packages/deployments/src/application/services/TargetResolutionService.ts Resolves targets only from repositories configured beforehand and returns null when none matches.
packages/deployments/src/application/useCases/notifyDistribution/NotifyDistributionUseCase.ts Skips recording a distribution and returns a null deployment identifier when target resolution finds no configured repository.
packages/deployments/src/application/useCases/notifyArtefactsDistribution/NotifyArtefactsDistributionUseCase.ts Applies nullable target handling to artifact-distribution notifications.

Sequence Diagram

sequenceDiagram
  participant User
  participant CLI
  participant API
  participant Git as Git domain
  participant Deployments
  User->>CLI: git connection/repo command
  CLI->>API: Organization-scoped request
  API->>Git: List or administer provider/repository
  Git-->>API: Connection/repository result
  API-->>CLI: HTTP response
  CLI-->>User: Formatted result
  User->>CLI: Install/render and notify distribution
  CLI->>API: Distribution notification
  API->>Deployments: Resolve configured repository and target
  alt Repository is configured
    Deployments-->>API: Recorded deployment ID
  else Repository is not configured
    Deployments-->>API: Null deployment ID
  end
Loading

Reviews (5): Last reviewed commit: "✅ test(e2e): track repo before asserting..." | Re-trigger Greptile

vincent-psarga and others added 12 commits July 24, 2026 15:34
Add a `git connection add <token> --displayName --type --url` subcommand
that creates a token-authenticated git provider via
PUT /organizations/:orgId/git/providers.

The --type option accepts github or gitlab; --url is optional for
provider.com hosts and required for self-hosted instances.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a `git repo list --connectionId` subcommand listing the repositories
managed under a connection. The `--show-available` flag instead lists the
repositories that can be managed (paginated via `--page`), sourced from
the provider's available-repos endpoint.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a `git repo add <owner/repo> --connectionId [--branch]` subcommand
that manages a repository under a connection via
POST /organizations/:orgId/git/repositories.

When --branch is omitted, the default branch is resolved by scanning the
connection's available repositories; the command asks for --branch if the
repo cannot be located.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Exercise the new `git connection list/add` and `git repo list/add`
commands end-to-end against a real CLI binary and API: the unauthenticated
guard, the empty-connection listing, connection creation, and managing a
repository under the created connection.

Adds a read-only git gateway to the e2e helpers to resolve the created
provider id for the repo commands.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a "Git Command" section to the CLI reference covering
`git connection list/add` and `git repo list/add`, and cross-link it with
the Git Repository Connection governance guide.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Distribution recording no longer provisions a git provider or repo on the
fly. TargetResolutionService now finds an existing repo (never creates one)
and only creates the target under it; when no repo has been set up for the
remote, it returns null.

The notify use cases skip recording and return `deploymentId: null` in that
case, and plugin render skips its distribution record. This makes
distribution tracking depend on a repository being set up beforehand (an
admin-only step via `track` or Git settings) instead of implicitly creating
tokenless providers/repos on install.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
AddGitProviderUseCase and AddGitRepoUseCase now extend AbstractAdminUseCase,
so creating a git provider or repository requires an organization admin and
throws OrganizationAdminRequiredError otherwise.

This is safe now that distribution recording no longer auto-provisions repos
on notify — the admin-gated tracking flows still create repos in admin
context. Note this also gates the GitHub App install callback and the UI/CLI
repo-add paths, which all funnel through these use cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Map OrganizationAdminRequiredError to a 403 Forbidden in the add-provider
and add-repository controllers (previously it surfaced as a 500), and show a
clear message in the CLI when the user is not an organization admin:
"You need to be an organization administrator to add a git connection." /
"...to manage a repository." instead of the raw server error.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Document that `git connection add` and `git repo add` require an
organization admin, and add a troubleshooting entry for the permission
error.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Distribution recording now only happens for a repository set up beforehand
(admin-only, via `track`); rendering no longer provisions a repo on the fly.
Move the plugin distribution-tracking tests into their own suite that signs
up with a packmind.com email (for the `cli-repo-tracking` flag), runs `track`
before rendering, and is gated to `> 0.31.0` so older production CLIs skip it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`notifyDistribution` no longer auto-provisions a tokenless provider/repo, so
the install distribution spec now sets up a tracked repository first. Add a
`setTrackedRepository` gateway to the Playwright API fixture and run the suite
under the `cli-repo-tracking` feature flag so the distribution and CLI-managed
provider assertions hold under the new existing-repo-only behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@vincent-psarga
vincent-psarga marked this pull request as draft July 28, 2026 12:44

logConsole('\nGit connections:\n');
const sorted = [...connections].sort((a, b) =>
a.displayName.localeCompare(b.displayName),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is displayName mandatory or optional?
If 2), is there any risk it'd fail at runtime ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants