gitconnect

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package gitconnect binds the current project to a GitHub repository.

The CLI never creates push credentials and never pushes: it resolves a local remote to a repository the caller's GitHub connection can already see, and asks the platform to bind it. Pushing stays the user's own `git push`.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoGitHubConnection indicates the caller has no usable GitHub
	// connection. The CLI cannot create one: the connect flow is a browser
	// redirect bound to an HttpOnly cookie, so it has to happen in the
	// dashboard.
	ErrNoGitHubConnection = errors.New("no GitHub account is connected")
	// ErrRepositoryNotAccessible indicates the repository is real as far as the
	// local remote is concerned, but the Volcano GitHub App cannot see it
	// through any of the caller's installations.
	ErrRepositoryNotAccessible = errors.New("repository is not accessible through your GitHub connection")
	// ErrProviderNotConfigured indicates the API has no GitHub App configured.
	// Local mode is the usual cause: those settings are first-party only.
	ErrProviderNotConfigured = errors.New("git provider integration is not configured on this API")
	// ErrNotConnected indicates the project has no repository bound.
	ErrNotConnected = errors.New("this project is not connected to a repository")
	// ErrBindingChanged indicates the project's binding was not what the command
	// read before it asked the user about it.
	ErrBindingChanged = errors.New("the project's repository connection changed while this command was running")
	// ErrNotAuthenticated indicates the platform rejected this CLI's own
	// credential on a Git route.
	//
	// Named for the CLI session because that is the cause the contract gives:
	// every route this flow calls documents its 401 as authentication — "Not
	// authenticated" on the connection routes, "Unauthorized - invalid or missing
	// token" on the project binding — and none documents a 401 for the stored
	// GitHub token. "The provider connection must be reconnected" is a 409, and
	// only on the import routes, which this flow never calls. So a 401 here is
	// first of all a session to renew, and reconnecting GitHub is the fallback.
	ErrNotAuthenticated = errors.New("not authenticated: your CLI session may have expired")
	// ErrProjectNotFound indicates the selected project does not exist. The
	// binding read answers 404 for this and for a project with no repository
	// connected, so the two are told apart before either is reported.
	ErrProjectNotFound = errors.New("the selected project does not exist")
)

Functions

This section is empty.

Types

type ProjectRef

type ProjectRef struct {
	ID uuid.UUID
	// Name is empty when the configuration cannot name the selected project,
	// which is what VOLCANO_PROJECT_ID pointing somewhere else looks like.
	Name string
}

ProjectRef identifies the project a command acts on. The repository comes from the working directory and the project comes from the CLI's own configuration, so the two are chosen independently and both have to be reported.

func (ProjectRef) Label

func (p ProjectRef) Label() string

Label renders the project for output: its name where one is known, and always enough to identify it.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service performs project git-connection work for the current project.

func NewService

func NewService(deps cliruntime.Deps) Service

NewService returns a git connection service.

func (Service) Connect

func (s Service) Connect(
	ctx context.Context, target Target, rootDirectory string, expected *apiclient.ProjectGitConnection,
) (*apiclient.ProjectGitConnection, error)

Connect binds the current project to a resolved repository, provided its binding is still expected — nil for a project that had none.

The bind is a full replace and names no prior state, so it overwrites whatever is bound when it arrives. Everything the caller decided rests on a read taken before resolving the repository and before any prompt, so the window is wide: three provider round-trips plus however long the user takes to answer. Within it another actor can point the project somewhere the user was never shown. Re-reading narrows that; the API has no conditional write to close it.

func (Service) DeploySettings

func (s Service) DeploySettings(ctx context.Context) (*apiclient.ProjectGitDeploySettings, error)

DeploySettings returns what a push to the production branch deploys. It is reported alongside a successful connect so the user learns straight away whether a push does anything.

func (Service) Disconnect

func (s Service) Disconnect(ctx context.Context, expected *apiclient.ProjectGitConnection) error

Disconnect removes the project's repository binding, provided it is still the one in expected. The repository itself is untouched.

The delete names no repository, so it removes whatever is bound when it arrives. Re-reading first keeps the command from deleting a binding the user was never shown — the window between reading a binding and confirming it is as long as the user takes to answer. It narrows that window rather than closing it; the API has no conditional delete to close it with.

func (Service) Project

func (s Service) Project() (ProjectRef, error)

Project returns the project these commands act on.

func (Service) Resolve

func (s Service) Resolve(ctx context.Context, repository localgit.Repository) (*Target, error)

Resolve finds the repository named by a local remote among the repos the caller's GitHub connection can reach, so the caller can confirm the binding before it is made.

func (Service) Status

Status returns the project's current connection, or ErrNotConnected when it has none. A project without a binding answers 404, which is an outcome here rather than a failure.

func (Service) WebURL

func (s Service) WebURL() (string, error)

WebURL returns the dashboard URL for the configured API, so callers can point at the page that owns a flow the CLI cannot run itself.

type Target

type Target struct {
	ConnectionID        uuid.UUID
	ConnectionLogin     string
	InstallationID      int64
	InstallationAccount string
	Repository          apiclient.GitRepository
}

Target is a resolved repository, and the connection and installation it was reached through. It is everything the bind call needs.

ConnectionLogin and InstallationAccount are carried for reporting only. The connection decides whose stored GitHub token the platform reads the repository with on every future deploy, and more than one connection can reach the same repository, so which one was picked is not something to leave unsaid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL