Documentation
¶
Index ¶
- func GetToken(hostname string) (string, error)
- type Client
- func (c *Client) CreatePullRequest(ctx context.Context, title, body, head, base string, draft bool) (number int, url string, err error)
- func (c *Client) DownloadArtifact(ctx context.Context, artifactID int64) (io.ReadCloser, error)
- func (c *Client) GetLatestRunForBranch(ctx context.Context, branch string) (*remote.Workflow, error)
- func (c *Client) GetLatestRunForTag(ctx context.Context, tag string) (*remote.Workflow, error)
- func (c *Client) GetLatestWorkflow(ctx context.Context, branch string) (*remote.Workflow, error)
- func (c *Client) GetPullRequestByBranch(ctx context.Context, branch string) (number int, url string, err error)
- func (c *Client) GetPullRequestChecks(ctx context.Context, prNumber int) (*remote.PRChecks, error)
- func (c *Client) GetPullRequestTitle(ctx context.Context, prNumber int) (string, error)
- func (c *Client) GetWorkflowRun(ctx context.Context, runID string) (*remote.Workflow, error)
- func (c *Client) ListRunArtifacts(ctx context.Context, runID string) ([]remote.Artifact, error)
- func (c *Client) ListRuns(ctx context.Context, workflowFile, branch string, limit int) ([]remote.Workflow, error)
- func (c *Client) MarkPullRequestReady(ctx context.Context, prNumber int) error
- func (c *Client) MergePullRequest(ctx context.Context, prNumber int, method string) error
- func (c *Client) RerunWorkflow(ctx context.Context, runID string, failedOnly bool) error
- func (c *Client) TriggerWorkflow(ctx context.Context, workflowFile, ref string, inputs map[string]string) (*remote.Workflow, error)
- func (c *Client) UpdatePullRequest(ctx context.Context, prNumber int, title, body string) error
- func (c *Client) WaitForChecksToStart(ctx context.Context, prNumber int, expectedSHA string, timeout time.Duration) (headSHA string, checks *remote.PRChecks, err error)
- func (c *Client) WatchPullRequestChecks(ctx context.Context, prNumber int) (<-chan remote.PRChecksUpdate, error)
- func (c *Client) WatchWorkflow(ctx context.Context, workflowID string) (<-chan remote.WorkflowUpdate, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements remote.Provider for GitLab
func NewClientWithBaseURL ¶
NewClientWithBaseURL creates a new GitLab client for self-hosted instances
func (*Client) CreatePullRequest ¶
func (c *Client) CreatePullRequest(ctx context.Context, title, body, head, base string, draft bool) (number int, url string, err error)
CreatePullRequest creates a new merge request
func (*Client) DownloadArtifact ¶
DownloadArtifact opens the zip archive a job uploaded. artifactID is the job's ID, which is what ListRunArtifacts reports.
func (*Client) GetLatestRunForBranch ¶
func (c *Client) GetLatestRunForBranch(ctx context.Context, branch string) (*remote.Workflow, error)
GetLatestRunForBranch returns the most recent pipeline for the given branch. On GitLab, all pipelines on a branch share the same .gitlab-ci.yml, so this is equivalent to GetLatestWorkflow.
func (*Client) GetLatestRunForTag ¶
GetLatestRunForTag returns the most recent pipeline triggered by a tag. GitLab queries pipelines by ref, which covers branches and tags alike, so the tag name is passed through unchanged. Unlike GetLatestWorkflow it reports an error rather than a nil pipeline when nothing matches, because callers watch the result (issue #223).
func (*Client) GetLatestWorkflow ¶
GetLatestWorkflow returns the latest pipeline for the given branch
func (*Client) GetPullRequestByBranch ¶
func (c *Client) GetPullRequestByBranch(ctx context.Context, branch string) (number int, url string, err error)
GetPullRequestByBranch finds an open MR for the given source branch
func (*Client) GetPullRequestChecks ¶
GetPullRequestChecks returns pipeline status for an MR.
The counterpart of issue #240 cannot arise here: the jobs come from the MR's own head pipeline, not from everything attached to the head commit, so a pipeline someone triggers by hand on the branch is a separate pipeline that is never folded in. GitHub has no such notion -- every check run of the SHA lands on the PR -- which is why only that side needed a filter.
func (*Client) GetPullRequestTitle ¶
GetPullRequestTitle returns the title of a merge request.
GitLab prefixes a draft's title with "Draft: ", which is the platform's marker rather than part of what the author wrote — UpdatePullRequest below re-applies it for the same reason. It is stripped here so a caller reading the title reads the title.
func (*Client) GetWorkflowRun ¶
GetWorkflowRun returns a pipeline by its ID.
func (*Client) ListRunArtifacts ¶
ListRunArtifacts returns the jobs of a pipeline that produced an artifact.
GitLab attaches artifacts to jobs, not to pipelines, so a job that uploaded something is what an artifact is here -- and the identifier the download takes is therefore the job's. The name is the job's name, which is what a GitLab user sees next to the archive in the UI.
func (*Client) ListRuns ¶
func (c *Client) ListRuns(ctx context.Context, workflowFile, branch string, limit int) ([]remote.Workflow, error)
ListRuns returns the most recent pipelines, newest first.
workflowFile selects nothing here for the same reason it selects nothing in TriggerWorkflow -- GitLab runs one pipeline definition per project -- so it is reported and ignored rather than silently dropped. Everything else carries over: an empty branch means every ref, and the listing is one call.
func (*Client) MarkPullRequestReady ¶
MarkPullRequestReady marks a draft MR as ready for review
func (*Client) MergePullRequest ¶
MergePullRequest merges a merge request
func (*Client) RerunWorkflow ¶
RerunWorkflow retries the failed jobs of a pipeline.
GitLab's retry endpoint restarts the jobs that failed or were cancelled, which is exactly the recovery `--failed` asks for. There is no counterpart for restarting a pipeline that succeeded: the platform's answer to that is a new pipeline on the same ref, which cidx already has a command for, so this says so instead of pretending (issue #342).
func (*Client) TriggerWorkflow ¶
func (c *Client) TriggerWorkflow(ctx context.Context, workflowFile, ref string, inputs map[string]string) (*remote.Workflow, error)
TriggerWorkflow starts a pipeline on ref and returns it.
GitLab runs one pipeline definition per project, so workflowFile selects nothing here -- it is reported and ignored rather than silently dropped. The inputs become pipeline variables, GitLab's equivalent of the key/value pairs a workflow_dispatch takes.
Unlike GitHub's dispatch endpoint, POST /projects/:id/pipeline answers with the pipeline it created, so there is no run to identify afterwards and none of the raciness documented on the GitHub side applies (issue #266).
func (*Client) UpdatePullRequest ¶
UpdatePullRequest updates the title and/or description of a merge request. Empty strings leave the corresponding field unchanged. The "Draft: " title prefix is preserved so retitling a draft MR does not mark it ready.
func (*Client) WaitForChecksToStart ¶
func (c *Client) WaitForChecksToStart(ctx context.Context, prNumber int, expectedSHA string, timeout time.Duration) (headSHA string, checks *remote.PRChecks, err error)
WaitForChecksToStart waits for pipeline to be created on the MR. When expectedSHA is set, it also waits for the MR head to reach that commit, so a pipeline for a previous commit is never returned (issue #167).
func (*Client) WatchPullRequestChecks ¶
func (c *Client) WatchPullRequestChecks(ctx context.Context, prNumber int) (<-chan remote.PRChecksUpdate, error)
WatchPullRequestChecks watches pipeline status for an MR
func (*Client) WatchWorkflow ¶
func (c *Client) WatchWorkflow(ctx context.Context, workflowID string) (<-chan remote.WorkflowUpdate, error)
WatchWorkflow watches a pipeline and sends updates