api

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const APIBasePath = "/api/v4"

APIBasePath is the GitLab REST API v4 base path.

Variables

This section is empty.

Functions

func EncodeProjectPath

func EncodeProjectPath(projectPath string) string

EncodeProjectPath URL-encodes a "group/subgroup/project" path for use in /api/v4/projects/:id endpoints. A numeric project ID is left as-is.

Types

type APIError

type APIError struct {
	StatusCode    int
	ErrorMessages []string
	Errors        map[string]string
}

APIError represents an error returned by the GitLab API.

func (*APIError) Error

func (e *APIError) Error() string

type Branch

type Branch struct {
	Name               string  `json:"name"`
	Merged             bool    `json:"merged"`
	Protected          bool    `json:"protected"`
	Default            bool    `json:"default"`
	DevelopersCanPush  bool    `json:"developers_can_push"`
	DevelopersCanMerge bool    `json:"developers_can_merge"`
	CanPush            bool    `json:"can_push"`
	WebURL             string  `json:"web_url"`
	Commit             *Commit `json:"commit"`
}

Branch is returned by GET /projects/:id/repository/branches

type BranchListOpts

type BranchListOpts struct {
	Search string
	Limit  int
}

BranchListOpts are options for listing branches.

type Client

type Client struct {

	// DownloadClient is used for large/binary downloads (artifacts, etc.).
	DownloadClient *http.Client

	// API groups — populated by NewClient. Subagents implement methods on each
	// API type in their own file (e.g. internal/api/mr.go). Always alphabetical.
	Issues        *IssueAPI
	Jobs          *JobAPI
	Labels        *LabelAPI
	MergeRequests *MergeRequestAPI
	Milestones    *MilestoneAPI
	Pipelines     *PipelineAPI
	Projects      *ProjectAPI
	Releases      *ReleaseAPI
	Repos         *RepoAPI
	Search        *SearchAPI
	Users         *UserAPI
	Variables     *VariableAPI
	// contains filtered or unexported fields
}

Client wraps the GitLab REST API v4 HTTP client.

func NewClient

func NewClient(cfg *config.Config) *Client

NewClient creates a new API client from the given configuration.

func (*Client) APIPath

func (c *Client) APIPath(resource string) string

APIPath returns "/api/v4" + the relative resource path.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) error

Delete sends a DELETE request.

func (*Client) DeleteWithBody

func (c *Client) DeleteWithBody(ctx context.Context, path string, body any) error

DeleteWithBody sends a DELETE request with a JSON body. Required for GitLab endpoints that take parameters in the body on DELETE (e.g. repository file deletion takes branch + commit_message in the body).

func (*Client) DownloadTo

func (c *Client) DownloadTo(ctx context.Context, path string, w io.Writer) error

DownloadTo streams a GET response body to w using DownloadClient (long timeout).

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) ([]byte, error)

Get sends a GET request. Returns body bytes only.

func (*Client) GetWithPagination

func (c *Client) GetWithPagination(ctx context.Context, path string) ([]byte, Pagination, error)

GetWithPagination sends a GET request and returns body + pagination metadata from the response headers. Useful for list endpoints.

func (*Client) Host

func (c *Client) Host() string

Host returns the underlying GitLab host (without trailing slash).

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body any) ([]byte, error)

Post sends a POST request.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body any) ([]byte, error)

Put sends a PUT request.

func (*Client) RawGet

func (c *Client) RawGet(ctx context.Context, path string, headers map[string]string) (int, []byte, error)

RawGet performs a GET with optional extra headers and returns (statusCode, body, error). It retries on 429/5xx but NOT on 416 (range not satisfiable — expected for streaming).

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, path, fieldName, filePath string) ([]byte, error)

type Commit

type Commit struct {
	ID             string   `json:"id"`
	ShortID        string   `json:"short_id"`
	Title          string   `json:"title"`
	Message        string   `json:"message"`
	AuthorName     string   `json:"author_name"`
	AuthorEmail    string   `json:"author_email"`
	AuthoredDate   string   `json:"authored_date"`
	CommitterName  string   `json:"committer_name"`
	CommitterEmail string   `json:"committer_email"`
	CommittedDate  string   `json:"committed_date"`
	WebURL         string   `json:"web_url"`
	ParentIDs      []string `json:"parent_ids"`
}

Commit is returned by GET /projects/:id/repository/commits

type CommitListOpts

type CommitListOpts struct {
	RefName string
	Since   string
	Until   string
	Path    string
	Limit   int
}

CommitListOpts are options for listing commits.

type FileWriteBody

type FileWriteBody struct {
	Branch        string `json:"branch"`
	Content       string `json:"content"`
	CommitMessage string `json:"commit_message"`
	Encoding      string `json:"encoding,omitempty"`
}

FileWriteBody is the request body for create/update file.

type Issue

