Documentation
¶
Overview ¶
This is a silly wrapper for gitlab client-go but helps maintain consistency
Index ¶
- Constants
- Variables
- func DetectCodingAgent() string
- func Is404(err error) bool
- func IsTokenConfigured(token string) bool
- func ListGroupMRs(client *gitlab.Client, projectID any, ...) ([]*gitlab.BasicMergeRequest, error)
- func NewHTTPRequest(ctx context.Context, c *Client, method string, baseURL *url.URL, ...) (*http.Request, error)
- func PipelineJobsWithID(client *gitlab.Client, pid any, ppid int64) ([]*gitlab.Job, []*gitlab.Bridge, error)
- func PlayOrRetryJobs(client *gitlab.Client, pid any, jobID int64, status string) (*gitlab.Job, error)
- func ProxyFromConfig(cfg config.Config, repoHost string) (func(*http.Request) (*url.URL, error), error)
- func UserByName(client *gitlab.Client, name string) (*gitlab.User, error)
- type BuildInfo
- type CliListMROption
- type Client
- type ClientOption
- func WithBaseURL(baseURL string) ClientOption
- func WithClientCertificate(certFile, keyFile string) ClientOption
- func WithCustomCA(caFile string) ClientOption
- func WithCustomHeaders(headers map[string]string, extraHosts ...string) ClientOption
- func WithGitLabClient(client *gitlab.Client) ClientOption
- func WithHTTPClient(httpClient *http.Client) ClientOption
- func WithInsecureSkipVerify(skip bool) ClientOption
- func WithProxy(proxy func(*http.Request) (*url.URL, error)) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- type FromConfigOption
- type ListMilestonesOptions
- type Milestone
Constants ¶
const ( NamespaceKindUser = "user" NamespaceKindGroup = "group" )
Describe namespace kinds which is either group or user See docs: https://docs.gitlab.com/api/namespaces/
const MaxPerPage = 100
MaxPerPage is the maximum number of items per page supported by the GitLab API. https://docs.gitlab.com/api/rest/#offset-based-pagination
Variables ¶
var DefaultListLimit int64 = 30
var DeleteMR = func(client *gitlab.Client, projectID any, mrID int64) error { _, err := client.MergeRequests.DeleteMergeRequest(projectID, mrID) if err != nil { return err } return nil }
UpdateMR updates an MR Attention: this is a global variable and may be overridden in tests.
var GetIssue = func(client *gitlab.Client, projectID any, issueID int64) (*gitlab.Issue, error) { issue, _, err := client.Issues.GetIssue(projectID, issueID) if err != nil { return nil, err } return issue, nil }
GetIssue returns an issue Attention: this is a global variable and may be overridden in tests.
var GetMR = func(client *gitlab.Client, projectID any, mrID int64, opts *gitlab.GetMergeRequestsOptions) (*gitlab.MergeRequest, error) { mr, _, err := client.MergeRequests.GetMergeRequest(projectID, mrID, opts) if err != nil { return nil, err } return mr, nil }
GetMR returns an MR Attention: this is a global variable and may be overridden in tests.
var GetProject = func(client *gitlab.Client, projectID any) (*gitlab.Project, error) { opts := &gitlab.GetProjectOptions{ License: new(true), WithCustomAttributes: new(true), } project, _, err := client.Projects.GetProject(projectID, opts) if err != nil { return nil, err } return project, nil }
GetProject returns a single project Attention: this is a global variable and may be overridden in tests.
var ListAllMilestones = func(client *gitlab.Client, projectID any, opts *ListMilestonesOptions) ([]*Milestone, error) { project, err := GetProject(client, projectID) if err != nil { return nil, err } errGroup := &errgroup.Group{} projectMilestones := []*gitlab.Milestone{} groupMilestones := []*gitlab.GroupMilestone{} errGroup.Go(func() error { var err error projectMilestones, err = listProjectMilestones(client, projectID, opts.ListProjectMilestonesOptions()) return err }) if project.Namespace.Kind == NamespaceKindGroup { errGroup.Go(func() error { var err error groupMilestones, err = listGroupMilestones(client, project.Namespace.ID, opts.ListGroupMilestonesOptions()) return err }) } if err := errGroup.Wait(); err != nil { return nil, fmt.Errorf("failed to get all project related milestones. %w", err) } milestones := make([]*Milestone, 0, len(projectMilestones)+len(groupMilestones)) for _, v := range projectMilestones { milestones = append(milestones, NewProjectMilestone(v)) } for _, v := range groupMilestones { milestones = append(milestones, NewGroupMilestone(v)) } return milestones, nil }
var ListMRs = func(client *gitlab.Client, projectID any, opts *gitlab.ListProjectMergeRequestsOptions, listOpts ...CliListMROption) ([]*gitlab.BasicMergeRequest, error) { composedListOpts := composeCliListMROptions(listOpts...) assigneeIds, reviewerIds := composedListOpts.assigneeIds, composedListOpts.reviewerIds if len(assigneeIds) > 0 || len(reviewerIds) > 0 { return listMRsWithAssigneesOrReviewers(client, projectID, opts, assigneeIds, reviewerIds) } else { return listMRsBase(client, projectID, opts) } }
ListMRs retrieves merge requests for a given project with optional filtering by assignees or reviewers.
Parameters:
- client: A GitLab client instance.
- projectID: The ID or name of the project.
- opts: GitLab-specific options for listing merge requests.
- listOpts: Optional list of arguments to filter by assignees or reviewers. May be any combination of api.WithMRAssignees and api.WithMRReviewers.
Returns:
- A slice of GitLab merge request objects and an error, if any.
Example usage:
mrs, err := api.ListMRs(client, "my-group", &gitlab.ListProjectMergeRequestsOptions{},
api.WithMRAssignees([]int{123, 456}),
api.WithMRReviewers([]int{789}))
Attention: this is a global variable and may be overridden in tests.
var UpdateIssue = func(client *gitlab.Client, projectID any, issueID int64, opts *gitlab.UpdateIssueOptions) (*gitlab.Issue, error) { issue, _, err := client.Issues.UpdateIssue(projectID, issueID, opts) if err != nil { return nil, err } return issue, nil }
UpdateIssue updates an issue Attention: this is a global variable and may be overridden in tests.
var UpdateMR = func(client *gitlab.Client, projectID any, mrID int64, opts *gitlab.UpdateMergeRequestOptions) (*gitlab.MergeRequest, error) { mr, _, err := client.MergeRequests.UpdateMergeRequest(projectID, mrID, opts) if err != nil { return nil, err } return mr, nil }
UpdateMR updates an MR Attention: this is a global variable and may be overridden in tests.
Functions ¶
func DetectCodingAgent ¶ added in v1.98.0
func DetectCodingAgent() string
AI_AGENT is the universal escape hatch; hardcoded agents are alphabetical, no priority implied.
func IsTokenConfigured ¶ added in v1.66.0
IsTokenConfigured checks if a token is configured (non-empty after trimming whitespace)
func ListGroupMRs ¶
func ListGroupMRs(client *gitlab.Client, projectID any, opts *gitlab.ListGroupMergeRequestsOptions, listOpts ...CliListMROption) ([]*gitlab.BasicMergeRequest, error)
ListGroupMRs retrieves merge requests for a given group with optional filtering by assignees or reviewers.
Parameters:
- client: A GitLab client instance.
- groupID: The ID or name of the group.
- opts: GitLab-specific options for listing group merge requests.
- listOpts: Optional list of arguments to filter by assignees or reviewers. May be any combination of api.WithMRAssignees and api.WithMRReviewers.
Returns:
- A slice of GitLab merge request objects and an error, if any.
Example usage:
groupMRs, err := api.ListGroupMRs(client, "my-group", &gitlab.ListGroupMergeRequestsOptions{},
api.WithMRAssignees([]int{123}),
api.WithMRReviewers([]int{456, 789}))
func NewHTTPRequest ¶
func PipelineJobsWithID ¶
func PipelineJobsWithID(client *gitlab.Client, pid any, ppid int64) ([]*gitlab.Job, []*gitlab.Bridge, error)
PipelineJobsWithID returns a list of jobs in a pipeline for a id. The jobs are returned in the order in which they were created
func PlayOrRetryJobs ¶
Types ¶
type CliListMROption ¶
type CliListMROption func(*cliListMROptions)
func WithMRAssignees ¶
func WithMRAssignees(assigneeIds []int) CliListMROption
func WithMRReviewers ¶
func WithMRReviewers(reviewerIds []int) CliListMROption
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an argument to NewClient
func NewClient ¶
func NewClient(newAuthSource newAuthSource, options ...ClientOption) (*Client, error)
NewClient initializes a api client for use throughout glab.
func NewClientFromConfig ¶
func NewClientFromConfig(repoHost string, cfg config.Config, isGraphQL bool, userAgent string, opts ...FromConfigOption) (*Client, error)
NewClientFromConfig initializes the global api with the config data
func (*Client) AuthSource ¶
func (c *Client) AuthSource() gitlab.AuthSource
AuthSource returns the auth source TODO: clarify use cases for this.
func (*Client) HTTPClient ¶
type ClientOption ¶
ClientOption represents a function that configures a Client
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL configures the base URL for the GitLab instance
func WithClientCertificate ¶
func WithClientCertificate(certFile, keyFile string) ClientOption
WithClientCertificate configures the client to use client certificates for mTLS
func WithCustomCA ¶
func WithCustomCA(caFile string) ClientOption
WithCustomCA configures the client to use a custom CA certificate
func WithCustomHeaders ¶ added in v1.73.0
func WithCustomHeaders(headers map[string]string, extraHosts ...string) ClientOption
WithCustomHeaders sets custom headers for requests to the client's base URL. extraHosts covers destinations the base URL does not, notably the OAuth refresh endpoint, which uses the configured host even when api_host points elsewhere.
func WithGitLabClient ¶
func WithGitLabClient(client *gitlab.Client) ClientOption
WithGitLabClient configures the GitLab client
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient configures the HTTP client
func WithInsecureSkipVerify ¶
func WithInsecureSkipVerify(skip bool) ClientOption
WithInsecureSkipVerify configures the client to skip TLS verification
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent configures the user agent to use
type FromConfigOption ¶ added in v1.114.0
type FromConfigOption func(*fromConfigOptions)
FromConfigOption customizes how NewClientFromConfig resolves credentials out of config. Distinct from ClientOption, which configures the client that has already been built: this affects resolution that happens before a Client exists.
func WithoutTokenFromEnvironment ¶ added in v1.114.0
func WithoutTokenFromEnvironment() FromConfigOption
WithoutTokenFromEnvironment resolves the access token and the is_oauth2 flag from config only, ignoring GITLAB_TOKEN, GITLAB_ACCESS_TOKEN, and GLAB_IS_OAUTH2.
Use it wherever glab acts on behalf of another process that inherits the user's shell environment, such as a Docker credential helper, so a stray environment variable cannot decide which identity the request is made as or which auth flow (OAuth2 vs. PAT) it uses. job_token is unaffected, so CI_JOB_TOKEN authentication keeps working under CI auto-login.
type ListMilestonesOptions ¶
type ListMilestonesOptions struct {
IIDs []int64
State *string
Title *string
Search *string
IncludeParentMilestones *bool
PerPage int64
Page int64
}
func (*ListMilestonesOptions) ListGroupMilestonesOptions ¶
func (opts *ListMilestonesOptions) ListGroupMilestonesOptions() *gitlab.ListGroupMilestonesOptions
func (*ListMilestonesOptions) ListProjectMilestonesOptions ¶
func (opts *ListMilestonesOptions) ListProjectMilestonesOptions() *gitlab.ListMilestonesOptions
type Milestone ¶
func NewGroupMilestone ¶
func NewGroupMilestone(m *gitlab.GroupMilestone) *Milestone
func NewProjectMilestone ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package artifactregistry provides a client for exchanging a GitLab session token for a short-lived GitLab Artifact Registry access token via the POST /api/v4/token_exchange endpoint.
|
Package artifactregistry provides a client for exchanging a GitLab session token for a short-lived GitLab Artifact Registry access token via the POST /api/v4/token_exchange endpoint. |