Documentation
¶
Overview ¶
Package gitlab provides GitLab API client functionality.
Index ¶
- Constants
- Variables
- func SetLogger(l Logger)
- func UnmarshalErrorMessage(body []byte) error
- type ErrorMessage
- type Group
- type Logger
- type Project
- type ProjectAccessToken
- 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) SetHTTPClient(httpClient *http.Client)
- 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. DownloadRateLimitIntervalSeconds = 60 // DownloadRateLimitBurst defines the burst limit for download API calls. DownloadRateLimitBurst = 1 // ExportRateLimitIntervalSeconds defines the rate limit interval for export API calls. 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 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 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 ProjectAccessToken ¶ added in v1.10.0
type ProjectAccessToken struct {
ID int `json:"id"`
Name string `json:"name"`
Revoked bool `json:"revoked"`
CreatedAt string `json:"created_at"`
Scopes []string `json:"scopes"`
UserID int `json:"user_id"`
LastUsedAt string `json:"last_used_at"`
Active bool `json:"active"`
ExpiresAt string `json:"expires_at"`
AccessLevel int `json:"access_level"`
}
ProjectAccessToken represents a GitLab project access token.
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/
func (*Service) SetHTTPClient ¶ added in v1.11.0
SetHTTPClient sets the http client default: http.Client{}