type Issue struct {
	IID          int      `json:"iid"`
	ID           int      `json:"id"`
	Title        string   `json:"title"`
	Description  string   `json:"description"`
	State        string   `json:"state"`
	Labels       []string `json:"labels"`
	Confidential bool     `json:"confidential"`
	WebURL       string   `json:"web_url"`
	Author       *User    `json:"author"`
	Assignee     *User    `json:"assignee"`
	Milestone    *struct {
		ID    int    `json:"id"`
		Title string `json:"title"`
	} `json:"milestone"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

Issue represents a GitLab project issue.

type IssueAPI

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

IssueAPI wraps issue-related API calls.

Endpoint reference: https://docs.gitlab.com/api/issues/

func (*IssueAPI) AddNote

func (a *IssueAPI) AddNote(ctx context.Context, projectID string, iid int, body string) (*IssueNote, error)

AddNote adds a comment to an issue.

POST /api/v4/projects/:id/issues/:iid/notes

func (*IssueAPI) Create

func (a *IssueAPI) Create(ctx context.Context, projectID string, opts IssueCreateOpts) (*Issue, error)

Create creates a new issue.

POST /api/v4/projects/:id/issues

func (*IssueAPI) DeleteNote

func (a *IssueAPI) DeleteNote(ctx context.Context, projectID string, iid, noteID int) error

DeleteNote deletes a comment from an issue.

DELETE /api/v4/projects/:id/issues/:iid/notes/:note_id

func (*IssueAPI) Get

func (a *IssueAPI) Get(ctx context.Context, projectID string, iid int) (*Issue, error)

Get returns a single issue by IID.

GET /api/v4/projects/:id/issues/:iid

func (*IssueAPI) List

func (a *IssueAPI) List(ctx context.Context, projectID string, opts *IssueListOpts) ([]Issue, error)

List returns issues for a project.

GET /api/v4/projects/:id/issues

func (*IssueAPI) ListNotes

func (a *IssueAPI) ListNotes(ctx context.Context, projectID string, iid, limit int) ([]IssueNote, error)

ListNotes returns comments on an issue.

GET /api/v4/projects/:id/issues/:iid/notes

func (*IssueAPI) Update

func (a *IssueAPI) Update(ctx context.Context, projectID string, iid int, opts IssueUpdateOpts) (*Issue, error)

Update updates an existing issue.

PUT /api/v4/projects/:id/issues/:iid

type IssueCreateOpts

type IssueCreateOpts struct {
	Title        string `json:"title"`
	Description  string `json:"description,omitempty"`
	AssigneeIDs  []int  `json:"assignee_ids,omitempty"`
	Labels       string `json:"labels,omitempty"`
	MilestoneID  int    `json:"milestone_id,omitempty"`
	Confidential bool   `json:"confidential,omitempty"`
}

IssueCreateOpts holds parameters for creating an issue.

type IssueListOpts

type IssueListOpts struct {
	State            string // opened|closed|all
	AssigneeUsername string
	AuthorUsername   string
	Labels           string // comma-separated
	Search           string
	Milestone        string
	Limit            int
}

IssueListOpts holds query parameters for listing issues.

type IssueNote

type IssueNote struct {
	ID        int    `json:"id"`
	Body      string `json:"body"`
	Author    *User  `json:"author"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	System    bool   `json:"system"`
}

IssueNote represents a comment on an issue.

type IssueUpdateOpts

type IssueUpdateOpts struct {
	Title        string `json:"title,omitempty"`
	Description  string `json:"description,omitempty"`
	AssigneeIDs  []int  `json:"assignee_ids,omitempty"`
	AddLabels    string `json:"add_labels,omitempty"`
	RemoveLabels string `json:"remove_labels,omitempty"`
	MilestoneID  int    `json:"milestone_id,omitempty"`
	StateEvent   string `json:"state_event,omitempty"` // close|reopen
}

IssueUpdateOpts holds parameters for updating an issue.

type Job

type Job struct {
	ID         int       `json:"id"`
	Name       string    `json:"name"`
	Status     string    `json:"status"`
	Stage      string    `json:"stage"`
	Ref        string    `json:"ref"`
	WebURL     string    `json:"web_url"`
	CreatedAt  string    `json:"created_at"`
	StartedAt  string    `json:"started_at"`
	FinishedAt string    `json:"finished_at"`
	Duration   float64   `json:"duration"`
	User       *User     `json:"user"`
	Pipeline   *Pipeline `json:"pipeline"`
}

Job represents a GitLab CI job.

type JobAPI

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

JobAPI wraps CI job–related API calls.

Endpoint reference: https://docs.gitlab.com/api/jobs/

Methods are implemented in this file by Phase 1 Wave A.

func (*JobAPI) Artifacts

func (a *JobAPI) Artifacts(ctx context.Context, projectID string, jobID int) ([]byte, error)

Artifacts downloads the artifacts archive for a job and returns the raw bytes.

GET /api/v4/projects/:id/jobs/:job_id/artifacts

func (*JobAPI) ArtifactsTo

func (a *JobAPI) ArtifactsTo(ctx context.Context, projectID string, jobID int, w io.Writer) error

ArtifactsTo streams the artifacts archive for a job to w.

GET /api/v4/projects/:id/jobs/:job_id/artifacts

func (*JobAPI) Cancel

