Documentation
¶
Overview ¶
Package gitlab answers the cleanup engine's forge questions — does a project exist, which merge requests contain a commit, does one commit contain another — against the GitLab REST API, with credentials taken from the environment or glab's config file.
Index ¶
- func Credentials(host string) (token, baseURL string, err error)
- func KnownHosts() []string
- type Client
- func (c *Client) Changes(ctx context.Context, p forge.Project, sha string) ([]forge.Change, error)
- func (c *Client) Contains(ctx context.Context, p forge.Project, ancestor, descendant string) (bool, error)
- func (c *Client) DefaultBranch(ctx context.Context, p forge.Project) (string, error)
- func (c *Client) Exists(ctx context.Context, p forge.Project) error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Credentials ¶
Credentials returns the token and API root ("<protocol>://<api host>/api/v4") for a GitLab host, which must be one of KnownHosts. GITLAB_TOKEN applies only to its own host — GITLAB_HOST's hostname, else gitlab.com — and wins there; every other token comes from glab's config file, which also supplies the API host and protocol. Where GITLAB_TOKEN is in use and the config names neither for the host, GITLAB_HOST's scheme and host[:port] do. The glab binary and the system keyring are never consulted, so a token glab keeps in the keyring is not found.
func KnownHosts ¶
func KnownHosts() []string
KnownHosts returns the hosts glab's config file lists, GITLAB_HOST's hostname, and gitlab.com when GITLAB_TOKEN is set without GITLAB_HOST — lowercased, deduplicated and sorted. A config file that exists but cannot be read or parsed contributes no hosts and is reported as a warning.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client queries GitLab hosts. It is safe for concurrent use and keeps one API client per host and one project lookup per project for its lifetime.
func (*Client) Changes ¶
Changes returns every merge request in p that contains the commit sha, whatever its state. A commit p does not hold yields an error wrapping forge.ErrCommitUnknown; a missing project, forge.ErrProjectNotFound.
func (*Client) Contains ¶
func (c *Client) Contains(ctx context.Context, p forge.Project, ancestor, descendant string) (bool, error)
Contains reports whether ancestor, a full commit SHA, is an ancestor of (or equal to) descendant, a SHA or ref, in p; commits sharing no history are not. Either side unknown to p yields an error wrapping forge.ErrCommitUnknown; a missing project, forge.ErrProjectNotFound.
func (*Client) DefaultBranch ¶
DefaultBranch returns p's default branch.
type Options ¶
type Options struct {
// BaseURL, when set, is the API root every host is served from, and
// Token is the token sent to it; Credentials, and with it the
// KnownHosts check, is then never consulted.
BaseURL string
Token string
// HTTPClient carries every request; nil selects net/http's default
// transport. Either way the Client follows no redirect that changes
// scheme or host, and gives a client without a Timeout one of 60
// seconds; HTTPClient itself is not modified.
HTTPClient *http.Client
}
Options configures a Client. The zero value resolves each host's token and API root through Credentials.