Documentation
¶
Overview ¶
Package gitlab implements forge.Client for the GitLab REST API v4.
Index ¶
- type APIError
- type LiveClient
- func (c *LiveClient) AddIssueLabels(ctx context.Context, owner, repo string, number int, newLabels ...string) error
- func (c *LiveClient) BaseURL() string
- func (c *LiveClient) CloseChangeProposal(ctx context.Context, owner, repo string, number int) error
- func (c *LiveClient) CloseIssue(ctx context.Context, owner, repo string, number int) error
- func (c *LiveClient) CommitFiles(ctx context.Context, owner, repo, message string, files []forge.TreeFile) (bool, error)
- func (c *LiveClient) CommitFilesToBranch(ctx context.Context, owner, repo, branch, message string, ...) (bool, error)
- func (c *LiveClient) CompareCommits(ctx context.Context, owner, repo, base, head string) (string, error)
- func (c *LiveClient) CreateBranch(ctx context.Context, owner, repo, branchName string) error
- func (c *LiveClient) CreateBranchFromSHA(ctx context.Context, owner, repo, branchName, sha string) error
- func (c *LiveClient) CreateChangeProposal(ctx context.Context, owner, repo, title, body, head, base string) (*forge.ChangeProposal, error)
- func (c *LiveClient) CreateCrossRepoChangeProposal(_ context.Context, _, _, _, _, _, _, _, _ string) (*forge.ChangeProposal, error)
- func (c *LiveClient) CreateFile(ctx context.Context, owner, repo, path, message string, content []byte) error
- func (c *LiveClient) CreateFileOnBranch(ctx context.Context, owner, repo, branch, path, message string, content []byte) error
- func (c *LiveClient) CreateFork(ctx context.Context, owner, repo string) (string, string, error)
- func (c *LiveClient) CreateForkInOrg(ctx context.Context, owner, repo, org, forkName string) (string, error)
- func (c *LiveClient) CreateIssue(ctx context.Context, owner, repo, title, body string, labels ...string) (*forge.Issue, error)
- func (c *LiveClient) CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) (*forge.IssueComment, error)
- func (c *LiveClient) CreateOrUpdateFile(ctx context.Context, owner, repo, path, message string, content []byte) error
- func (c *LiveClient) CreateOrUpdateFileOnBranch(ctx context.Context, owner, repo, branch, path, message string, content []byte) error
- func (c *LiveClient) CreateOrUpdateOrgVariable(_ context.Context, _, _, _ string, _ []int64) error
- func (c *LiveClient) CreateOrUpdateOrgVariableAll(_ context.Context, _, _, _ string) error
- func (c *LiveClient) CreateOrUpdateRepoVariable(ctx context.Context, owner, repo, name, value string) error
- func (c *LiveClient) CreateOrgSecret(_ context.Context, _, _, _ string, _ []int64) error
- func (c *LiveClient) CreatePipeline(ctx context.Context, owner, repo, ref string, variables map[string]string) (*forge.Pipeline, error)
- func (c *LiveClient) CreatePipelineSchedule(ctx context.Context, owner, repo, ref, description, cron string, ...) (int64, error)
- func (c *LiveClient) CreateProjectAccessToken(ctx context.Context, owner, repo, name string, scopes []string, ...) (*ProjectAccessToken, error)
- func (c *LiveClient) CreateProtectedCIVariable(ctx context.Context, owner, repo, name, value string) error
- func (c *LiveClient) CreatePullRequestReview(ctx context.Context, owner, repo string, number int, ...) error
- func (c *LiveClient) CreateRepo(ctx context.Context, org, name, description string, private bool) (*forge.Repository, error)
- func (c *LiveClient) CreateRepoSecret(ctx context.Context, owner, repo, name, value string) error
- func (c *LiveClient) DeleteFile(ctx context.Context, owner, repo, path, message string) error
- func (c *LiveClient) DeleteFiles(ctx context.Context, owner, repo, message string, paths []string) (int, error)
- func (c *LiveClient) DeleteIssueComment(ctx context.Context, owner, repo string, commentID int) error
- func (c *LiveClient) DeleteOrgSecret(_ context.Context, _, _ string) error
- func (c *LiveClient) DeleteOrgVariable(_ context.Context, _, _ string) error
- func (c *LiveClient) DeletePipelineSchedule(ctx context.Context, owner, repo string, scheduleID int64) error
- func (c *LiveClient) DeleteRef(ctx context.Context, owner, repo, refPath string) error
- func (c *LiveClient) DeleteRepo(ctx context.Context, owner, repo string) error
- func (c *LiveClient) DeleteRepoSecret(ctx context.Context, owner, repo, name string) error
- func (c *LiveClient) DeleteRepoVariable(ctx context.Context, owner, repo, name string) error
- func (c *LiveClient) DismissPullRequestReview(ctx context.Context, owner, repo string, number, reviewID int, message string) error
- func (c *LiveClient) DispatchWorkflow(_ context.Context, _, _, _, _ string, _ map[string]string) error
- func (c *LiveClient) DownloadWorkflowRunArtifact(_ context.Context, _, _ string, _ int) ([]byte, error)
- func (c *LiveClient) FindExistingFork(ctx context.Context, owner, repo string) (string, string, error)
- func (c *LiveClient) GetAuthenticatedUser(ctx context.Context) (string, error)
- func (c *LiveClient) GetAuthenticatedUserIdentity(ctx context.Context) (*forge.UserIdentity, error)
- func (c *LiveClient) GetBranchRef(ctx context.Context, owner, repo, branch string) (string, error)
- func (c *LiveClient) GetFileContent(ctx context.Context, owner, repo, path string) ([]byte, error)
- func (c *LiveClient) GetFileContentAtRef(ctx context.Context, owner, repo, path, ref string) ([]byte, error)
- func (c *LiveClient) GetIssue(ctx context.Context, owner, repo string, number int) (*forge.Issue, error)
- func (c *LiveClient) GetLatestWorkflowRun(_ context.Context, _, _, _ string) (*forge.WorkflowRun, error)
- func (c *LiveClient) GetOrgPlan(ctx context.Context, org string) (string, error)
- func (c *LiveClient) GetOrgSecretRepos(_ context.Context, _, _ string) ([]int64, error)
- func (c *LiveClient) GetOrgVariable(_ context.Context, _, _ string) (string, bool, error)
- func (c *LiveClient) GetOrgVariableRepos(_ context.Context, _, _ string) ([]int64, error)
- func (c *LiveClient) GetPullRequestHeadSHA(ctx context.Context, owner, repo string, number int) (string, error)
- func (c *LiveClient) GetPullRequestInfo(ctx context.Context, owner, repo string, number int) (*forge.PullRequestInfo, error)
- func (c *LiveClient) GetRef(ctx context.Context, owner, repo, refPath string) (string, error)
- func (c *LiveClient) GetRepo(ctx context.Context, owner, repo string) (*forge.Repository, error)
- func (c *LiveClient) GetRepoVariable(ctx context.Context, owner, repo, name string) (string, bool, error)
- func (c *LiveClient) GetTokenScopes(_ context.Context) ([]string, error)
- func (c *LiveClient) GetWorkflow(_ context.Context, _, _, _ string) (*forge.Workflow, error)
- func (c *LiveClient) GetWorkflowRun(_ context.Context, _, _ string, _ int) (*forge.WorkflowRun, error)
- func (c *LiveClient) GetWorkflowRunAnnotations(_ context.Context, _, _ string, _ int) ([]forge.Annotation, error)
- func (c *LiveClient) GetWorkflowRunLogs(_ context.Context, _, _ string, _ int) (string, error)
- func (c *LiveClient) IsEnterprise(ctx context.Context) bool
- func (c *LiveClient) IsInstallationToken(_ context.Context) (bool, error)
- func (c *LiveClient) IsProtectedBranch(ctx context.Context, owner, repo, branch string) (bool, error)
- func (c *LiveClient) ListDirectoryContents(ctx context.Context, owner, repo, path, ref string, recursive bool) ([]forge.DirectoryEntry, error)
- func (c *LiveClient) ListIssueComments(ctx context.Context, owner, repo string, number int) ([]forge.IssueComment, error)
- func (c *LiveClient) ListOpenIssues(ctx context.Context, owner, repo string, labelFilter ...string) ([]forge.Issue, error)
- func (c *LiveClient) ListOrgRepos(ctx context.Context, org string, includePrivate bool) ([]forge.Repository, error)
- func (c *LiveClient) ListOrgVariables(_ context.Context, _ string) ([]forge.OrgVariable, error)
- func (c *LiveClient) ListPipelineSchedules(ctx context.Context, owner, repo string) ([]forge.PipelineSchedule, error)
- func (c *LiveClient) ListProjectAccessTokens(ctx context.Context, owner, repo string) ([]ProjectAccessToken, error)
- func (c *LiveClient) ListPullRequestFileDiffs(ctx context.Context, owner, repo string, number int) ([]forge.PullRequestFileDiff, error)
- func (c *LiveClient) ListPullRequestFiles(ctx context.Context, owner, repo string, number int) ([]string, error)
- func (c *LiveClient) ListPullRequestReviews(ctx context.Context, owner, repo string, number int) ([]forge.PullRequestReview, error)
- func (c *LiveClient) ListRecentWorkflowRuns(_ context.Context, _, _ string, _ int) ([]forge.WorkflowRun, error)
- func (c *LiveClient) ListRepoPullRequests(ctx context.Context, owner, repo string) ([]forge.ChangeProposal, error)
- func (c *LiveClient) ListRepoVariables(ctx context.Context, owner, repo string) (map[string]string, error)
- func (c *LiveClient) ListRepositoryArtifacts(_ context.Context, _, _ string, _ int) ([]forge.RepositoryArtifact, error)
- func (c *LiveClient) ListRepositoryFiles(ctx context.Context, owner, repo string) ([]string, error)
- func (c *LiveClient) ListResourceGroups(ctx context.Context, owner, repo string) ([]ResourceGroup, error)
- func (c *LiveClient) ListWorkflowRunArtifacts(_ context.Context, _, _ string, _ int) ([]forge.WorkflowArtifact, error)
- func (c *LiveClient) ListWorkflowRunJobs(_ context.Context, _, _ string, _ int) ([]forge.WorkflowJob, error)
- func (c *LiveClient) ListWorkflowRuns(_ context.Context, _, _, _ string) ([]forge.WorkflowRun, error)
- func (c *LiveClient) MergeChangeProposal(ctx context.Context, owner, repo string, number int) error
- func (c *LiveClient) MinimizeComment(_ context.Context, _, _ string) error
- func (c *LiveClient) OrgSecretExists(_ context.Context, _, _ string) (bool, error)
- func (c *LiveClient) OrgVariableExists(_ context.Context, _, _ string) (bool, error)
- func (c *LiveClient) RepoSecretExists(ctx context.Context, owner, repo, name string) (bool, error)
- func (c *LiveClient) RepoVariableExists(ctx context.Context, owner, repo, name string) (bool, error)
- func (c *LiveClient) RevokeProjectAccessToken(ctx context.Context, owner, repo string, tokenID int) error
- func (c *LiveClient) SetOrgSecretRepos(_ context.Context, _, _ string, _ []int64) error
- func (c *LiveClient) SetOrgVariableRepos(_ context.Context, _, _ string, _ []int64) error
- func (c *LiveClient) UpdateCIVariable(ctx context.Context, owner, repo, name, value string, protected bool) error
- func (c *LiveClient) UpdateIssueComment(ctx context.Context, owner, repo string, commentID int, body string) error
- func (c *LiveClient) UpdatePullRequestBranch(ctx context.Context, owner, repo string, number int) error
- func (c *LiveClient) UpdateRepoVisibility(ctx context.Context, owner, repo string, private bool) error
- func (c *LiveClient) UpdateResourceGroupProcessMode(ctx context.Context, owner, repo, key, processMode string) error
- type Option
- type PollClient
- func (pc *PollClient) CreateNoteAwardEmoji(ctx context.Context, owner, repo string, noteableType string, ...) error
- func (pc *PollClient) CreatePipeline(ctx context.Context, owner, repo, ref string, variables map[string]string) (int64, string, error)
- func (pc *PollClient) GetAuthenticatedUserID(ctx context.Context) (int, error)
- func (pc *PollClient) GetCIVariable(ctx context.Context, owner, repo, name string) (string, error)
- func (pc *PollClient) GetIssue(ctx context.Context, owner, repo string, issueIID int) (*poll.Issue, error)
- func (pc *PollClient) GetMemberAccessLevel(ctx context.Context, owner, repo string, userID int) (int, error)
- func (pc *PollClient) GetMergeRequest(ctx context.Context, owner, repo string, mrIID int) (*poll.MergeRequest, error)
- func (pc *PollClient) GetProjectPath(ctx context.Context, projectID int) (string, error)
- func (pc *PollClient) ListIssueNotes(ctx context.Context, owner, repo string, issueIID int) ([]poll.Note, error)
- func (pc *PollClient) ListIssuesUpdatedSince(ctx context.Context, owner, repo string, since time.Time) ([]poll.Issue, error)
- func (pc *PollClient) ListMergeRequestNotes(ctx context.Context, owner, repo string, mrIID int) ([]poll.Note, error)
- func (pc *PollClient) ListMergeRequestsUpdatedSince(ctx context.Context, owner, repo string, since time.Time) ([]poll.MergeRequest, error)
- func (pc *PollClient) ListProjectEvents(ctx context.Context, owner, repo string, targetType string, after time.Time) ([]poll.ProjectEvent, error)
- func (pc *PollClient) ListResourceLabelEvents(ctx context.Context, owner, repo string, issueIID int) ([]poll.ResourceLabelEvent, error)
- type ProjectAccessToken
- type ResourceGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError represents an error response from the GitLab API.
func (*APIError) IsTransient ¶ added in v0.37.0
IsTransient reports whether the API error represents a transient failure that may succeed on retry: server errors (500–504) and rate limits (429). This method satisfies the transientReporter interface used by forge.IsTransient.
type LiveClient ¶
type LiveClient struct {
// contains filtered or unexported fields
}
LiveClient implements forge.Client for the GitLab REST API v4.
func New ¶
func New(token string, opts ...Option) (*LiveClient, error)
New creates a new GitLab client with the given project access token. Returns an error if the configured base URL uses an insecure scheme for a non-loopback host.
func (*LiveClient) AddIssueLabels ¶
func (c *LiveClient) AddIssueLabels(ctx context.Context, owner, repo string, number int, newLabels ...string) error
AddIssueLabels atomically appends labels to an existing issue using GitLab's add_labels parameter, avoiding the read-modify-write race of replacing the full label set.
func (*LiveClient) BaseURL ¶ added in v0.37.0
func (c *LiveClient) BaseURL() string
BaseURL returns the configured base URL for the GitLab instance.
func (*LiveClient) CloseChangeProposal ¶ added in v0.33.0
CloseChangeProposal closes an open merge request without merging it.
func (*LiveClient) CloseIssue ¶
CloseIssue closes an issue by setting its state_event to "close".
func (*LiveClient) CommitFiles ¶
func (c *LiveClient) CommitFiles(ctx context.Context, owner, repo, message string, files []forge.TreeFile) (bool, error)
CommitFiles atomically commits multiple files to the default branch via GitLab's Commits API. Returns (false, nil) when all files already match the current tree (idempotent).
func (*LiveClient) CommitFilesToBranch ¶
func (*LiveClient) CompareCommits ¶ added in v0.37.0
func (c *LiveClient) CompareCommits(ctx context.Context, owner, repo, base, head string) (string, error)
CompareCommits compares two commits and returns their relationship status: "ahead" (head is ahead of base), "behind" (head is behind base), "identical" (same commit), or "diverged" (no linear relationship).
GitLab's compare endpoint is not symmetric — it only reports commits reachable from "to" but not from "from". A single forward call cannot distinguish "ahead" from "diverged" because both cases return non-empty commits. To resolve the ambiguity, a reverse comparison (from=head, to=base) is always made when the forward call returns any diffs or commits. When both directions have commits, the history has diverged.
func (*LiveClient) CreateBranch ¶
func (c *LiveClient) CreateBranch(ctx context.Context, owner, repo, branchName string) error
func (*LiveClient) CreateBranchFromSHA ¶ added in v0.34.0
func (c *LiveClient) CreateBranchFromSHA(ctx context.Context, owner, repo, branchName, sha string) error
CreateBranchFromSHA creates a new branch pointing at the given commit SHA. GitLab's branch creation API accepts a commit SHA as the ref parameter. Returns forge.ErrAlreadyExists if the branch already exists.
func (*LiveClient) CreateChangeProposal ¶
func (c *LiveClient) CreateChangeProposal(ctx context.Context, owner, repo, title, body, head, base string) (*forge.ChangeProposal, error)
CreateChangeProposal creates a merge request on GitLab.
func (*LiveClient) CreateCrossRepoChangeProposal ¶ added in v0.33.0
func (c *LiveClient) CreateCrossRepoChangeProposal(_ context.Context, _, _, _, _, _, _, _, _ string) (*forge.ChangeProposal, error)
CreateCrossRepoChangeProposal is not supported on GitLab. GitLab merge requests between forks use the same source_branch / target_branch API as same-repo MRs (the fork relationship is implicit in the project), so the cross-repo variant is unnecessary. Returns forge.ErrNotSupported.
func (*LiveClient) CreateFile ¶
func (*LiveClient) CreateFileOnBranch ¶
func (*LiveClient) CreateFork ¶
CreateFork is idempotent: if a fork already exists (409 Conflict), it returns the existing fork's metadata.
func (*LiveClient) CreateForkInOrg ¶
func (c *LiveClient) CreateForkInOrg(ctx context.Context, owner, repo, org, forkName string) (string, error)
CreateForkInOrg creates a fork of the given repository under the specified GitLab group (namespace) with the given name.
func (*LiveClient) CreateIssue ¶
func (c *LiveClient) CreateIssue(ctx context.Context, owner, repo, title, body string, labels ...string) (*forge.Issue, error)
CreateIssue creates a new issue on a GitLab project. Labels are sent as a comma-separated string per the GitLab API convention.
func (*LiveClient) CreateIssueComment ¶
func (c *LiveClient) CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) (*forge.IssueComment, error)
CreateIssueComment creates a new note on an issue or merge request.
func (*LiveClient) CreateOrUpdateFile ¶
func (c *LiveClient) CreateOrUpdateFile(ctx context.Context, owner, repo, path, message string, content []byte) error
CreateOrUpdateFile tries a POST (create); on 400 "already exists" it falls back to PUT (update). GitLab's file API does not require a SHA for updates, unlike GitHub.
func (*LiveClient) CreateOrUpdateFileOnBranch ¶
func (*LiveClient) CreateOrUpdateOrgVariable ¶
CreateOrUpdateOrgVariable is not supported on GitLab (per-repo mode).
func (*LiveClient) CreateOrUpdateOrgVariableAll ¶
func (c *LiveClient) CreateOrUpdateOrgVariableAll(_ context.Context, _, _, _ string) error
CreateOrUpdateOrgVariableAll is not supported on GitLab (per-repo mode).
func (*LiveClient) CreateOrUpdateRepoVariable ¶
func (c *LiveClient) CreateOrUpdateRepoVariable(ctx context.Context, owner, repo, name, value string) error
CreateOrUpdateRepoVariable creates a CI/CD variable, or updates it if it already exists. GitLab returns either 409 Conflict or 400 Bad Request with "has already been taken" for duplicate keys.
func (*LiveClient) CreateOrgSecret ¶
CreateOrgSecret is not supported on GitLab (per-repo mode).
func (*LiveClient) CreatePipeline ¶ added in v0.33.0
func (c *LiveClient) CreatePipeline(ctx context.Context, owner, repo, ref string, variables map[string]string) (*forge.Pipeline, error)
CreatePipeline creates a new pipeline on the given ref with the given variables via POST /projects/:id/pipeline. Returns the pipeline ID and web URL. Used by the cron-poller to dispatch agent stages directly.
func (*LiveClient) CreatePipelineSchedule ¶
func (c *LiveClient) CreatePipelineSchedule(ctx context.Context, owner, repo, ref, description, cron string, variables map[string]string) (int64, error)
CreatePipelineSchedule creates a pipeline schedule and attaches variables. Returns the schedule ID.
func (*LiveClient) CreateProjectAccessToken ¶ added in v0.34.0
func (c *LiveClient) CreateProjectAccessToken(ctx context.Context, owner, repo, name string, scopes []string, accessLevel int, expiresAt string) (*ProjectAccessToken, error)
CreateProjectAccessToken creates a project access token with the given name, scopes, and access level. Returns the token (only available at creation time) and the token ID. accessLevel 40 = Maintainer.
func (*LiveClient) CreateProtectedCIVariable ¶
func (c *LiveClient) CreateProtectedCIVariable(ctx context.Context, owner, repo, name, value string) error
CreateProtectedCIVariable creates a branch-restricted, unmasked CI/CD variable. Values are visible in pipeline logs; use CreateRepoSecret for credentials.
func (*LiveClient) CreatePullRequestReview ¶
func (c *LiveClient) CreatePullRequestReview(ctx context.Context, owner, repo string, number int, event, body, commitSHA string, comments []forge.ReviewComment) error
CreatePullRequestReview creates a review on a merge request.
GitLab has no native review object. This method synthesizes reviews:
- APPROVE: POST /projects/:id/merge_requests/:iid/approve When commitSHA is non-empty, it is passed as the "sha" parameter so GitLab rejects the approval if HEAD has advanced (409 Conflict).
- REQUEST_CHANGES or COMMENT: POST a note with the review body, plus individual notes for each inline comment. GitLab's Notes API has no commit-pinning parameter, so commitSHA cannot be enforced for these events.
Inline comments are posted as plain MR notes with file:line in the body text, not as positioned diff comments. GitLab's Discussions API supports positioned comments but requires base/head/start SHAs that are not available through the forge.Client interface.
func (*LiveClient) CreateRepo ¶
func (c *LiveClient) CreateRepo(ctx context.Context, org, name, description string, private bool) (*forge.Repository, error)
func (*LiveClient) CreateRepoSecret ¶
func (c *LiveClient) CreateRepoSecret(ctx context.Context, owner, repo, name, value string) error
CreateRepoSecret creates or updates a protected, masked CI/CD variable (secret). If the value doesn't meet GitLab's masking requirements (min 8 chars, single line, restricted charset), the variable is stored unmasked. If the variable already exists, it is updated in place.
func (*LiveClient) DeleteFile ¶
func (c *LiveClient) DeleteFile(ctx context.Context, owner, repo, path, message string) error
func (*LiveClient) DeleteFiles ¶
func (*LiveClient) DeleteIssueComment ¶
func (c *LiveClient) DeleteIssueComment(ctx context.Context, owner, repo string, commentID int) error
DeleteIssueComment deletes a note on an issue. See UpdateIssueComment for the note-lookup strategy.
func (*LiveClient) DeleteOrgSecret ¶
func (c *LiveClient) DeleteOrgSecret(_ context.Context, _, _ string) error
DeleteOrgSecret is not supported on GitLab (per-repo mode).
func (*LiveClient) DeleteOrgVariable ¶
func (c *LiveClient) DeleteOrgVariable(_ context.Context, _, _ string) error
DeleteOrgVariable is not supported on GitLab (per-repo mode).
func (*LiveClient) DeletePipelineSchedule ¶
func (c *LiveClient) DeletePipelineSchedule(ctx context.Context, owner, repo string, scheduleID int64) error
DeletePipelineSchedule deletes a pipeline schedule.
func (*LiveClient) DeleteRef ¶ added in v0.33.0
func (c *LiveClient) DeleteRef(ctx context.Context, owner, repo, refPath string) error
DeleteRef deletes a git ref via the GitLab Branches or Tags API. refPath must be in the form "heads/<branch>" or "tags/<tag>". Returns forge.ErrNotFound (wrapped) if the ref does not exist.
func (*LiveClient) DeleteRepo ¶
func (c *LiveClient) DeleteRepo(ctx context.Context, owner, repo string) error
func (*LiveClient) DeleteRepoSecret ¶
func (c *LiveClient) DeleteRepoSecret(ctx context.Context, owner, repo, name string) error
DeleteRepoSecret deletes a CI/CD variable (secret). It is idempotent: a 404 (variable already gone) is not treated as an error.
func (*LiveClient) DeleteRepoVariable ¶
func (c *LiveClient) DeleteRepoVariable(ctx context.Context, owner, repo, name string) error
DeleteRepoVariable deletes a CI/CD variable. It is idempotent: a 404 (variable already gone) is not treated as an error.
func (*LiveClient) DismissPullRequestReview ¶
func (c *LiveClient) DismissPullRequestReview(ctx context.Context, owner, repo string, number, reviewID int, message string) error
DismissPullRequestReview dismisses a review on a merge request.
On GitLab, if the review was an approval, this unapproves the MR. For non-approval reviews backed by a request-changes note, this edits the note to replace the request-changes marker with a dismissed marker so ListPullRequestReviews stops reporting it as CHANGES_REQUESTED.
func (*LiveClient) DispatchWorkflow ¶
func (c *LiveClient) DispatchWorkflow(_ context.Context, _, _, _, _ string, _ map[string]string) error
DispatchWorkflow is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) DownloadWorkflowRunArtifact ¶
func (c *LiveClient) DownloadWorkflowRunArtifact(_ context.Context, _, _ string, _ int) ([]byte, error)
DownloadWorkflowRunArtifact is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) FindExistingFork ¶
func (*LiveClient) GetAuthenticatedUser ¶
func (c *LiveClient) GetAuthenticatedUser(ctx context.Context) (string, error)
GetAuthenticatedUser returns the username of the authenticated GitLab user.
func (*LiveClient) GetAuthenticatedUserIdentity ¶
func (c *LiveClient) GetAuthenticatedUserIdentity(ctx context.Context) (*forge.UserIdentity, error)
GetAuthenticatedUserIdentity returns the display name and email of the authenticated GitLab user for Signed-off-by trailers.
When name is empty, the username is used as a fallback. When email is empty, a noreply address is constructed from the user's ID and username to avoid producing malformed Signed-off-by trailers.
func (*LiveClient) GetBranchRef ¶
func (*LiveClient) GetFileContent ¶
func (*LiveClient) GetFileContentAtRef ¶
func (*LiveClient) GetIssue ¶
func (c *LiveClient) GetIssue(ctx context.Context, owner, repo string, number int) (*forge.Issue, error)
GetIssue returns an issue by its project-scoped IID.
func (*LiveClient) GetLatestWorkflowRun ¶
func (c *LiveClient) GetLatestWorkflowRun(_ context.Context, _, _, _ string) (*forge.WorkflowRun, error)
GetLatestWorkflowRun is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) GetOrgPlan ¶
GetOrgPlan returns the billing plan name for a GitLab namespace. Uses the Namespaces API where the plan field is documented, rather than the Groups API where it is undocumented and may be absent. Self-hosted instances typically return "default"; gitlab.com returns the SaaS tier name ("free", "premium", "ultimate", etc.).
func (*LiveClient) GetOrgSecretRepos ¶
GetOrgSecretRepos is not supported on GitLab (per-repo mode).
func (*LiveClient) GetOrgVariable ¶
GetOrgVariable is not supported on GitLab (per-repo mode).
func (*LiveClient) GetOrgVariableRepos ¶
GetOrgVariableRepos is not supported on GitLab (per-repo mode).
func (*LiveClient) GetPullRequestHeadSHA ¶
func (c *LiveClient) GetPullRequestHeadSHA(ctx context.Context, owner, repo string, number int) (string, error)
GetPullRequestHeadSHA returns the current HEAD commit SHA of a merge request.
func (*LiveClient) GetPullRequestInfo ¶
func (c *LiveClient) GetPullRequestInfo(ctx context.Context, owner, repo string, number int) (*forge.PullRequestInfo, error)
GetPullRequestInfo returns branch and repo context for a merge request.
func (*LiveClient) GetRef ¶
GetRef maps forge-style ref paths ("heads/main", "tags/v1") to GitLab commit lookups. GitLab's commits endpoint accepts branch names, tag names, and SHAs directly.
func (*LiveClient) GetRepo ¶
func (c *LiveClient) GetRepo(ctx context.Context, owner, repo string) (*forge.Repository, error)
func (*LiveClient) GetRepoVariable ¶
func (c *LiveClient) GetRepoVariable(ctx context.Context, owner, repo, name string) (string, bool, error)
GetRepoVariable returns the value of a CI/CD variable. Returns ("", false, nil) if the variable does not exist.
func (*LiveClient) GetTokenScopes ¶
func (c *LiveClient) GetTokenScopes(_ context.Context) ([]string, error)
GetTokenScopes returns nil because GitLab does not expose token scopes via an API response header the way GitHub does.
func (*LiveClient) GetWorkflow ¶
GetWorkflow is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) GetWorkflowRun ¶
func (c *LiveClient) GetWorkflowRun(_ context.Context, _, _ string, _ int) (*forge.WorkflowRun, error)
GetWorkflowRun is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) GetWorkflowRunAnnotations ¶
func (c *LiveClient) GetWorkflowRunAnnotations(_ context.Context, _, _ string, _ int) ([]forge.Annotation, error)
GetWorkflowRunAnnotations is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) GetWorkflowRunLogs ¶
GetWorkflowRunLogs is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) IsEnterprise ¶ added in v0.34.0
func (c *LiveClient) IsEnterprise(ctx context.Context) bool
IsEnterprise checks the /metadata endpoint to determine if the GitLab instance is running Enterprise Edition. Self-hosted EE instances always have this set to true. Returns false on error or CE instances.
func (*LiveClient) IsInstallationToken ¶
func (c *LiveClient) IsInstallationToken(_ context.Context) (bool, error)
IsInstallationToken returns false because GitLab has no App installation token concept.
func (*LiveClient) IsProtectedBranch ¶
func (c *LiveClient) IsProtectedBranch(ctx context.Context, owner, repo, branch string) (bool, error)
IsProtectedBranch checks whether the given branch has protection rules. GitLab returns 200 if the branch is protected, 404 if not.
func (*LiveClient) ListDirectoryContents ¶
func (c *LiveClient) ListDirectoryContents(ctx context.Context, owner, repo, path, ref string, recursive bool) ([]forge.DirectoryEntry, error)
func (*LiveClient) ListIssueComments ¶
func (c *LiveClient) ListIssueComments(ctx context.Context, owner, repo string, number int) ([]forge.IssueComment, error)
ListIssueComments returns all notes on an issue or merge request, sorted ascending. GitLab calls comments "notes". The target type (issue vs MR) is controlled by WithNoteTarget.
func (*LiveClient) ListOpenIssues ¶
func (c *LiveClient) ListOpenIssues(ctx context.Context, owner, repo string, labelFilter ...string) ([]forge.Issue, error)
ListOpenIssues returns open issues for a project, optionally filtered by labels. Paginates automatically until all matching issues are retrieved.
func (*LiveClient) ListOrgRepos ¶
func (c *LiveClient) ListOrgRepos(ctx context.Context, org string, includePrivate bool) ([]forge.Repository, error)
func (*LiveClient) ListOrgVariables ¶
func (c *LiveClient) ListOrgVariables(_ context.Context, _ string) ([]forge.OrgVariable, error)
ListOrgVariables is not supported on GitLab (per-repo mode).
func (*LiveClient) ListPipelineSchedules ¶
func (c *LiveClient) ListPipelineSchedules(ctx context.Context, owner, repo string) ([]forge.PipelineSchedule, error)
ListPipelineSchedules returns all pipeline schedules for the project.
func (*LiveClient) ListProjectAccessTokens ¶ added in v0.34.0
func (c *LiveClient) ListProjectAccessTokens(ctx context.Context, owner, repo string) ([]ProjectAccessToken, error)
ListProjectAccessTokens lists all project access tokens.
func (*LiveClient) ListPullRequestFileDiffs ¶
func (c *LiveClient) ListPullRequestFileDiffs(ctx context.Context, owner, repo string, number int) ([]forge.PullRequestFileDiff, error)
ListPullRequestFileDiffs returns the files changed by a merge request along with their unified diff patches.
func (*LiveClient) ListPullRequestFiles ¶
func (c *LiveClient) ListPullRequestFiles(ctx context.Context, owner, repo string, number int) ([]string, error)
ListPullRequestFiles returns the file paths changed by a merge request. GitLab returns diffs with old_path and new_path; we use new_path as the canonical path (matching rename destinations).
func (*LiveClient) ListPullRequestReviews ¶
func (c *LiveClient) ListPullRequestReviews(ctx context.Context, owner, repo string, number int) ([]forge.PullRequestReview, error)
ListPullRequestReviews synthesizes reviews from GitLab's approval state and MR notes.
GitLab has no native review object. Approvals are mapped to APPROVED reviews (ID = approver's user ID), and MR notes are mapped to COMMENTED reviews (ID = note ID). DismissPullRequestReview relies on this convention to distinguish approvals from comments.
func (*LiveClient) ListRecentWorkflowRuns ¶
func (c *LiveClient) ListRecentWorkflowRuns(_ context.Context, _, _ string, _ int) ([]forge.WorkflowRun, error)
ListRecentWorkflowRuns is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) ListRepoPullRequests ¶
func (c *LiveClient) ListRepoPullRequests(ctx context.Context, owner, repo string) ([]forge.ChangeProposal, error)
ListRepoPullRequests lists open merge requests for a project with pagination.
func (*LiveClient) ListRepoVariables ¶
func (c *LiveClient) ListRepoVariables(ctx context.Context, owner, repo string) (map[string]string, error)
ListRepoVariables returns all CI/CD variables for a project as a key-to-value map. Results are paginated; the method follows pagination until all variables are fetched.
func (*LiveClient) ListRepositoryArtifacts ¶
func (c *LiveClient) ListRepositoryArtifacts(_ context.Context, _, _ string, _ int) ([]forge.RepositoryArtifact, error)
ListRepositoryArtifacts is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) ListRepositoryFiles ¶
func (*LiveClient) ListResourceGroups ¶ added in v0.35.0
func (c *LiveClient) ListResourceGroups(ctx context.Context, owner, repo string) ([]ResourceGroup, error)
ListResourceGroups returns all resource groups for the project. Results are paginated; the method follows pagination until all groups are fetched.
func (*LiveClient) ListWorkflowRunArtifacts ¶
func (c *LiveClient) ListWorkflowRunArtifacts(_ context.Context, _, _ string, _ int) ([]forge.WorkflowArtifact, error)
ListWorkflowRunArtifacts is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) ListWorkflowRunJobs ¶ added in v0.34.0
func (c *LiveClient) ListWorkflowRunJobs(_ context.Context, _, _ string, _ int) ([]forge.WorkflowJob, error)
ListWorkflowRunJobs is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) ListWorkflowRuns ¶
func (c *LiveClient) ListWorkflowRuns(_ context.Context, _, _, _ string) ([]forge.WorkflowRun, error)
ListWorkflowRuns is not supported on GitLab (GitHub Actions concept).
func (*LiveClient) MergeChangeProposal ¶
MergeChangeProposal merges a merge request by its IID.
func (*LiveClient) MinimizeComment ¶
func (c *LiveClient) MinimizeComment(_ context.Context, _, _ string) error
MinimizeComment is not supported on GitLab -- there is no equivalent concept of hiding/minimizing individual comments.
func (*LiveClient) OrgSecretExists ¶
OrgSecretExists is not supported on GitLab (per-repo mode).
func (*LiveClient) OrgVariableExists ¶
OrgVariableExists is not supported on GitLab (per-repo mode).
func (*LiveClient) RepoSecretExists ¶
RepoSecretExists checks whether a CI/CD variable (secret) exists.
func (*LiveClient) RepoVariableExists ¶
func (c *LiveClient) RepoVariableExists(ctx context.Context, owner, repo, name string) (bool, error)
RepoVariableExists checks whether a CI/CD variable exists.
func (*LiveClient) RevokeProjectAccessToken ¶ added in v0.34.0
func (c *LiveClient) RevokeProjectAccessToken(ctx context.Context, owner, repo string, tokenID int) error
RevokeProjectAccessToken revokes (deletes) a project access token by ID.
func (*LiveClient) SetOrgSecretRepos ¶
SetOrgSecretRepos is not supported on GitLab (per-repo mode).
func (*LiveClient) SetOrgVariableRepos ¶
SetOrgVariableRepos is not supported on GitLab (per-repo mode).
func (*LiveClient) UpdateCIVariable ¶
func (c *LiveClient) UpdateCIVariable(ctx context.Context, owner, repo, name, value string, protected bool) error
UpdateCIVariable upserts a CI/CD variable (update if exists, create if not).
func (*LiveClient) UpdateIssueComment ¶
func (c *LiveClient) UpdateIssueComment(ctx context.Context, owner, repo string, commentID int, body string) error
UpdateIssueComment updates the body of an existing note on an issue. GitLab's note API requires the issue IID in the URL path, but the forge.Client interface only provides the note ID. Since GitLab has no endpoint to look up a note by ID alone, we scan recent issues (open then closed) to locate the note. In practice, this is always called shortly after ListIssueComments or CreateIssueComment on the same issue.
func (*LiveClient) UpdatePullRequestBranch ¶
func (c *LiveClient) UpdatePullRequestBranch(ctx context.Context, owner, repo string, number int) error
UpdatePullRequestBranch rebases a merge request's source branch onto the target branch. GitLab uses rebase rather than merge-base-into-head. The rebase may be asynchronous; we fire the request and return without waiting for completion.
func (*LiveClient) UpdateRepoVisibility ¶ added in v0.33.0
func (*LiveClient) UpdateResourceGroupProcessMode ¶ added in v0.35.0
func (c *LiveClient) UpdateResourceGroupProcessMode(ctx context.Context, owner, repo, key, processMode string) error
UpdateResourceGroupProcessMode sets the process_mode for a resource group. Valid modes are "unordered", "oldest_first", and "newest_first".
type Option ¶
type Option func(*LiveClient)
Option configures the GitLab client.
func WithAfterFunc ¶ added in v0.37.0
WithAfterFunc replaces the default time.After used for retry delays. Tests can inject an immediate-return function to avoid real sleeps.
func WithBaseURL ¶
WithBaseURL sets a custom base URL for self-hosted GitLab instances. Non-https schemes are only allowed for loopback addresses (localhost, 127.0.0.1) to support test servers; other http:// URLs are rejected to prevent sending the PRIVATE-TOKEN header in cleartext.
func WithNoteTarget ¶ added in v0.34.0
WithNoteTarget configures which GitLab noteable type the comment methods (CreateIssueComment, ListIssueComments, UpdateIssueComment, DeleteIssueComment) operate on. Valid values are "issues" (default) and "merge_requests". GitLab uses separate API endpoints for issue notes vs MR notes; this option selects the correct one.
type PollClient ¶ added in v0.33.0
type PollClient struct {
*LiveClient
}
PollClient wraps a LiveClient to satisfy poll.GitLabClient.
A separate type is needed because poll.GitLabClient.GetIssue returns *poll.Issue while forge.Client.GetIssue returns *forge.Issue. Go does not allow two methods with the same name and different return types on a single struct, so PollClient shadows GetIssue with the poll-specific version and inherits the remaining methods (UpdateCIVariable, GetAuthenticatedUser) from the embedded LiveClient.
func NewPollClient ¶ added in v0.33.0
func NewPollClient(c *LiveClient) *PollClient
NewPollClient wraps a LiveClient for use with the cron poller.
func (*PollClient) CreateNoteAwardEmoji ¶ added in v0.33.0
func (pc *PollClient) CreateNoteAwardEmoji(ctx context.Context, owner, repo string, noteableType string, noteableIID, noteID int, emoji string) error
CreateNoteAwardEmoji adds an emoji reaction to a note. noteableType must be "Issue" or "MergeRequest" to select the correct API path.
func (*PollClient) CreatePipeline ¶ added in v0.33.0
func (pc *PollClient) CreatePipeline(ctx context.Context, owner, repo, ref string, variables map[string]string) (int64, string, error)
CreatePipeline creates a new pipeline on the given ref with the given variables. Returns the pipeline ID and web URL.
func (*PollClient) GetAuthenticatedUserID ¶ added in v0.33.0
func (pc *PollClient) GetAuthenticatedUserID(ctx context.Context) (int, error)
GetAuthenticatedUserID returns the numeric user ID of the authenticated GitLab user. Used by the CLI to set the bot user ID for event filtering.
func (*PollClient) GetCIVariable ¶ added in v0.33.0
GetCIVariable returns the value of a CI/CD variable by key.
func (*PollClient) GetIssue ¶ added in v0.33.0
func (pc *PollClient) GetIssue(ctx context.Context, owner, repo string, issueIID int) (*poll.Issue, error)
GetIssue returns a single issue by its project-scoped IID. This method shadows LiveClient.GetIssue to return *poll.Issue instead of *forge.Issue.
func (*PollClient) GetMemberAccessLevel ¶ added in v0.33.0
func (pc *PollClient) GetMemberAccessLevel(ctx context.Context, owner, repo string, userID int) (int, error)
GetMemberAccessLevel returns the access level for a project member. Uses the /members/all/:user_id endpoint to include inherited group-level membership.
func (*PollClient) GetMergeRequest ¶ added in v0.33.0
func (pc *PollClient) GetMergeRequest(ctx context.Context, owner, repo string, mrIID int) (*poll.MergeRequest, error)
GetMergeRequest returns a single merge request by its project-scoped IID.
func (*PollClient) GetProjectPath ¶ added in v0.33.0
GetProjectPath returns the path_with_namespace for a project by its numeric ID.
func (*PollClient) ListIssueNotes ¶ added in v0.33.0
func (pc *PollClient) ListIssueNotes(ctx context.Context, owner, repo string, issueIID int) ([]poll.Note, error)
ListIssueNotes returns all notes on the given issue in ascending created_at order.
func (*PollClient) ListIssuesUpdatedSince ¶ added in v0.33.0
func (pc *PollClient) ListIssuesUpdatedSince(ctx context.Context, owner, repo string, since time.Time) ([]poll.Issue, error)
ListIssuesUpdatedSince returns all project issues updated after the given timestamp. Results are paginated; all pages are fetched.
func (*PollClient) ListMergeRequestNotes ¶ added in v0.33.0
func (pc *PollClient) ListMergeRequestNotes(ctx context.Context, owner, repo string, mrIID int) ([]poll.Note, error)
ListMergeRequestNotes returns all notes on the given merge request in ascending created_at order.
func (*PollClient) ListMergeRequestsUpdatedSince ¶ added in v0.33.0
func (pc *PollClient) ListMergeRequestsUpdatedSince(ctx context.Context, owner, repo string, since time.Time) ([]poll.MergeRequest, error)
ListMergeRequestsUpdatedSince returns all project merge requests updated after the given timestamp. Results are paginated.
func (*PollClient) ListProjectEvents ¶ added in v0.33.0
func (pc *PollClient) ListProjectEvents(ctx context.Context, owner, repo string, targetType string, after time.Time) ([]poll.ProjectEvent, error)
ListProjectEvents returns project events matching the given target type (e.g. "note") created after the given timestamp. The GitLab Events API "after" parameter is date-only (ISO 8601, exclusive), so we widen the window by one day and filter client-side.
func (*PollClient) ListResourceLabelEvents ¶ added in v0.33.0
func (pc *PollClient) ListResourceLabelEvents(ctx context.Context, owner, repo string, issueIID int) ([]poll.ResourceLabelEvent, error)
ListResourceLabelEvents returns all resource label events for the given issue in ascending ID order.
type ProjectAccessToken ¶ added in v0.34.0
type ProjectAccessToken struct {
ID int `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Token string `json:"token"`
}
ProjectAccessToken represents a GitLab project access token.
type ResourceGroup ¶ added in v0.35.0
ResourceGroup represents a GitLab project resource group.