func (a *JobAPI) Cancel(ctx context.Context, projectID string, jobID int) (*Job, error)

Cancel cancels a job.

POST /api/v4/projects/:id/jobs/:job_id/cancel

func (*JobAPI) Get

func (a *JobAPI) Get(ctx context.Context, projectID string, jobID int) (*Job, error)

Get returns a single job.

GET /api/v4/projects/:id/jobs/:job_id

func (*JobAPI) Log

func (a *JobAPI) Log(ctx context.Context, projectID string, jobID int) ([]byte, error)

Log returns the plain-text trace for a job.

GET /api/v4/projects/:id/jobs/:job_id/trace

func (*JobAPI) LogStream

func (a *JobAPI) LogStream(ctx context.Context, projectID string, jobID int, w io.Writer, interval time.Duration) error

LogStream polls the job trace endpoint and writes new bytes to w until the job reaches a terminal state or ctx is cancelled. interval is the poll interval; defaults to 3s if zero.

func (*JobAPI) Retry

func (a *JobAPI) Retry(ctx context.Context, projectID string, jobID int) (*Job, error)

Retry retries a job.

POST /api/v4/projects/:id/jobs/:job_id/retry

type Label

type Label struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Color       string `json:"color"`
	Description string `json:"description"`
	Priority    *int   `json:"priority"`
}

Label represents a GitLab project label.

type LabelAPI

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

LabelAPI wraps label-related API calls.

Endpoint reference: https://docs.gitlab.com/api/labels/

func (*LabelAPI) Create

func (a *LabelAPI) Create(ctx context.Context, projectID string, opts LabelCreateOpts) (*Label, error)

Create creates a new label.

POST /api/v4/projects/:id/labels

func (*LabelAPI) Delete

func (a *LabelAPI) Delete(ctx context.Context, projectID string, labelID int) error

Delete deletes a label.

DELETE /api/v4/projects/:id/labels/:label_id

func (*LabelAPI) List

func (a *LabelAPI) List(ctx context.Context, projectID string, limit int) ([]Label, error)

List returns labels for a project.

GET /api/v4/projects/:id/labels

func (*LabelAPI) Update

func (a *LabelAPI) Update(ctx context.Context, projectID string, labelID int, opts LabelUpdateOpts) (*Label, error)

Update updates an existing label.

PUT /api/v4/projects/:id/labels/:label_id

type LabelCreateOpts

type LabelCreateOpts struct {
	Name        string `json:"name"`
	Color       string `json:"color"`
	Description string `json:"description,omitempty"`
	Priority    *int   `json:"priority,omitempty"`
}

LabelCreateOpts holds parameters for creating a label.

type LabelUpdateOpts

type LabelUpdateOpts struct {
	NewName     string `json:"new_name,omitempty"`
	Color       string `json:"color,omitempty"`
	Description string `json:"description,omitempty"`
	Priority    *int   `json:"priority,omitempty"`
}

LabelUpdateOpts holds parameters for updating a label.

type MergeRequest

type MergeRequest struct {
	IID          int      `json:"iid"`
	Title        string   `json:"title"`
	State        string   `json:"state"`
	SourceBranch string   `json:"source_branch"`
	TargetBranch string   `json:"target_branch"`
	WebURL       string   `json:"web_url"`
	Description  string   `json:"description"`
	Draft        bool     `json:"draft"`
	Squash       bool     `json:"squash"`
	Author       *User    `json:"author"`
	Assignee     *User    `json:"assignee"`
	Labels       []string `json:"labels"`
	SHA          string   `json:"sha"`
	MergeStatus  string   `json:"merge_status"`
	CreatedAt    string   `json:"created_at"`
	UpdatedAt    string   `json:"updated_at"`
}

MergeRequest mirrors the GitLab MR object (subset of fields the CLI surfaces).

type MergeRequestAPI

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

MergeRequestAPI wraps Merge-Request-related API calls.

Endpoint reference: https://docs.gitlab.com/api/merge_requests/

Methods are implemented in this file by Phase 1 Wave A.

func (*MergeRequestAPI) AddNote

func (a *MergeRequestAPI) AddNote(ctx context.Context, projectID string, iid int, body string) (*MergeRequestNote, error)

AddNote adds a comment to an MR.

func (*MergeRequestAPI) Approve

func (a *MergeRequestAPI) Approve(ctx context.Context, projectID string, iid int) error

Approve approves an MR.

func (*MergeRequestAPI) Close

func (a *MergeRequestAPI) Close(ctx context.Context, projectID string, iid int) (*MergeRequest, error)

Close closes an MR via state_event.

func (*MergeRequestAPI) Create

Create creates a new MR.

func (*MergeRequestAPI) DeleteNote

func (a *MergeRequestAPI) DeleteNote(ctx context.Context, projectID string, iid, noteID int) error

DeleteNote deletes a comment from an MR.

func (*MergeRequestAPI) Get

func (a *MergeRequestAPI) Get(ctx context.Context, projectID string, iid int) (*MergeRequest, error)

Get returns a single MR by IID.

func (*MergeRequestAPI) GetRawDiff

