Documentation
¶
Overview ¶
Package gitlab provides GitLab API client functionality.
Index ¶
- Constants
- Variables
- func SetLogger(l Logger)
- func UnmarshalErrorMessage(body []byte) error
- type ErrorMessage
- type GitLabClient
- type Group
- type GroupsService
- type Logger
- type Project
- type ProjectImportExportService
- type ProjectsService
- type Service
- func (s *Service) ExportProject(ctx context.Context, project *Project, archiveFilePath string) error
- func (r *Service) GetGroup(ctx context.Context, groupID int) (Group, error)
- func (r *Service) GetProject(ctx context.Context, projectID int) (Project, error)
- func (s *Service) GetProjectsLst(ctx context.Context, groupID int) ([]Project, error)
- func (s *Service) GetProjectsOfGroup(ctx context.Context, groupID int) ([]Project, error)
- func (s *Service) GetSubgroups(ctx context.Context, groupID int) ([]Group, error)
- func (r *Service) SetGitlabEndpoint(gitlabAPIEndpoint string)
- func (r *Service) SetToken(token string)
Constants ¶
const ( // GitlabAPIEndpoint is the default GitLab API endpoint. GitlabAPIEndpoint = "https://gitlab.com/api/v4" // DownloadRateLimitIntervalSeconds defines the rate limit interval for download API calls. // Based on GitLab repository files API limit: 5 requests per minute per user DownloadRateLimitIntervalSeconds = 60 // DownloadRateLimitBurst defines the burst limit for download API calls. DownloadRateLimitBurst = 5 // ExportRateLimitIntervalSeconds defines the rate limit interval for export API calls. // Based on GitLab project import/export API limit: 6 requests per minute per user ExportRateLimitIntervalSeconds = 60 // ExportRateLimitBurst defines the burst limit for export API calls. ExportRateLimitBurst = 6 )
const ( // ExportCheckIntervalSeconds defines the interval between export status checks. ExportCheckIntervalSeconds = 5 // MaxExportRetries defines the maximum number of export retries. MaxExportRetries = 5 )
Variables ¶
var ( // ErrUnmarshalJSON is returned when JSON unmarshalling fails. ErrUnmarshalJSON = errors.New("error unmarshalling json") // ErrGitlabAPI is returned when GitLab API returns an error. ErrGitlabAPI = errors.New("error message from Gitlab API") )
var ( // ErrExportTimeout is returned when timeout occurs waiting for GitLab to start project export. ErrExportTimeout = errors.New("timeout waiting for gitlab to start the export project") // ErrRateLimit is returned when rate limit is exceeded. ErrRateLimit = errors.New("rate limit error") )
var ( // ErrHTTPStatusCode is returned when an unexpected HTTP status code is received. ErrHTTPStatusCode = errors.New("unexpected HTTP status code") )
Functions ¶
func UnmarshalErrorMessage ¶ added in v1.10.0
UnmarshalErrorMessage unmarshals the error message from the Gitlab API.
Types ¶
type ErrorMessage ¶ added in v1.5.0
type ErrorMessage struct {
Message string `json:"message"`
}
ErrorMessage is a struct that contains an error message. It is returned by the Gitlab API when an error occurs.
type GitLabClient ¶ added in v1.13.0
type GitLabClient interface { Groups() GroupsService Projects() ProjectsService ProjectImportExport() ProjectImportExportService }
GitLabClient defines the interface for GitLab client operations.
func NewGitLabClientWrapper ¶ added in v1.13.0
func NewGitLabClientWrapper(client *gitlab.Client) GitLabClient
NewGitLabClientWrapper creates a new wrapper around the official GitLab client.
type Group ¶ added in v1.11.0
Group represents a Gitlab group https://docs.gitlab.com/ee/api/groups.html struct fields are not exhaustive - most of them won't be used.
type GroupsService ¶ added in v1.13.0
type GroupsService interface { //nolint:lll // GitLab API method signatures are inherently long GetGroup(gid interface{}, opt *gitlab.GetGroupOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Group, *gitlab.Response, error) //nolint:lll // GitLab API method signatures are inherently long ListSubGroups(gid interface{}, opt *gitlab.ListSubGroupsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Group, *gitlab.Response, error) //nolint:lll // GitLab API method signatures are inherently long ListGroupProjects(gid interface{}, opt *gitlab.ListGroupProjectsOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.Project, *gitlab.Response, error) }
GroupsService defines the interface for GitLab Groups API operations.
type Logger ¶
type Logger interface { Debug(msg string, args ...any) Warn(msg string, args ...any) Error(msg string, args ...any) Info(msg string, args ...any) }
Logger interface defines the logging methods used by GitLab service.
type Project ¶ added in v1.11.0
type Project struct { ID int `json:"id"` Name string `json:"name"` Archived bool `json:"archived"` ExportStatus string `json:"export_status"` }
Project represents a Gitlab project https://docs.gitlab.com/ee/api/projects.html struct fields are not exhaustive - most of them won't be used.
type ProjectImportExportService ¶ added in v1.13.0
type ProjectImportExportService interface { //nolint:lll // GitLab API method signatures are inherently long ScheduleExport(pid interface{}, opt *gitlab.ScheduleExportOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Response, error) ExportStatus(pid interface{}, options ...gitlab.RequestOptionFunc) (*gitlab.ExportStatus, *gitlab.Response, error) ExportDownload(pid interface{}, options ...gitlab.RequestOptionFunc) ([]byte, *gitlab.Response, error) }
ProjectImportExportService defines the interface for GitLab Project Import/Export API operations.
type ProjectsService ¶ added in v1.13.0
type ProjectsService interface { //nolint:lll // GitLab API method signatures are inherently long GetProject(pid interface{}, opt *gitlab.GetProjectOptions, options ...gitlab.RequestOptionFunc) (*gitlab.Project, *gitlab.Response, error) }
ProjectsService defines the interface for GitLab Projects API operations.
type Service ¶ added in v1.11.0
type Service struct {
// contains filtered or unexported fields
}
Service provides methods to interact with GitLab API.
func (*Service) ExportProject ¶ added in v1.11.0
func (s *Service) ExportProject(ctx context.Context, project *Project, archiveFilePath string) error
ExportProject exports the project to the given archive file path.
func (*Service) GetProject ¶ added in v1.11.0
GetProject returns informations of the project that matches the given ID.
func (*Service) GetProjectsLst ¶ added in v1.11.0
GetProjectsLst returns the list of projects of the group.
func (*Service) GetProjectsOfGroup ¶ added in v1.11.0
GetProjectsOfGroup returns the list of every projects of the group and subgroups.
func (*Service) GetSubgroups ¶ added in v1.11.0
GetSubgroups returns the list of subgroups of the group. It's a recursive function that will return all subgroups of the group.
func (*Service) SetGitlabEndpoint ¶ added in v1.11.0
SetGitlabEndpoint sets the Gitlab API endpoint default: https://gitlab.com/v4/api/