Documentation ¶
Overview ¶
This is a silly wrapper for go-gitlab but helps maintain consistency
Index ¶
- Constants
- Variables
- func HTTPClient() *http.Client
- func IsValidToken(token string) bool
- func NewHTTPRequest(c *Client, method string, baseURL *url.URL, body io.Reader, headers []string, ...) (*http.Request, error)
- func OverrideHTTPClient(client *http.Client)
- func RefreshClient()
- func SetProtocol(protocol string)
- func SetUserAgent(version string, platform string, architecture string)
- func Token() string
- type Client
- func GetClient() *Client
- func NewClient(host, token string, allowInsecure bool, isGraphQL bool) (*Client, error)
- func NewClientWithCfg(repoHost string, cfg config.Config, isGraphQL bool) (client *Client, err error)
- func NewClientWithCustomCA(host, token, caFile string, isGraphQL bool) (*Client, error)
- func NewClientWithCustomCAClientCert(host, token, caFile string, certFile string, keyFile string, isGraphQL bool) (*Client, error)
- func TestClient(httpClient *http.Client, token, host string, isGraphQL bool) (*Client, error)
- type CreatePullMirrorOptions
- type CreatePushMirrorOptions
- type JobSort
- type ListMilestonesOptions
- type Milestone
Constants ¶
const ( NoToken authType = iota OAuthToken PrivateToken )
const ( NamespaceKindUser = "user" NamespaceKindGroup = "group" )
Describe namespace kinds which is either group or user See docs: https://docs.gitlab.com/ee/api/namespaces.html
Variables ¶
var AddIssueTimeSpent = func(client *gitlab.Client, projectID interface{}, issueIDD int, opts *gitlab.AddSpentTimeOptions) (*gitlab.TimeStats, error) { if client == nil { client = apiClient.Lab() } timeStats, _, err := client.Issues.AddSpentTime(projectID, issueIDD, opts) if err != nil { return nil, err } return timeStats, nil }
var ApproveMR = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.ApproveMergeRequestOptions) (*gitlab.MergeRequestApprovals, error) { if client == nil { client = apiClient.Lab() } mr, _, err := client.MergeRequestApprovals.ApproveMergeRequest(projectID, mrID, opts) if err != nil { return nil, err } return mr, nil }
var CancelPipelineJob = func(client *gitlab.Client, repo string, jobID int) (*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } pipe, _, err := client.Jobs.CancelJob(repo, jobID) if err != nil { return nil, err } return pipe, nil }
var CreateBranch = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateBranchOptions) (*gitlab.Branch, error) { if client == nil { client = apiClient.Lab() } branch, _, err := client.Branches.CreateBranch(projectID, opts) if err != nil { return nil, err } return branch, nil }
var CreateGroupVariable = func(client *gitlab.Client, groupID interface{}, opts *gitlab.CreateGroupVariableOptions) (*gitlab.GroupVariable, error) { if client == nil { client = apiClient.Lab() } vars, _, err := client.GroupVariables.CreateVariable(groupID, opts) if err != nil { return nil, err } return vars, nil }
var CreateIssue = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateIssueOptions) (*gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } issue, _, err := client.Issues.CreateIssue(projectID, opts) if err != nil { return nil, err } return issue, nil }
var CreateIssueBoard = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateIssueBoardOptions) (*gitlab.IssueBoard, error) { if client == nil { client = apiClient.Lab() } board, _, err := client.Boards.CreateIssueBoard(projectID, opts) if err != nil { return nil, err } return board, nil }
var CreateIssueNote = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.CreateIssueNoteOptions) (*gitlab.Note, error) { if client == nil { client = apiClient.Lab() } note, _, err := client.Notes.CreateIssueNote(projectID, mrID, opts) if err != nil { return note, err } return note, nil }
var CreateLabel = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateLabelOptions) (*gitlab.Label, error) { if client == nil { client = apiClient.Lab() } label, _, err := client.Labels.CreateLabel(projectID, opts) if err != nil { return nil, err } return label, nil }
var CreateMR = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateMergeRequestOptions) (*gitlab.MergeRequest, error) { if client == nil { client = apiClient.Lab() } mr, _, err := client.MergeRequests.CreateMergeRequest(projectID, opts) if err != nil { return nil, err } return mr, nil }
var CreateMRNote = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.CreateMergeRequestNoteOptions) (*gitlab.Note, error) { if client == nil { client = apiClient.Lab() } note, _, err := client.Notes.CreateMergeRequestNote(projectID, mrID, opts) if err != nil { return note, err } return note, nil }
var CreatePipeline = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreatePipelineOptions) (*gitlab.Pipeline, error) { if client == nil { client = apiClient.Lab() } pipe, _, err := client.Pipelines.CreatePipeline(projectID, opts) return pipe, err }
var CreateProject = func(client *gitlab.Client, opts *gitlab.CreateProjectOptions) (*gitlab.Project, error) { if client == nil { client = apiClient.Lab() } project, _, err := client.Projects.CreateProject(opts) if err != nil { return nil, err } return project, nil }
var CreateProjectSnippet = func( client *gitlab.Client, projectID interface{}, opts *gitlab.CreateProjectSnippetOptions, ) (*gitlab.Snippet, error) { if client == nil { client = apiClient.Lab() } snipet, _, err := client.ProjectSnippets.CreateSnippet(projectID, opts) if err != nil { return nil, err } return snipet, err }
CreateProjectSnippet inside the project
var CreateProjectVariable = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateProjectVariableOptions) (*gitlab.ProjectVariable, error) { if client == nil { client = apiClient.Lab() } vars, _, err := client.ProjectVariables.CreateVariable(projectID, opts) if err != nil { return nil, err } return vars, nil }
var CreatePullMirror = func( client *gitlab.Client, projectID interface{}, opts *CreatePullMirrorOptions, ) error { if client == nil { client = apiClient.Lab() } opt := &gitlab.EditProjectOptions{ ImportURL: &opts.Url, Mirror: &opts.Enabled, OnlyMirrorProtectedBranches: &opts.OnlyProtectedBranches, } _, _, err := client.Projects.EditProject(projectID, opt) return err }
var CreatePushMirror = func( client *gitlab.Client, projectID interface{}, opts *CreatePushMirrorOptions, ) (*gitlab.ProjectMirror, error) { if client == nil { client = apiClient.Lab() } opt := &gitlab.AddProjectMirrorOptions{ URL: &opts.Url, Enabled: &opts.Enabled, OnlyProtectedBranches: &opts.OnlyProtectedBranches, KeepDivergentRefs: &opts.KeepDivergentRefs, } pm, _, err := client.ProjectMirrors.AddProjectMirror(projectID, opt) return pm, err }
var CreateRelease = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateReleaseOptions) (*gitlab.Release, error) { if client == nil { client = apiClient.Lab() } release, _, err := client.Releases.CreateRelease(projectID, opts) if err != nil { return nil, err } return release, nil }
var CreateSnippet = func( client *gitlab.Client, projectID interface{}, opts *gitlab.CreateSnippetOptions, ) (*gitlab.Snippet, error) { if client == nil { client = apiClient.Lab() } snipet, _, err := client.Snippets.CreateSnippet(opts) if err != nil { return nil, err } return snipet, err }
CreateSnippet for the user inside the users snippets
var CurrentUser = func(client *gitlab.Client) (*gitlab.User, error) { if client == nil { client = apiClient.Lab() } u, _, err := client.Users.CurrentUser() if err != nil { return nil, err } return u, nil }
var CurrentUserEvents = func(client *gitlab.Client, opts *gitlab.ListContributionEventsOptions) ([]*gitlab.ContributionEvent, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } events, _, err := client.Events.ListCurrentUserContributionEvents(opts) if err != nil { return nil, err } return events, nil }
var DefaultListLimit = 30
var DeleteGroupVariable = func(client *gitlab.Client, groupID interface{}, key string) error { if client == nil { client = apiClient.Lab() } _, err := client.GroupVariables.RemoveVariable(groupID, key) if err != nil { return err } return nil }
var DeleteIssue = func(client *gitlab.Client, projectID interface{}, issueID int) error { if client == nil { client = apiClient.Lab() } _, err := client.Issues.DeleteIssue(projectID, issueID) if err != nil { return err } return nil }
var DeleteMR = func(client *gitlab.Client, projectID interface{}, mrID int) error { if client == nil { client = apiClient.Lab() } _, err := client.MergeRequests.DeleteMergeRequest(projectID, mrID) if err != nil { return err } return nil }
var DeletePipeline = func(client *gitlab.Client, projectID interface{}, pipeID int) error { if client == nil { client = apiClient.Lab() } _, err := client.Pipelines.DeletePipeline(projectID, pipeID) if err != nil { return err } return nil }
var DeleteProject = func(client *gitlab.Client, projectID interface{}) (*gitlab.Response, error) { if client == nil { client = apiClient.Lab() } project, err := client.Projects.DeleteProject(projectID) if err != nil { return nil, err } return project, nil }
var DeleteProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, scope string) error { if client == nil { client = apiClient.Lab() } reqOpts := &gitlab.RemoveProjectVariableOptions{ Filter: &gitlab.VariableFilter{ EnvironmentScope: scope, }, } _, err := client.ProjectVariables.RemoveVariable(projectID, key, reqOpts) if err != nil { return err } return nil }
var DownloadArtifactJob = func(client *gitlab.Client, repo string, ref string, opts *gitlab.DownloadArtifactsFileOptions) (*bytes.Reader, error) { if client == nil { client = apiClient.Lab() } if opts == nil { opts = &gitlab.DownloadArtifactsFileOptions{} } jobs, _, err := client.Jobs.DownloadArtifactsFile(repo, ref, opts, nil) if err != nil { return nil, err } return jobs, nil }
var ErasePipelineJob = func(client *gitlab.Client, pid int, repo string) (*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } pipe, _, err := client.Jobs.EraseJob(repo, pid) if err != nil { return nil, err } return pipe, nil }
var ErrTodoExists = errors.New("To-do already exists.")
var ForkProject = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ForkProjectOptions) (*gitlab.Project, error) { if client == nil { client = apiClient.Lab() } project, _, err := client.Projects.ForkProject(projectID, opts) if err != nil { return nil, err } return project, nil }
var GetCommit = func(client *gitlab.Client, repo string, ref string) (*gitlab.Commit, error) { if client == nil { client = apiClient.Lab() } c, _, err := client.Commits.GetCommit(repo, ref) if err != nil { return nil, err } return c, nil }
var GetCommitStatuses = func(client *gitlab.Client, pid interface{}, sha string) ([]*gitlab.CommitStatus, error) { if client == nil { client = apiClient.Lab() } opt := &gitlab.GetCommitStatusesOptions{ All: gitlab.Bool(true), } statuses, _, err := client.Commits.GetCommitStatuses(pid, sha, opt, nil) if err != nil { return nil, err } return statuses, nil }
var GetFile = func(client *gitlab.Client, projectID interface{}, path string, ref string) (*gitlab.File, error) { if client == nil { client = apiClient.Lab() } fileOpts := &gitlab.GetFileOptions{ Ref: &ref, } file, _, err := client.RepositoryFiles.GetFile(projectID, path, fileOpts) if err != nil { return nil, err } return file, nil }
GetFile retrieves a file from repository. Note that file content is Base64 encoded.
var GetGroup = func(client *gitlab.Client, groupID interface{}) (*gitlab.Group, error) { if client == nil { client = apiClient.Lab() } group, _, err := client.Groups.GetGroup(groupID, &gitlab.GetGroupOptions{}) if err != nil { return nil, err } return group, nil }
var GetGroupIssueBoardLists = func(client *gitlab.Client, groupID interface{}, boardID int, opts *gitlab.ListGroupIssueBoardListsOptions) ([]*gitlab.BoardList, error) { if client == nil { client = apiClient.Lab() } boardLists, _, err := client.GroupIssueBoards.ListGroupIssueBoardLists(groupID, boardID, opts) if err != nil { return nil, err } return boardLists, nil }
var GetGroupVariable = func(client *gitlab.Client, groupID interface{}, key string, opts *gitlab.RequestOptionFunc) (*gitlab.GroupVariable, error) { if client == nil { client = apiClient.Lab() } vars, _, err := client.GroupVariables.GetVariable(groupID, key) if err != nil { return nil, err } return vars, nil }
var GetIssue = func(client *gitlab.Client, projectID interface{}, issueID int) (*gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } issue, _, err := client.Issues.GetIssue(projectID, issueID) if err != nil { return nil, err } return issue, nil }
var GetIssueBoardLists = func(client *gitlab.Client, projectID interface{}, boardID int, opts *gitlab.GetIssueBoardListsOptions) ([]*gitlab.BoardList, error) { if client == nil { client = apiClient.Lab() } boardLists, _, err := client.Boards.GetIssueBoardLists(projectID, boardID, opts) if err != nil { return nil, err } return boardLists, nil }
var GetJobs = func(client *gitlab.Client, repo string, opts *gitlab.ListJobsOptions) ([]*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } if opts == nil { opts = &gitlab.ListJobsOptions{} } jobs, _, err := client.Jobs.ListProjectJobs(repo, opts) if err != nil { return nil, err } return jobs, nil }
var GetLastPipeline = func(client *gitlab.Client, repo string, ref string) (*gitlab.PipelineInfo, error) { if client == nil { client = apiClient.Lab() } c, _, err := client.Commits.GetCommit(repo, ref) if err != nil { return nil, err } if c.LastPipeline != nil { return c.LastPipeline, nil } l := &gitlab.ListProjectPipelinesOptions{ Ref: gitlab.String(ref), Sort: gitlab.String("desc"), } l.Page = 1 l.PerPage = 1 pipes, err := GetPipelines(client, l, repo) if err != nil { return nil, err } if len(pipes) == 0 { return nil, errors.New("No pipeline running or available for ref " + ref) } return pipes[0], nil }
var GetMR = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.GetMergeRequestsOptions) (*gitlab.MergeRequest, error) { if client == nil { client = apiClient.Lab() } mr, _, err := client.MergeRequests.GetMergeRequest(projectID, mrID, opts) if err != nil { return nil, err } return mr, nil }
var GetMRApprovalState = func(client *gitlab.Client, projectID interface{}, mrID int, opts ...gitlab.RequestOptionFunc) (*gitlab.MergeRequestApprovalState, error) { if client == nil { client = apiClient.Lab() } mrApprovals, _, err := client.MergeRequestApprovals.GetApprovalState(projectID, mrID, opts...) if err != nil { return nil, err } return mrApprovals, nil }
var GetMRLinkedIssues = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.GetIssuesClosedOnMergeOptions) ([]*gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } mrIssues, _, err := client.MergeRequests.GetIssuesClosedOnMerge(projectID, mrID, opts) if err != nil { return nil, err } return mrIssues, nil }
var GetPipeline = func(client *gitlab.Client, pid int, l *gitlab.RequestOptionFunc, repo interface{}) (*gitlab.Pipeline, error) { if client == nil { client = apiClient.Lab() } pipe, _, err := client.Pipelines.GetPipeline(repo, pid) if err != nil { return nil, err } return pipe, nil }
var GetPipelineFromBranch = func(client *gitlab.Client, ref, repo string) ([]*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } var err error if ref == "" { ref, err = git.CurrentBranch() if err != nil { return nil, err } } l := &gitlab.ListProjectPipelinesOptions{ Ref: gitlab.String(ref), Sort: gitlab.String("desc"), } l.Page = 1 l.PerPage = 1 pipeline, err := GetLastPipeline(client, repo, ref) if err != nil { return nil, err } jobs, err := GetPipelineJobs(client, pipeline.ID, repo) if err != nil { return nil, err } return jobs, nil }
var GetPipelineJob = func(client *gitlab.Client, jid int, repo string) (*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } job, _, err := client.Jobs.GetJob(repo, jid) return job, err }
var GetPipelineJobLog = func(client *gitlab.Client, jobID int, repo string) (io.Reader, error) { if client == nil { client = apiClient.Lab() } pipeJoblog, _, err := client.Jobs.GetTraceFile(repo, jobID) if err != nil { return nil, err } return pipeJoblog, nil }
var GetPipelineJobs = func(client *gitlab.Client, pid int, repo string) ([]*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } pipeJobs := make([]*gitlab.Job, 0, 10) listOptions := &gitlab.ListJobsOptions{ ListOptions: gitlab.ListOptions{ PerPage: 100, }, } for { pageJobs, resp, err := client.Jobs.ListPipelineJobs(repo, pid, listOptions) if err != nil { return nil, err } pipeJobs = append(pipeJobs, pageJobs...) if resp.CurrentPage == resp.TotalPages { break } listOptions.Page = resp.NextPage if resp.CurrentPage >= resp.TotalPages { break } } return pipeJobs, nil }
var GetPipelineVariables = func(client *gitlab.Client, pid int, l *gitlab.RequestOptionFunc, projectID int) ([]*gitlab.PipelineVariable, error) { if client == nil { client = apiClient.Lab() } pipelineVars, _, err := client.Pipelines.GetPipelineVariables(projectID, pid) if err != nil { return nil, err } return pipelineVars, nil }
var GetPipelines = func(client *gitlab.Client, l *gitlab.ListProjectPipelinesOptions, repo interface{}) ([]*gitlab.PipelineInfo, error) { if client == nil { client = apiClient.Lab() } if l.PerPage == 0 { l.PerPage = DefaultListLimit } pipes, _, err := client.Pipelines.ListProjectPipelines(repo, l) if err != nil { return nil, err } return pipes, nil }
var GetProject = func(client *gitlab.Client, projectID interface{}) (*gitlab.Project, error) { if client == nil { client = apiClient.Lab() } opts := &gitlab.GetProjectOptions{ Statistics: gitlab.Bool(true), License: gitlab.Bool(true), WithCustomAttributes: gitlab.Bool(true), } project, _, err := client.Projects.GetProject(projectID, opts) if err != nil { return nil, err } return project, nil }
var GetProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, scope string) (*gitlab.ProjectVariable, error) { if client == nil { client = apiClient.Lab() } reqOpts := &gitlab.GetProjectVariableOptions{ Filter: &gitlab.VariableFilter{ EnvironmentScope: scope, }, } vars, _, err := client.ProjectVariables.GetVariable(projectID, key, reqOpts) if err != nil { return nil, err } return vars, nil }
var GetRelease = func(client *gitlab.Client, projectID interface{}, tag string) (*gitlab.Release, error) { if client == nil { client = apiClient.Lab() } release, _, err := client.Releases.GetRelease(projectID, tag) if err != nil { return nil, err } return release, nil }
var GetSchedules = func(client *gitlab.Client, l *gitlab.ListPipelineSchedulesOptions, repo string) ([]*gitlab.PipelineSchedule, error) { if client == nil { client = apiClient.Lab() } if l.PerPage == 0 { l.PerPage = DefaultListLimit } schedules, _, err := client.PipelineSchedules.ListPipelineSchedules(repo, l) if err != nil { return nil, err } return schedules, nil }
var GetSinglePipeline = func(client *gitlab.Client, pid int, repo string) (*gitlab.Pipeline, error) { if client == nil { client = apiClient.Lab() } pipes, _, err := client.Pipelines.GetPipeline(repo, pid) if err != nil { return nil, err } return pipes, nil }
var LinkIssues = func(client *gitlab.Client, projectID interface{}, issueIDD int, opts *gitlab.CreateIssueLinkOptions) (*gitlab.Issue, *gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } issueLink, _, err := client.IssueLinks.CreateIssueLink(projectID, issueIDD, opts) if err != nil { return nil, nil, err } return issueLink.SourceIssue, issueLink.TargetIssue, nil }
var ListAllMilestones = func(client *gitlab.Client, projectID interface{}, 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 ListGroupIssueBoards = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupIssueBoardsOptions) ([]*gitlab.GroupIssueBoard, error) { if client == nil { client = apiClient.Lab() } boards, _, err := client.GroupIssueBoards.ListGroupIssueBoards(groupID, opts) if err != nil { return nil, err } return boards, nil }
var ListGroupIssues = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupIssuesOptions) ([]*gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } issues, _, err := client.Issues.ListGroupIssues(groupID, opts) if err != nil { return nil, err } return issues, nil }
var ListGroupMRs = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupMergeRequestsOptions) ([]*gitlab.MergeRequest, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } mrs, _, err := client.MergeRequests.ListGroupMergeRequests(groupID, opts) if err != nil { return nil, err } return mrs, nil }
var ListGroupMilestones = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupMilestonesOptions) ([]*gitlab.GroupMilestone, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } milestone, _, err := client.GroupMilestones.ListGroupMilestones(groupID, opts) if err != nil { return nil, err } return milestone, nil }
var ListGroupProjects = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupProjectsOptions) ([]*gitlab.Project, *gitlab.Response, error) { if client == nil { client = apiClient.Lab() } project, resp, err := client.Groups.ListGroupProjects(groupID, opts) if err != nil { return nil, nil, err } return project, resp, nil }
var ListGroupVariables = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupVariablesOptions) ([]*gitlab.GroupVariable, error) { if client == nil { client = apiClient.Lab() } vars, _, err := client.GroupVariables.ListVariables(groupID, opts) if err != nil { return nil, err } return vars, nil }
var ListIssueBoards = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListIssueBoardsOptions) ([]*gitlab.IssueBoard, error) { if client == nil { client = apiClient.Lab() } boards, _, err := client.Boards.ListIssueBoards(projectID, opts) if err != nil { return nil, err } return boards, nil }
var ListIssueNotes = func(client *gitlab.Client, projectID interface{}, issueID int, opts *gitlab.ListIssueNotesOptions) ([]*gitlab.Note, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } notes, _, err := client.Notes.ListIssueNotes(projectID, issueID, opts) if err != nil { return nil, err } return notes, nil }
var ListIssues = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectIssuesOptions) ([]*gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } issues, _, err := client.Issues.ListProjectIssues(projectID, opts) if err != nil { return nil, err } return issues, nil }
var ListLabels = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListLabelsOptions) ([]*gitlab.Label, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } label, _, err := client.Labels.ListLabels(projectID, opts) if err != nil { return nil, err } return label, nil }
var ListMRNotes = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.ListMergeRequestNotesOptions) ([]*gitlab.Note, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } notes, _, err := client.Notes.ListMergeRequestNotes(projectID, mrID, opts) if err != nil { return notes, err } return notes, nil }
var ListMRs = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectMergeRequestsOptions) ([]*gitlab.MergeRequest, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } mrs, _, err := client.MergeRequests.ListProjectMergeRequests(projectID, opts) if err != nil { return nil, err } return mrs, nil }
var ListMRsWithAssigneesOrReviewers = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectMergeRequestsOptions, assigneeIds []int, reviewerIds []int) ([]*gitlab.MergeRequest, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } mrs := make([]*gitlab.MergeRequest, 0) for _, id := range assigneeIds { opts.AssigneeID = gitlab.AssigneeID(id) assingeMrs, err := ListMRs(client, projectID, opts) if err != nil { return nil, err } mrs = append(mrs, assingeMrs...) } opts.AssigneeID = nil for _, id := range reviewerIds { opts.ReviewerID = gitlab.ReviewerID(id) reviewerMrs, err := ListMRs(client, projectID, opts) if err != nil { return nil, err } mrs = append(mrs, reviewerMrs...) } return mrs, nil }
var ListProjectMembers = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectMembersOptions) ([]*gitlab.ProjectMember, error) { if client == nil { client = apiClient.Lab() } members, _, err := client.ProjectMembers.ListAllProjectMembers(projectID, opts) if err != nil { return nil, err } return members, nil }
var ListProjectMilestones = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListMilestonesOptions) ([]*gitlab.Milestone, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } milestone, _, err := client.Milestones.ListMilestones(projectID, opts) if err != nil { return nil, err } return milestone, nil }
var ListProjectPipelines = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectPipelinesOptions) ([]*gitlab.PipelineInfo, error) { if client == nil { client = apiClient.Lab() } pipes, _, err := client.Pipelines.ListProjectPipelines(projectID, opts) if err != nil { return pipes, err } return pipes, nil }
var ListProjectVariables = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectVariablesOptions) ([]*gitlab.ProjectVariable, error) { if client == nil { client = apiClient.Lab() } vars, _, err := client.ProjectVariables.ListVariables(projectID, opts) if err != nil { return nil, err } return vars, nil }
var ListProjectsGroups = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectGroupOptions) ([]*gitlab.ProjectGroup, error) { if client == nil { client = apiClient.Lab() } groups, _, err := client.Projects.ListProjectsGroups(projectID, opts) if err != nil { return nil, err } return groups, nil }
var ListReleases = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListReleasesOptions) ([]*gitlab.Release, error) { if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } releases, _, err := client.Releases.ListReleases(projectID, opts) if err != nil { return nil, err } return releases, nil }
var MRTodo = func(client *gitlab.Client, projectID interface{}, mrID int, opts gitlab.RequestOptionFunc) (*gitlab.Todo, error) { if client == nil { client = apiClient.Lab() } mr, resp, err := client.MergeRequests.CreateTodo(projectID, mrID, opts) if resp.StatusCode == http.StatusNotModified { return nil, ErrTodoExists } if err != nil { return nil, err } return mr, nil }
var MergeMR = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.AcceptMergeRequestOptions) (*gitlab.MergeRequest, *gitlab.Response, error) { if client == nil { client = apiClient.Lab() } mrs, resp, err := client.MergeRequests.AcceptMergeRequest(projectID, mrID, opts) if err != nil { return nil, resp, err } return mrs, resp, nil }
var PipelineCILint = func(client *gitlab.Client, content string) (*gitlab.LintResult, error) { if client == nil { client = apiClient.Lab() } c, _, err := client.Validate.Lint(&gitlab.LintOptions{Content: content}) if err != nil { return nil, err } return c, nil }
var PipelineJobWithSha = func(client *gitlab.Client, pid interface{}, sha, name string) (*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } jobs, err := PipelineJobsWithSha(client, pid, sha) if len(jobs) == 0 || err != nil { return nil, err } var ( job *gitlab.Job lastRunning *gitlab.Job firstPending *gitlab.Job ) for _, j := range jobs { if j.Status == "running" { lastRunning = j } if j.Status == "pending" && firstPending == nil { firstPending = j } if j.Name == name { job = j } } if job == nil { job = lastRunning } if job == nil { job = firstPending } if job == nil { job = jobs[len(jobs)-1] } return job, err }
var PipelineJobsWithSha = func(client *gitlab.Client, pid interface{}, sha string) ([]*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } pipelines, err := GetPipelines(client, &gitlab.ListProjectPipelinesOptions{ SHA: gitlab.String(sha), }, pid) if len(pipelines) == 0 || err != nil { return nil, err } target := pipelines[0].ID opts := &gitlab.ListJobsOptions{ ListOptions: gitlab.ListOptions{ PerPage: 500, }, } jobsList := make([]*gitlab.Job, 0) for { jobs, resp, err := client.Jobs.ListPipelineJobs(pid, target, opts) if err != nil { return nil, err } opts.Page = resp.NextPage jobsList = append(jobsList, jobs...) if resp.CurrentPage == resp.TotalPages { break } } sort.Sort(JobSort{Jobs: jobsList}) return jobsList, nil }
PipelineJobsWithSha returns a list of jobs in a pipeline for a given commit sha. The jobs are returned in the order in which they were created
var PlayOrRetryJobs = func(client *gitlab.Client, repo string, jobID int, status string) (*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } switch status { case "pending", "running": return nil, nil case "manual": j, err := PlayPipelineJob(client, jobID, repo) if err != nil { return nil, err } return j, nil default: j, err := RetryPipelineJob(client, jobID, repo) if err != nil { return nil, err } return j, nil } }
var PlayPipelineJob = func(client *gitlab.Client, pid int, repo string) (*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } playOptions := gitlab.PlayJobOptions{} pipe, _, err := client.Jobs.PlayJob(repo, pid, &playOptions) if err != nil { return nil, err } return pipe, nil }
var ProjectListIssueOptionsToGroup = func(l *gitlab.ListProjectIssuesOptions) *gitlab.ListGroupIssuesOptions {
return &gitlab.ListGroupIssuesOptions{
ListOptions: l.ListOptions,
State: l.State,
Labels: l.Labels,
NotLabels: l.NotLabels,
WithLabelDetails: l.WithLabelDetails,
IIDs: l.IIDs,
Milestone: l.Milestone,
Scope: l.Scope,
AuthorID: l.AuthorID,
NotAuthorID: l.NotAuthorID,
AssigneeID: l.AssigneeID,
NotAssigneeID: l.NotAssigneeID,
AssigneeUsername: l.AssigneeUsername,
MyReactionEmoji: l.MyReactionEmoji,
NotMyReactionEmoji: l.NotMyReactionEmoji,
OrderBy: l.OrderBy,
Sort: l.Sort,
Search: l.Search,
In: l.In,
CreatedAfter: l.CreatedAfter,
CreatedBefore: l.CreatedBefore,
UpdatedAfter: l.UpdatedAfter,
UpdatedBefore: l.UpdatedBefore,
IssueType: l.IssueType,
}
}
var ProjectListMROptionsToGroup = func(l *gitlab.ListProjectMergeRequestsOptions) *gitlab.ListGroupMergeRequestsOptions {
return &gitlab.ListGroupMergeRequestsOptions{
ListOptions: l.ListOptions,
State: l.State,
OrderBy: l.OrderBy,
Sort: l.Sort,
Milestone: l.Milestone,
View: l.View,
Labels: l.Labels,
NotLabels: l.NotLabels,
WithLabelsDetails: l.WithLabelsDetails,
WithMergeStatusRecheck: l.WithMergeStatusRecheck,
CreatedAfter: l.CreatedAfter,
CreatedBefore: l.CreatedBefore,
UpdatedAfter: l.UpdatedAfter,
UpdatedBefore: l.UpdatedBefore,
Scope: l.Scope,
AuthorID: l.AuthorID,
AssigneeID: l.AssigneeID,
ReviewerID: l.ReviewerID,
ReviewerUsername: l.ReviewerUsername,
MyReactionEmoji: l.MyReactionEmoji,
SourceBranch: l.SourceBranch,
TargetBranch: l.TargetBranch,
Search: l.Search,
WIP: l.WIP,
}
}
var ProjectMilestoneByTitle = func(client *gitlab.Client, projectID interface{}, name string) (*gitlab.Milestone, error) { opts := &gitlab.ListMilestonesOptions{Title: gitlab.String(name)} if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } milestones, _, err := client.Milestones.ListMilestones(projectID, opts) if err != nil { return nil, err } if len(milestones) != 1 { return nil, fmt.Errorf("failed to find milestone by title: %s", name) } return milestones[0], nil }
var RebaseMR = func(client *gitlab.Client, projectID interface{}, mrID int, opts gitlab.RequestOptionFunc) error { if client == nil { client = apiClient.Lab() } _, err := client.MergeRequests.RebaseMergeRequest(projectID, mrID, opts) if err != nil { return err } return nil }
var RetryPipeline = func(client *gitlab.Client, pid int, repo string) (*gitlab.Pipeline, error) { if client == nil { client = apiClient.Lab() } pipe, _, err := client.Pipelines.RetryPipelineBuild(repo, pid) if err != nil { return nil, err } return pipe, nil }
var RetryPipelineJob = func(client *gitlab.Client, pid int, repo string) (*gitlab.Job, error) { if client == nil { client = apiClient.Lab() } pipe, _, err := client.Jobs.RetryJob(repo, pid) if err != nil { return nil, err } return pipe, nil }
var RunSchedule = func(client *gitlab.Client, repo string, schedule int, opts ...gitlab.RequestOptionFunc) error { if client == nil { client = apiClient.Lab() } _, err := client.PipelineSchedules.RunPipelineSchedule(repo, schedule, opts...) if err != nil { return fmt.Errorf("running scheduled pipeline status: %w", err) } return nil }
var SetIssueTimeEstimate = func(client *gitlab.Client, projectID interface{}, issueIDD int, opts *gitlab.SetTimeEstimateOptions) (*gitlab.TimeStats, error) { if client == nil { client = apiClient.Lab() } timeStats, _, err := client.Issues.SetTimeEstimate(projectID, issueIDD, opts) if err != nil { return nil, err } return timeStats, nil }
var SubscribeToIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts gitlab.RequestOptionFunc) (*gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } issue, resp, err := client.Issues.SubscribeToIssue(projectID, issueID, opts) if err != nil { if resp != nil { if resp.StatusCode == http.StatusNotModified { return nil, errors.New("you are already subscribed to this issue") } } return issue, err } return issue, nil }
var SubscribeToMR = func(client *gitlab.Client, projectID interface{}, mrID int, opts gitlab.RequestOptionFunc) (*gitlab.MergeRequest, error) { if client == nil { client = apiClient.Lab() } mr, _, err := client.MergeRequests.SubscribeToMergeRequest(projectID, mrID, opts) if err != nil { return nil, err } return mr, nil }
var UnapproveMR = func(client *gitlab.Client, projectID interface{}, mrID int) error { if client == nil { client = apiClient.Lab() } _, err := client.MergeRequestApprovals.UnapproveMergeRequest(projectID, mrID) if err != nil { return err } return nil }
var UnsubscribeFromIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts gitlab.RequestOptionFunc) (*gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } issue, resp, err := client.Issues.UnsubscribeFromIssue(projectID, issueID, opts) if err != nil { if resp != nil { if resp.StatusCode == http.StatusNotModified { return nil, errors.New("you are not subscribed to this issue") } } return issue, err } return issue, nil }
var UnsubscribeFromMR = func(client *gitlab.Client, projectID interface{}, mrID int, opts gitlab.RequestOptionFunc) (*gitlab.MergeRequest, error) { if client == nil { client = apiClient.Lab() } mr, _, err := client.MergeRequests.UnsubscribeFromMergeRequest(projectID, mrID, opts) if err != nil { return nil, err } return mr, nil }
var UpdateGroupVariable = func(client *gitlab.Client, groupID interface{}, key string, opts *gitlab.UpdateGroupVariableOptions) (*gitlab.GroupVariable, error) { if client == nil { client = apiClient.Lab() } vars, _, err := client.GroupVariables.UpdateVariable(groupID, key, opts) if err != nil { return nil, err } return vars, nil }
var UpdateIssue = func(client *gitlab.Client, projectID interface{}, issueID int, opts *gitlab.UpdateIssueOptions) (*gitlab.Issue, error) { if client == nil { client = apiClient.Lab() } issue, _, err := client.Issues.UpdateIssue(projectID, issueID, opts) if err != nil { return nil, err } return issue, nil }
var UpdateMR = func(client *gitlab.Client, projectID interface{}, mrID int, opts *gitlab.UpdateMergeRequestOptions) (*gitlab.MergeRequest, error) { if client == nil { client = apiClient.Lab() } mr, _, err := client.MergeRequests.UpdateMergeRequest(projectID, mrID, opts) if err != nil { return nil, err } return mr, nil }
var UpdateProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, opts *gitlab.UpdateProjectVariableOptions) (*gitlab.ProjectVariable, error) { if client == nil { client = apiClient.Lab() } filter := func(request *retryablehttp.Request) error { q := request.URL.Query() q.Add("filter[environment_scope]", *opts.EnvironmentScope) request.URL.RawQuery = q.Encode() return nil } vars, _, err := client.ProjectVariables.UpdateVariable(projectID, key, opts, filter) if err != nil { return nil, err } return vars, nil }
var UserByName = func(client *gitlab.Client, name string) (*gitlab.User, error) { opts := &gitlab.ListUsersOptions{Username: gitlab.String(name)} if client == nil { client = apiClient.Lab() } if opts.PerPage == 0 { opts.PerPage = DefaultListLimit } if name == "@me" { return CurrentUser(client) } users, _, err := client.Users.ListUsers(opts) if err != nil { return nil, err } if len(users) != 1 { return nil, fmt.Errorf("failed to find user by name : %s", name) } return users[0], nil }
var UsersByNames = func(client *gitlab.Client, names []string) ([]*gitlab.User, error) { users := make([]*gitlab.User, 0) for _, name := range names { user, err := UserByName(client, name) if err != nil { return nil, err } users = append(users, user) } return users, nil }
Functions ¶
func HTTPClient ¶
HTTPClient returns the httpClient instance used to initialise the gitlab api client
func IsValidToken ¶
IsValidToken checks if a token provided is valid. The token string must be 26 characters in length and have the 'glpat-' prefix or just be 20 characters long to be recognized as a valid personal access token.
TODO: check if token has minimum scopes required by glab
func NewHTTPRequest ¶
func OverrideHTTPClient ¶
OverrideHTTPClient overrides the default http client
func SetProtocol ¶
func SetProtocol(protocol string)
func SetUserAgent ¶ added in v1.26.0
Types ¶
type Client ¶
type Client struct { // LabClient represents GitLab API client. // Note: this is exported for tests. Do not access it directly. Use Lab() method LabClient *gitlab.Client // Token type used to make authenticated API calls. AuthType authType // Protocol: host url protocol to make requests. Default is https Protocol string // contains filtered or unexported fields }
Client represents an argument to NewClient
func NewClientWithCfg ¶
func NewClientWithCfg(repoHost string, cfg config.Config, isGraphQL bool) (client *Client, err error)
NewClientWithCfg initializes the global api with the config data
func NewClientWithCustomCA ¶
NewClientWithCustomCA initializes the global api client with a self-signed certificate
func NewClientWithCustomCAClientCert ¶
func NewClientWithCustomCAClientCert(host, token, caFile string, certFile string, keyFile string, isGraphQL bool) (*Client, error)
NewClientWithCustomCAClientCert initializes the global api client with a self-signed certificate and client certificates
func TestClient ¶
func (*Client) HTTPClient ¶
func (*Client) Lab ¶
func (c *Client) Lab() *gitlab.Client
Lab returns the initialized GitLab client. Initializes a new GitLab Client if not initialized but error is ignored
func (*Client) OverrideHTTPClient ¶
func (*Client) SetProtocol ¶
type CreatePullMirrorOptions ¶
type CreatePushMirrorOptions ¶
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
func NewProjectMilestone ¶
func NewProjectMilestone(m *gitlab.Milestone) *Milestone