func (a *MergeRequestAPI) GetRawDiff(ctx context.Context, projectID string, iid int) (string, error)

GetRawDiff returns the unified diff text for an MR.

func (*MergeRequestAPI) List

func (a *MergeRequestAPI) List(ctx context.Context, projectID string, opts *MergeRequestListOpts) ([]MergeRequest, error)

List returns merge requests for a project.

func (*MergeRequestAPI) ListNotes

func (a *MergeRequestAPI) ListNotes(ctx context.Context, projectID string, iid, limit int) ([]MergeRequestNote, error)

ListNotes returns comments for an MR.

func (*MergeRequestAPI) Merge

func (a *MergeRequestAPI) Merge(ctx context.Context, projectID string, iid int, req *MergeRequestMergeRequest) (*MergeRequest, error)

Merge merges an MR.

func (*MergeRequestAPI) Reopen

func (a *MergeRequestAPI) Reopen(ctx context.Context, projectID string, iid int) (*MergeRequest, error)

Reopen reopens an MR via state_event.

func (*MergeRequestAPI) Unapprove

func (a *MergeRequestAPI) Unapprove(ctx context.Context, projectID string, iid int) error

Unapprove removes approval from an MR.

func (*MergeRequestAPI) Update

func (a *MergeRequestAPI) Update(ctx context.Context, projectID string, iid int, req *MergeRequestUpdateRequest) (*MergeRequest, error)

Update updates an existing MR.

type MergeRequestCreateRequest

type MergeRequestCreateRequest struct {
	Title              string `json:"title"`
	SourceBranch       string `json:"source_branch"`
	TargetBranch       string `json:"target_branch"`
	Description        string `json:"description,omitempty"`
	AssigneeID         int    `json:"assignee_id,omitempty"`
	Labels             string `json:"labels,omitempty"`
	Draft              bool   `json:"draft,omitempty"`
	Squash             bool   `json:"squash,omitempty"`
	RemoveSourceBranch bool   `json:"remove_source_branch,omitempty"`
}

MergeRequestCreateRequest is the POST body for creating an MR.

type MergeRequestListOpts

type MergeRequestListOpts struct {
	State        string // opened|closed|merged|all
	AssigneeUser string
	AuthorUser   string
	Labels       string // comma-separated
	Search       string
	SourceBranch string
	TargetBranch string
	Limit        int
}

MergeRequestListOpts holds query parameters for listing MRs.

type MergeRequestMergeRequest

type MergeRequestMergeRequest struct {
	Squash                   bool   `json:"squash,omitempty"`
	ShouldRemoveSourceBranch bool   `json:"should_remove_source_branch,omitempty"`
	MergeCommitMessage       string `json:"merge_commit_message,omitempty"`
	SHA                      string `json:"sha,omitempty"`
}

MergeRequestMergeRequest is the PUT body for merging an MR.

type MergeRequestNote

type MergeRequestNote struct {
	ID        int    `json:"id"`
	Body      string `json:"body"`
	Author    *User  `json:"author"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	System    bool   `json:"system"`
}

MergeRequestNote mirrors a GitLab MR note (comment).

type MergeRequestUpdateRequest

type MergeRequestUpdateRequest struct {
	Title        string `json:"title,omitempty"`
	Description  string `json:"description,omitempty"`
	AssigneeIDs  []int  `json:"assignee_ids,omitempty"`
	AddLabels    string `json:"add_labels,omitempty"`
	RemoveLabels string `json:"remove_labels,omitempty"`
	TargetBranch string `json:"target_branch,omitempty"`
	StateEvent   string `json:"state_event,omitempty"` // "close" or "reopen"
}

MergeRequestUpdateRequest is the PUT body for updating an MR.

type Milestone

type Milestone struct {
	ID          int    `json:"id"`
	IID         int    `json:"iid"`
	Title       string `json:"title"`
	Description string `json:"description"`
	State       string `json:"state"`
	StartDate   string `json:"start_date"`
	DueDate     string `json:"due_date"`
	WebURL      string `json:"web_url"`
	CreatedAt   string `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
}

Milestone represents a GitLab project milestone.

type MilestoneAPI

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

MilestoneAPI wraps milestone-related API calls.

Endpoint reference: https://docs.gitlab.com/api/milestones/

func (*MilestoneAPI) Create

func (a *MilestoneAPI) Create(ctx context.Context, projectID string, opts MilestoneCreateOpts) (*Milestone, error)

Create creates a new milestone.

POST /api/v4/projects/:id/milestones

func (*MilestoneAPI) Delete

func (a *MilestoneAPI) Delete(ctx context.Context, projectID string, milestoneID int) error

Delete deletes a milestone.

DELETE /api/v4/projects/:id/milestones/:milestone_id

func (*MilestoneAPI) GetByID

func (a *MilestoneAPI) GetByID(ctx context.Context, projectID string, milestoneID int) (*Milestone, error)

GetByID returns a single milestone by its ID.

GET /api/v4/projects/:id/milestones/:milestone_id

func (*MilestoneAPI) List

func (a *MilestoneAPI) List(ctx context.Context, projectID string, opts *MilestoneListOpts) ([]Milestone, error)

