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
- Variables
- type Bridge
- func (b *Bridge) DefaultBranch(ctx context.Context, repo store.Repo) (string, error)
- func (b *Bridge) ExportBranch(ctx context.Context, repo store.Repo, baseSHA, branch string, ...) ([]string, error)
- func (b *Bridge) FindPullRequest(ctx context.Context, repo store.Repo, head string) (provider.PRInfo, error)
- func (b *Bridge) HostURL(p store.Provider) string
- func (b *Bridge) OpenPullRequest(ctx context.Context, repo store.Repo, pr provider.PullRequest) (provider.OpenedPR, error)
- func (b *Bridge) PullRequest(ctx context.Context, repo store.Repo, number int) (provider.PRInfo, error)
- func (b *Bridge) SetHost(p store.Provider, cfg HostConfig)
- func (b *Bridge) SyncBranch(ctx context.Context, repo store.Repo, branch string) (store.Branch, int, error)
- func (b *Bridge) UseHostTokens(f func(ctx context.Context, repo store.Repo) (string, error))
- func (b *Bridge) UseRepoTokens(f func(ctx context.Context, repo store.Repo) (string, error))
- type HostConfig
Constants ¶
const ( GitLabURL = "https://gitlab.com" BitbucketURL = "https://bitbucket.org" BitbucketAPIURL = "https://api.bitbucket.org/2.0" )
Default host addresses.
const BranchPrefix = "vx/"
BranchPrefix is the only namespace vx ever pushes to.
Variables ¶
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 (*Bridge) DefaultBranch ¶
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
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
UseHostTokens sets HostToken; the server passes the tokens it keeps per repository 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.
Source Files
¶
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. |