Documentation
¶
Overview ¶
This is a silly wrapper for gitlab client-go but helps maintain consistency
Index ¶
- Constants
- Variables
- 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 PipelineJobWithSha(client *gitlab.Client, pid any, sha, name string) (*gitlab.Job, error)
- func PipelineJobsWithID(client *gitlab.Client, pid any, ppid int) ([]*gitlab.Job, []*gitlab.Bridge, error)
- func PlayOrRetryJobs(client *gitlab.Client, repo string, jobID int, status string) (*gitlab.Job, 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 WithGitLabClient(client *gitlab.Client) ClientOption
- func WithHTTPClient(httpClient *http.Client) ClientOption
- func WithInsecureSkipVerify(skip bool) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- 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 = 30
var DeleteMR = func(client *gitlab.Client, projectID any, mrID int) 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 int) (*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 int, 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: gitlab.Ptr(true), WithCustomAttributes: gitlab.Ptr(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 int, 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 int, 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 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 PipelineJobWithSha ¶
func PipelineJobsWithID ¶
func PipelineJobsWithID(client *gitlab.Client, pid any, ppid int) ([]*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) (*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 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 ListMilestonesOptions ¶
type ListMilestonesOptions struct { IIDs []int State *string Title *string Search *string IncludeParentMilestones *bool PerPage int Page int }
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