List returns milestones for a project.

GET /api/v4/projects/:id/milestones

func (*MilestoneAPI) Update

func (a *MilestoneAPI) Update(ctx context.Context, projectID string, milestoneID int, opts MilestoneUpdateOpts) (*Milestone, error)

Update updates an existing milestone.

PUT /api/v4/projects/:id/milestones/:milestone_id

type MilestoneCreateOpts

type MilestoneCreateOpts struct {
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	StartDate   string `json:"start_date,omitempty"`
	DueDate     string `json:"due_date,omitempty"`
}

MilestoneCreateOpts holds parameters for creating a milestone.

type MilestoneListOpts

type MilestoneListOpts struct {
	State string // active|closed|all
	Limit int
}

MilestoneListOpts holds query parameters for listing milestones.

type MilestoneUpdateOpts

type MilestoneUpdateOpts struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	StartDate   string `json:"start_date,omitempty"`
	DueDate     string `json:"due_date,omitempty"`
	StateEvent  string `json:"state_event,omitempty"` // close|activate
}

MilestoneUpdateOpts holds parameters for updating a milestone.

type Pagination

type Pagination struct {
	Total      int    // X-Total (may be empty for very large lists)
	TotalPages int    // X-Total-Pages
	Page       int    // X-Page
	PerPage    int    // X-Per-Page
	NextPage   int    // X-Next-Page (0 if last)
	PrevPage   int    // X-Prev-Page (0 if first)
	Link       string // Link header
}

Pagination holds the page metadata returned in GitLab response headers.

func PaginateGET

func PaginateGET(ctx context.Context, c *Client, path string, limit int) ([]byte, Pagination, error)

PaginateGET fetches a GitLab list endpoint across pages using X-Next-Page until limit items are collected or there are no more pages. path may include query parameters; per_page and page are set or overridden by this helper. The returned Pagination reflects the last page fetched (use NextPage for hasMore).

type Pipeline

