Help us shape the future of Go! Take the 2026 Go Developer Survey

gitlab

package
v1.0.0-rc.12 Latest Latest
Warning

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

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

Documentation

Overview

Package gitlab implements the provider protocol and Git credential transport.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConfigured = errors.New("GitLab not configured")

ErrNotConfigured: no GitLab connection is set up on this AppTown. That is an ordinary state (an AppTown may keep code only on itself), so callers can tell it apart from a GitLab that is set up but failing.

Functions

func CanonicalBase

func CanonicalBase(raw string) (string, error)

CanonicalBase is the credential-free provider namespace used in durable repository identity. Ambiguous addresses are refused, not normalized across hosts, protocols or reverse-proxy mount points.

func RepositoryURL

func RepositoryURL(base, raw string) (location, projectPath string, err error)

RepositoryURL checks a clone URL against the exact provider namespace and returns its credential-free location and relative project path. A username is transport metadata; a password is never accepted or retained.

Types

type Client

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

func New

func New(base, token string) (*Client, error)

func (*Client) AccountID

func (g *Client) AccountID(ctx context.Context) (int64, error)

AccountID observes the authenticated account using this client's credential snapshot. It must not be followed by resolving a different credential for the effect it admits.

func (*Client) ArchiveProject

func (g *Client) ArchiveProject(ctx context.Context, id int64) error

ArchiveProject makes a project read-only. Unlike ArchiveRename, a refusal is returned: the token needs Owner on the project to archive it.

func (*Client) ArchiveRename

func (g *Client) ArchiveRename(ctx context.Context, pathNS, newPath string) error

ArchiveRename frees the original path and archives the renamed remote. Archive failure is logged after a successful rename.

func (*Client) AskpassEnv

func (g *Client) AskpassEnv(dataDir string) ([]string, error)

AskpassEnv keeps the token out of Git configuration. The helper is published atomically so concurrent projects never observe a partial script.

func (*Client) BaseURL

func (g *Client) BaseURL() string

BaseURL is the public provider location, without credentials.

func (*Client) BranchHead

func (g *Client) BranchHead(ctx context.Context, projectPath, branch string) (string, error)

BranchHead is the commit a project's branch points at.

func (*Client) CreateMR

func (g *Client) CreateMR(ctx context.Context, projectPath, source, target, title, description string) (*MergeRequest, error)

func (*Client) CreateProject

func (g *Client) CreateProject(ctx context.Context, name string, namespaceID int) (cloneURL, pathNS string, err error)

CreateProject creates a private project and returns its clone URL and path.

func (*Client) CreateRepository

func (g *Client) CreateRepository(ctx context.Context, name string, namespaceID int, association string) (ProjectRef, error)

CreateRepository returns the provider identity as well as its observed location.

func (*Client) Do

func (g *Client) Do(ctx context.Context, method, path string, body any, out any) error

func (*Client) DoContext

func (g *Client) DoContext(ctx context.Context, method, path string, body any, out any) error

func (*Client) GetMR

func (g *Client) GetMR(ctx context.Context, projectPath string, iid int) (*MergeRequest, error)

func (*Client) MergeMR

func (g *Client) MergeMR(ctx context.Context, projectPath string, iid int, sha, message string) error

MergeMR merges a merge request only if its head is sha, never squashed.

func (*Client) MergeSettings

func (g *Client) MergeSettings(ctx context.Context, projectPath string) (MergeSettings, error)

func (*Client) Project

func (g *Client) Project(ctx context.Context, ref string) (ProjectRef, error)

Project reads a project by its id or its path with namespace.

func (*Client) Raw

func (g *Client) Raw(ctx context.Context, method, path string, body any) (int, []byte, error)

Raw sends JSON to an API-relative path and returns the complete bounded response. It honors ctx without detaching cancellation. Status remains available if reading fails; an incomplete response does not establish the outcome of a provider write.

func (*Client) RenameProject

func (g *Client) RenameProject(ctx context.Context, id int64, newPath string) error

RenameProject moves a project, addressed by its permanent id, to newPath within its namespace.

func (*Client) UpdateMRDescription

func (g *Client) UpdateMRDescription(ctx context.Context, projectPath string, iid int, description string) error

UpdateMRDescription replaces a merge request's whole description. GitLab runs quick actions found in a saved description as this token's owner, so a caller sends only text it has made inert.

type HTTPError

type HTTPError struct {
	Status int
	Text   string
}

Do is DoContext for AppTown's own calls. A write, once sent, is answered though ctx has ended: GitLab makes the change either way, and AppTown must hear which (a project's id, a token). HTTPError is GitLab's answer with a failing status, so a caller can tell "not there" (404) from a refusal or an outage.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type MergeRequest

type MergeRequest struct {
	IID             int    `json:"iid"`
	WebURL          string `json:"web_url"`
	State           string `json:"state"`
	SHA             string `json:"sha"`
	MergeCommitSHA  string `json:"merge_commit_sha"`
	SquashCommitSHA string `json:"squash_commit_sha"`
	SourceBranch    string `json:"source_branch"`
	TargetBranch    string `json:"target_branch"`
	// Squash: the request squashes its commits when merged.
	Squash bool `json:"squash"`
}

type MergeSettings

type MergeSettings struct {
	MergeMethod  string `json:"merge_method"`
	SquashOption string `json:"squash_option"`
	// AutomaticRebase: GitLab rebases the source onto the target itself
	// before merging, landing commits other than the source's. Nil when the
	// project does not say.
	AutomaticRebase *bool `json:"automatic_rebase_enabled"`
}

MergeSettings is how a GitLab project merges: its merge method ("merge", "rebase_merge" for semi-linear history, or "ff"), its squash option ("never", "always", "default_on" or "default_off"), and whether it rebases automatically before merging.

type ProjectRef

type ProjectRef struct {
	DefaultBranch string `json:"default_branch"`
	Description   string `json:"description"`
	CreatorID     int64  `json:"creator_id"`
	ID            int64  `json:"id"`
	HTTPURL       string `json:"http_url_to_repo"`
	SSHURL        string `json:"ssh_url_to_repo"`
	PathNS        string `json:"path_with_namespace"`
	Archived      bool   `json:"archived"`
}

ProjectRef is a GitLab project's permanent id, current path and archive state.

Directories

Path Synopsis
Package gitlabtest is a fake GitLab for tests of code that reaches GitLab through internal/gitlab.
Package gitlabtest is a fake GitLab for tests of code that reaches GitLab through internal/gitlab.

Jump to

Keyboard shortcuts

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