gitbridge

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitbridge connects vx to git hosts. It imports upstream branches as changesets and exports effort changes as git commits on vx/ branches.

Each repo has a bare git mirror under the data directory. Imports fetch only the branch in use, shallow at first, and map git objects to vx objects in Postgres so later imports skip everything that did not change.

Index

Constants

View Source
const (
	GitLabURL       = "https://gitlab.com"
	BitbucketURL    = "https://bitbucket.org"
	BitbucketAPIURL = "https://api.bitbucket.org/2.0"
)

Default host addresses.

View Source
const BranchPrefix = "vx/"

BranchPrefix is the only namespace vx ever pushes to.

Variables

View Source
var ErrBranchNotFound = errors.New("branch not found on the remote")

ErrBranchNotFound is returned when the remote has no such branch.

Functions

This section is empty.

Types

type Bridge

type Bridge struct {
	Store *store.Store
	Blobs blob.Store
	Dir   string // root for bare mirrors
	// GitHubToken returns a token for github.com, or "" for anonymous access.
	GitHubToken func() string
	// RepoToken returns a token for one GitHub repository (a GitHub App
	// installation token), or "" to fall back to GitHubToken. nil: only
	// GitHubToken is used.
	RepoToken func(ctx context.Context, repo store.Repo) (string, error)
	// GitHubAPI is the REST API base URL (tests point it at a fake).
	GitHubAPI string
	// GitHubGitBase is the base URL for git over HTTPS (tests override it).
	GitHubGitBase string
	// Hosts configures GitLab, Gitea, Forgejo and Bitbucket (hosts.go).
	Hosts map[store.Provider]HostConfig
	// HostToken returns the token kept for one GitLab, Gitea, Forgejo or
	// Bitbucket repository, or "" to use the server's token for its host.
	HostToken func(ctx context.Context, repo store.Repo) (string, error)
	// FirstDepth is how many commits the first import of a branch fetches.
	FirstDepth int
	// SyncDepth bounds how many new commits one sync imports.
	SyncDepth int
	Log       *slog.Logger
	// contains filtered or unexported fields
}

Bridge imports from and exports to git remotes.

func New

func New(st *store.Store, blobs blob.Store, dir string, githubToken func() string) *Bridge

New returns a bridge with defaults.

func (*Bridge) DefaultBranch

func (b *Bridge) DefaultBranch(ctx context.Context, repo store.Repo) (string, error)

DefaultBranch asks the remote which branch HEAD points to.

func (*Bridge) ExportBranch

func (b *Bridge) ExportBranch(ctx context.Context, repo store.Repo, baseSHA, branch string, commits []provider.Commit) ([]string, error)

ExportBranch writes commits on top of the git commit baseSHA and pushes them to branch, which must start with "vx/". It returns the git SHA of every commit, oldest first.

func (*Bridge) FindPullRequest added in v0.4.0

func (b *Bridge) FindPullRequest(ctx context.Context, repo store.Repo, head string) (provider.PRInfo, error)

FindPullRequest returns the newest open pull request (GitLab: merge request) from head, or provider.ErrNotFound.

func (*Bridge) HostURL added in v0.4.0

func (b *Bridge) HostURL(p store.Provider) string

HostURL is the address repositories of p default to, or "".

func (*Bridge) OpenPullRequest

func (b *Bridge) OpenPullRequest(ctx context.Context, repo store.Repo, pr provider.PullRequest) (provider.OpenedPR, error)

OpenPullRequest opens a PR (GitLab: merge request) for head, or updates the open one: title, body and base, so a stacked PR can be retargeted.

func (*Bridge) PullRequest added in v0.4.0

func (b *Bridge) PullRequest(ctx context.Context, repo store.Repo, number int) (provider.PRInfo, error)

PullRequest reads one pull request (GitLab: merge request iid).

func (*Bridge) SetHost added in v0.4.0

func (b *Bridge) SetHost(p store.Provider, cfg HostConfig)

SetHost configures one kind of host; empty fields keep the defaults.

func (*Bridge) SyncBranch

func (b *Bridge) SyncBranch(ctx context.Context, repo store.Repo, branch string) (store.Branch, int, error)

SyncBranch fetches branch and imports its new first-parent commits.

func (*Bridge) UseHostTokens added in v0.4.0

func (b *Bridge) UseHostTokens(f func(ctx context.Context, repo store.Repo) (string, error))

UseHostTokens sets HostToken; the server passes the tokens it keeps per repository this way.

func (*Bridge) UseRepoTokens added in v0.2.0

func (b *Bridge) UseRepoTokens(f func(ctx context.Context, repo store.Repo) (string, error))

UseRepoTokens sets RepoToken; the server passes the GitHub App's installation tokens this way.

type HostConfig added in v0.4.0

type HostConfig struct {
	// URL is the host's web address repositories default to, e.g.
	// https://gitlab.com; empty: every repository names its own.
	URL string
	// APIURL overrides the API address for repositories on URL; empty:
	// derived from the repository's address (GitLab /api/v4, Gitea and
	// Forgejo /api/v1, Bitbucket https://api.bitbucket.org/2.0).
	APIURL string
	// Token is the server's token for repositories on URL ("" for none).
	// It is never sent to another address: a repository elsewhere needs
	// its own token.
	Token func() string
}

HostConfig is the server's configuration for one kind of host.

Directories

Path Synopsis
Package hosttest fakes the pull request APIs of GitLab (REST v4), Gitea and Forgejo (/api/v1) and Bitbucket Cloud (2.0) for one repository, and optionally serves git over HTTP for it (git http-backend), so tests never call a real host.
Package hosttest fakes the pull request APIs of GitLab (REST v4), Gitea and Forgejo (/api/v1) and Bitbucket Cloud (2.0) for one repository, and optionally serves git over HTTP for it (git http-backend), so tests never call a real host.

Jump to

Keyboard shortcuts

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