type Pipeline struct {
	ID        int    `json:"id"`
	IID       int    `json:"iid"`
	ProjectID int    `json:"project_id"`
	Ref       string `json:"ref"`
	SHA       string `json:"sha"`
	Status    string `json:"status"`
	Source    string `json:"source"`
	WebURL    string `json:"web_url"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	User      *User  `json:"user"`
}

Pipeline represents a GitLab CI pipeline.

type PipelineAPI

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

PipelineAPI wraps pipeline-related API calls.

Endpoint reference: https://docs.gitlab.com/api/pipelines/

Methods are implemented in this file by Phase 1 Wave A.

func (*PipelineAPI) Cancel

func (a *PipelineAPI) Cancel(ctx context.Context, projectID string, pipelineID int) (*Pipeline, error)

Cancel cancels a pipeline.

POST /api/v4/projects/:id/pipelines/:pipeline_id/cancel

func (*PipelineAPI) Create

func (a *PipelineAPI) Create(ctx context.Context, projectID string, body PipelineCreateBody) (*Pipeline, error)

Create triggers a new pipeline.

POST /api/v4/projects/:id/pipeline

func (*PipelineAPI) Get

func (a *PipelineAPI) Get(ctx context.Context, projectID string, pipelineID int) (*Pipeline, error)

Get returns a single pipeline.

GET /api/v4/projects/:id/pipelines/:pipeline_id

func (*PipelineAPI) Jobs

func (a *PipelineAPI) Jobs(ctx context.Context, projectID string, pipelineID int, scope []string) ([]Job, error)

Jobs returns jobs for a pipeline.

GET /api/v4/projects/:id/pipelines/:pipeline_id/jobs

func (*PipelineAPI) List

func (a *PipelineAPI) List(ctx context.Context, projectID string, opts *PipelineListOpts) ([]Pipeline, error)

List returns pipelines for a project.

GET /api/v4/projects/:id/pipelines

func (*PipelineAPI) Retry

func (a *PipelineAPI) Retry(ctx context.Context, projectID string, pipelineID int) (*Pipeline, error)

Retry retries a pipeline.

POST /api/v4/projects/:id/pipelines/:pipeline_id/retry

type PipelineCreateBody

type PipelineCreateBody struct {
	Ref       string             `json:"ref"`
	Variables []PipelineVariable `json:"variables,omitempty"`
}

PipelineCreateBody is the request body for creating a pipeline.

type PipelineListOpts

type PipelineListOpts struct {
	Ref      string
	Status   string
	Username string
	Limit    int
}

PipelineListOpts holds query parameters for listing pipelines.

type PipelineVariable

type PipelineVariable struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

PipelineVariable is a key/value pair for pipeline variables.

type Project

type Project struct {
	ID                int    `json:"id"`
	Name              string `json:"name"`
	PathWithNamespace string `json:"path_with_namespace"`
	Visibility        string `json:"visibility"`
	WebURL            string `json:"web_url"`
	DefaultBranch     string `json:"default_branch"`
	Description       string `json:"description"`
	SSHURLToRepo      string `json:"ssh_url_to_repo"`
	HTTPURLToRepo     string `json:"http_url_to_repo"`
	StarCount         int    `json:"star_count"`
	ForksCount        int    `json:"forks_count"`
	CreatedAt         string `json:"created_at"`
	LastActivityAt    string `json:"last_activity_at"`
}

Project mirrors the GitLab project object (subset of fields the CLI surfaces).

type ProjectAPI

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

ProjectAPI wraps project-related API calls.

Endpoint reference: https://docs.gitlab.com/api/projects/

Methods are implemented in this file by Phase 1 Wave B.

func (*ProjectAPI) Get

func (a *ProjectAPI) Get(ctx context.Context, idOrPath string) (*Project, error)

Get returns a single project by ID or path.

GET /api/v4/projects/:id

func (*ProjectAPI) List

func (a *ProjectAPI) List(ctx context.Context, opts *ProjectListOpts) ([]Project, error)

List returns projects matching the given options.

GET /api/v4/projects

func (*ProjectAPI) Members

func (a *ProjectAPI) Members(ctx context.Context, idOrPath, query string, limit int) ([]ProjectMember, error)

Members returns members of a project.

GET /api/v4/projects/:id/members

type ProjectListOpts

type ProjectListOpts struct {
	Owned      bool
	Membership bool
	Search     string
	Visibility string // public|internal|private
	Limit      int
}

ProjectListOpts holds query parameters for listing projects.

type ProjectMember

type ProjectMember struct {
	ID          int    `json:"id"`
	Username    string `json:"username"`
	Name        string `json:"name"`
	State       string `json:"state"`
	AccessLevel int    `json:"access_level"`
	WebURL      string `json:"web_url"`
}

ProjectMember mirrors a GitLab project member.

type Release

type Release struct {
	TagName         string         `json:"tag_name"`
	Name            string         `json:"name"`
	Description     string         `json:"description"`
	CreatedAt       string         `json:"created_at"`
	ReleasedAt      string         `json:"released_at"`
	Author          *User          `json:"author"`
	Commit          *Commit        `json:"commit"`
	Milestones      []interface{}  `json:"milestones"`
	CommitPath      string         `json:"commit_path"`
	TagPath         string         `json:"tag_path"`
	DescriptionHTML string         `json:"description_html"`
	Assets          *ReleaseAssets `json:"assets"`
}

Release is returned by GET /projects/:id/releases

type ReleaseAPI

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

ReleaseAPI wraps release-related API calls.

Endpoint reference: https://docs.gitlab.com/api/releases/

func (*ReleaseAPI) Create

func (a *ReleaseAPI) Create(ctx context.Context, projectID string, body ReleaseCreateBody) (*Release, error)

Create creates a new release. POST /api/v4/projects/:id/releases

func (*ReleaseAPI) Delete

func (a *ReleaseAPI) Delete(ctx context.Context, projectID, tagName string) error

Delete deletes a release. DELETE /api/v4/projects/:id/releases/:tag_name

func (*ReleaseAPI) Get

func (a *ReleaseAPI) Get(ctx context.Context, projectID, tagName string) (*Release, error)

Get returns a single release by tag name. GET /api/v4/projects/:id/releases/:tag_name

func (*ReleaseAPI) List

func (a *ReleaseAPI) List(ctx context.Context, projectID string, limit int) ([]Release, error)

List returns releases for a project. GET /api/v4/projects/:id/releases

func (*ReleaseAPI) Update

func (a *ReleaseAPI) Update(ctx context.Context, projectID, tagName string, body ReleaseUpdateBody) (*Release, error)

Update updates an existing release. PUT /api/v4/projects/:id/releases/:tag_name

type ReleaseAssets

type ReleaseAssets struct {
	Count   int `json:"count"`
	Sources []struct {
		Format string `json:"format"`
		URL    string `json:"url"`
	} `json:"sources"`
}

ReleaseAssets holds asset counts for a release.

type ReleaseCreateBody

type ReleaseCreateBody struct {
	TagName     string   `json:"tag_name"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Ref         string   `json:"ref,omitempty"`
	Milestones  []string `json:"milestones,omitempty"`
}

ReleaseCreateBody is the request body for creating a release.

type ReleaseUpdateBody

type ReleaseUpdateBody struct {
	Name        string   `json:"name,omitempty"`
	Description string   `json:"description,omitempty"`
	Milestones  []string `json:"milestones,omitempty"`
}

ReleaseUpdateBody is the request body for updating a release.

type RepoAPI

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

RepoAPI wraps repository-related API calls (files, branches, commits, tree).

Endpoint references:

https://docs.gitlab.com/api/repository_files/
https://docs.gitlab.com/api/branches/
https://docs.gitlab.com/api/commits/
https://docs.gitlab.com/api/repositories/

func (*RepoAPI) CreateBranch

func (a *RepoAPI) CreateBranch(ctx context.Context, projectID, name, ref string) (*Branch, error)

CreateBranch creates a new branch.

func (*RepoAPI) CreateFile

func (a *RepoAPI) CreateFile(ctx context.Context, projectID, filePath string, body FileWriteBody) error

