gitlab

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gitlab implements forge.Forge for gitlab.com using the GitLab REST API. Uses net/http directly; no extra dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient *http.Client
}

Client is a minimal GitLab API client authenticated with a personal access token. It implements forge.Forge.

func NewClient

func NewClient(token string, throttle http.RoundTripper) *Client

NewClient returns a Client that authenticates with token and throttles/retries via throttle. The transport chain is: Header → Retry → throttle.

func (*Client) BranchCompareURL

func (c *Client) BranchCompareURL(remoteURL, branch string) string

BranchCompareURL returns the GitLab compare URL for a branch.

func (*Client) CIHomeURL

func (c *Client) CIHomeURL(remoteURL string) string

CIHomeURL returns the GitLab pipelines overview URL for a repo.

func (*Client) CIJobURL

func (c *Client) CIJobURL(owner, repo string, _, jobID int64) string

CIJobURL returns the GitLab job URL.

func (*Client) CreatePR

func (c *Client) CreatePR(ctx context.Context, owner, repo, head, base, title, body string) (forge.PR, error)

CreatePR creates a merge request on GitLab and returns its metadata.

func (*Client) FindPRByBranch

func (c *Client) FindPRByBranch(ctx context.Context, owner, repo, sourceBranch string) (forge.PR, error)

FindPRByBranch returns the MR for the given source branch, or ErrNotFound if no MR exists for that branch.

func (*Client) GetCheckRuns

func (c *Client) GetCheckRuns(ctx context.Context, owner, repo, sha string) ([]forge.CheckRun, error)

GetCheckRuns returns all CI pipeline job statuses for the given commit SHA.

func (*Client) GetDefaultBranchSHA

func (c *Client) GetDefaultBranchSHA(ctx context.Context, owner, repo, branch string) (string, error)

GetDefaultBranchSHA returns the HEAD commit SHA of branch in the given repo.

func (*Client) GetJobLabels

func (c *Client) GetJobLabels(_ context.Context, _, _ string, _ int64) ([]string, error)

GetJobLabels returns nil for GitLab; the commit statuses API does not expose job labels.

func (*Client) GetJobLog

func (c *Client) GetJobLog(ctx context.Context, owner, repo string, jobID int64, failingOnly bool) (log string, err error)

GetJobLog fetches the log for a GitLab CI job, capped at 100 MB. failingOnly selects bounded head/tail context: GitLab traces do not include reliable step-level markers. Full retrieval keeps the existing download cap.

func (*Client) MergePR

func (c *Client) MergePR(ctx context.Context, owner, repo string, prNumber int, commitTitle, commitMessage string) error

MergePR squash-merges a merge request on GitLab.

func (*Client) Name

func (c *Client) Name() string

Name returns "GitLab".

func (*Client) PRLabel

func (c *Client) PRLabel(prNumber int) string

PRLabel returns a GitLab-style MR label.

func (*Client) PRURL

func (c *Client) PRURL(owner, repo string, prNumber int) string

PRURL returns the GitLab merge request URL.

type MergeRequestEvent added in v0.8.0

type MergeRequestEvent struct {
	ObjectAttributes struct {
		IID        int    `json:"iid"`
		State      string `json:"state"` // "opened", "closed", "merged"
		Merged     bool   `json:"merged"`
		Title      string `json:"title"`
		Body       string `json:"description"`
		HeadBranch string `json:"head_branch"`
		BaseBranch string `json:"base_branch"`
		HeadSHA    string `json:"head_sha"`
		URL        string `json:"url"`
	} `json:"object_attributes"`
	Project struct {
		PathWithNamespace string `json:"path_with_namespace"` // "group/repo"
	} `json:"project"`
	Repository struct {
		FullName string `json:"full_name"` // "group/repo" (may be empty; use Project)
	} `json:"repository"`
}

MergeRequestEvent is the payload for X-Gitlab-Event: Merge Request Hook.

type PipelineEvent

type PipelineEvent struct {
	ObjectAttributes struct {
		SHA    string `json:"sha"`
		Status string `json:"status"` // "success", "failed", "canceled", "skipped"
		ID     int64  `json:"id"`
	} `json:"object_attributes"`
	Project struct {
		PathWithNamespace string `json:"path_with_namespace"` // "group/repo"
	} `json:"project"`
}

PipelineEvent is the payload for X-Gitlab-Event: Pipeline Hook.

Jump to

Keyboard shortcuts

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