CreateFile creates a new file in the repository.

func (*RepoAPI) DeleteBranch

func (a *RepoAPI) DeleteBranch(ctx context.Context, projectID, name string) error

DeleteBranch deletes a branch.

func (*RepoAPI) DeleteFile

func (a *RepoAPI) DeleteFile(ctx context.Context, projectID, filePath, branch, commitMessage string) error

DeleteFile deletes a file from the repository.

func (*RepoAPI) GetCommit

func (a *RepoAPI) GetCommit(ctx context.Context, projectID, sha string) (*Commit, error)

GetCommit returns a single commit by SHA.

func (*RepoAPI) GetFile

func (a *RepoAPI) GetFile(ctx context.Context, projectID, filePath, ref string) (*RepoFile, error)

GetFile returns file metadata + base64 content.

func (*RepoAPI) GetFileRaw

func (a *RepoAPI) GetFileRaw(ctx context.Context, projectID, filePath, ref string) ([]byte, error)

GetFileRaw returns the raw bytes of a file.

func (*RepoAPI) ListBranches

func (a *RepoAPI) ListBranches(ctx context.Context, projectID string, opts *BranchListOpts) ([]Branch, error)

ListBranches lists branches for a project.

func (*RepoAPI) ListCommits

func (a *RepoAPI) ListCommits(ctx context.Context, projectID string, opts *CommitListOpts) ([]Commit, error)

ListCommits lists commits for a project.

func (*RepoAPI) ListTree

func (a *RepoAPI) ListTree(ctx context.Context, projectID string, opts *TreeOpts) ([]TreeEntry, error)

ListTree lists tree entries for a project.

func (*RepoAPI) UpdateFile

func (a *RepoAPI) UpdateFile(ctx context.Context, projectID, filePath string, body FileWriteBody) error

UpdateFile updates an existing file in the repository.

type RepoFile

type RepoFile struct {
	FileName      string `json:"file_name"`
	FilePath      string `json:"file_path"`
	Size          int    `json:"size"`
	Encoding      string `json:"encoding"`
	Content       string `json:"content"`
	ContentSHA256 string `json:"content_sha256"`
	Ref           string `json:"ref"`
	BlobID        string `json:"blob_id"`
	CommitID      string `json:"commit_id"`
	LastCommitID  string `json:"last_commit_id"`
}

RepoFile is returned by GET /projects/:id/repository/files/:path

type SearchAPI

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

SearchAPI wraps the global search API.

Endpoint reference: https://docs.gitlab.com/api/search/

Methods are implemented in this file by Phase 1 Wave B.

func (*SearchAPI) Code

func (a *SearchAPI) Code(ctx context.Context, query, project string, limit int) ([]SearchBlob, error)

Code searches for code (blobs) within a project. project is required.

GET /api/v4/projects/:id/search?scope=blobs&search=<q>

func (*SearchAPI) Commits

func (a *SearchAPI) Commits(ctx context.Context, query, project string, limit int) ([]SearchCommit, error)

Commits searches for commits. If project is non-empty, uses project-scoped endpoint.

GET /api/v4/search?scope=commits&search=<q> GET /api/v4/projects/:id/search?scope=commits&search=<q>

func (*SearchAPI) Issues

func (a *SearchAPI) Issues(ctx context.Context, query, project string, limit int) ([]SearchIssue, error)

Issues searches for issues. If project is non-empty, uses project-scoped endpoint.

GET /api/v4/search?scope=issues&search=<q> GET /api/v4/projects/:id/search?scope=issues&search=<q>

func (*SearchAPI) MergeRequests

func (a *SearchAPI) MergeRequests(ctx context.Context, query, project string, limit int) ([]SearchMR, error)

MergeRequests searches for MRs. If project is non-empty, uses project-scoped endpoint.

GET /api/v4/search?scope=merge_requests&search=<q> GET /api/v4/projects/:id/search?scope=merge_requests&search=<q>

func (*SearchAPI) Projects

func (a *SearchAPI) Projects(ctx context.Context, query string, limit int) ([]SearchProject, error)

Projects searches for projects globally.

GET /api/v4/search?scope=projects&search=<q>

type SearchBlob

type SearchBlob struct {
	Basename  string `json:"basename"`
	Data      string `json:"data"`
	Path      string `json:"path"`
	Filename  string `json:"filename"`
	Ref       string `json:"ref"`
	StartLine int    `json:"startline"`
	ProjectID int    `json:"project_id"`
}

SearchBlob is a code search result (blob/file match).

type SearchCommit

type SearchCommit struct {
	ID         string `json:"id"`
	ShortID    string `json:"short_id"`
	Title      string `json:"title"`
	AuthorName string `json:"author_name"`
	CreatedAt  string `json:"created_at"`
	WebURL     string `json:"web_url"`
	ProjectID  int    `json:"project_id"`
}

SearchCommit is a slim commit result from search.

type SearchIssue

type SearchIssue struct {
	ID        int    `json:"id"`
	IID       int    `json:"iid"`
	Title     string `json:"title"`
	State     string `json:"state"`
	WebURL    string `json:"web_url"`
	ProjectID int    `json:"project_id"`
}

SearchIssue is a slim issue result from search.

type SearchMR

type SearchMR struct {
	ID        int    `json:"id"`
	IID       int    `json:"iid"`
	Title     string `json:"title"`
	State     string `json:"state"`
	WebURL    string `json:"web_url"`
	ProjectID int    `json:"project_id"`
}

SearchMR is a slim merge request result from search.

type SearchProject

type SearchProject struct {
	ID                int    `json:"id"`
	Name              string `json:"name"`
	PathWithNamespace string `json:"path_with_namespace"`
	WebURL            string `json:"web_url"`
	Visibility        string `json:"visibility"`
	DefaultBranch     string `json:"default_branch"`
}

SearchProject is a slim project result from global search.

type TreeEntry

type TreeEntry struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"` // "blob" or "tree"
	Path string `json:"path"`
	Mode string `json:"mode"`
}

TreeEntry is returned by GET /projects/:id/repository/tree

type TreeOpts

type TreeOpts struct {
	Path      string
	Ref       string
	Recursive bool
	Limit     int
}

TreeOpts are options for listing tree entries.

type User

type User struct {
	ID        int    `json:"id"`
	Username  string `json:"username"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	State     string `json:"state"`
	WebURL    string `json:"web_url"`
	AvatarURL string `json:"avatar_url"`
	Bot       bool   `json:"bot"`
}

type UserAPI

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

UserAPI wraps user-related API calls.

Endpoint reference: https://docs.gitlab.com/api/users/

func (*UserAPI) GetByUsername

func (a *UserAPI) GetByUsername(ctx context.Context, username string) (*User, error)

GetByUsername fetches a user by username via /users?username=<name>. Returns nil, nil if no user found.

func (*UserAPI) Me

func (a *UserAPI) Me(ctx context.Context) (*User, error)

Me retrieves the currently authenticated user (GET /user).

func (*UserAPI) Search

func (a *UserAPI) Search(ctx context.Context, query string, limit int) ([]User, error)

Search searches for users (GET /users?search=...).

type Variable

type Variable struct {
	Key              string `json:"key"`
	Value            string `json:"value"`
	VariableType     string `json:"variable_type"`
	Protected        bool   `json:"protected"`
	Masked           bool   `json:"masked"`
	Raw              bool   `json:"raw"`
	EnvironmentScope string `json:"environment_scope"`
	Description      string `json:"description"`
}

Variable mirrors a GitLab project-level CI/CD variable.

type VariableAPI

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

VariableAPI wraps CI/CD variable–related API calls.

Endpoint reference: https://docs.gitlab.com/api/project_level_variables/

Methods are implemented in this file by Phase 1 Wave B.

func (*VariableAPI) Create

func (a *VariableAPI) Create(ctx context.Context, projectID string, opts *VariableCreateOpts) (*Variable, error)

Create creates a new CI/CD variable.

POST /api/v4/projects/:id/variables

func (*VariableAPI) Delete

func (a *VariableAPI) Delete(ctx context.Context, projectID, key, envScope string) error

Delete deletes a CI/CD variable.

DELETE /api/v4/projects/:id/variables/:key?filter[env_scope]=<scope>

func (*VariableAPI) Get

func (a *VariableAPI) Get(ctx context.Context, projectID, key, envScope string) (*Variable, error)

Get returns a single variable by key.

GET /api/v4/projects/:id/variables/:key?filter[env_scope]=<scope>

func (*VariableAPI) List

func (a *VariableAPI) List(ctx context.Context, projectID string, limit int) ([]Variable, error)

List returns all CI/CD variables for a project.

GET /api/v4/projects/:id/variables?per_page=N

func (*VariableAPI) Update

func (a *VariableAPI) Update(ctx context.Context, projectID, key, envScope string, opts *VariableUpdateOpts) (*Variable, error)

Update updates an existing CI/CD variable.

PUT /api/v4/projects/:id/variables/:key?filter[env_scope]=<scope>

type VariableCreateOpts

type VariableCreateOpts struct {
	Key              string `json:"key"`
	Value            string `json:"value"`
	VariableType     string `json:"variable_type,omitempty"`
	Protected        bool   `json:"protected,omitempty"`
	Masked           bool   `json:"masked,omitempty"`
	Raw              bool   `json:"raw,omitempty"`
	EnvironmentScope string `json:"environment_scope,omitempty"`
	Description      string `json:"description,omitempty"`
}

VariableCreateOpts is the POST body for creating a variable.

type VariableUpdateOpts

type VariableUpdateOpts struct {
	Value            string `json:"value,omitempty"`
	VariableType     string `json:"variable_type,omitempty"`
	Protected        *bool  `json:"protected,omitempty"`
	Masked           *bool  `json:"masked,omitempty"`
	Raw              *bool  `json:"raw,omitempty"`
	EnvironmentScope string `json:"environment_scope,omitempty"`
	Description      string `json:"description,omitempty"`
}

VariableUpdateOpts is the PUT body for updating a variable.

Jump to

Keyboard shortcuts

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