gitlab

package
v1.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gitlab provides GitLab API client functionality.

Index

Constants

View Source
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
)
View Source
const (
	// ExportCheckIntervalSeconds defines the interval between export status checks.
	ExportCheckIntervalSeconds = 5
	// MaxExportRetries defines the maximum number of export retries.
	MaxExportRetries = 5
)

Variables

View Source
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")
)
View Source
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")
)
View Source
var (
	// ErrHTTPStatusCode is returned when an unexpected HTTP status code is received.
	ErrHTTPStatusCode = errors.New("unexpected HTTP status code")
)

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger sets the logger.

func UnmarshalErrorMessage added in v1.10.0

func UnmarshalErrorMessage(body []byte) error

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

type Group struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

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 NewGitlabService

func NewGitlabService() *Service

NewGitlabService returns a new Service.

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) GetGroup added in v1.11.0

func (r *Service) GetGroup(ctx context.Context, groupID int) (Group, error)

GetGroup returns the gitlab group from the given ID.

func (*Service) GetProject added in v1.11.0

func (r *Service) GetProject(ctx context.Context, projectID int) (Project, error)

GetProject returns informations of the project that matches the given ID.

func (*Service) GetProjectsLst added in v1.11.0

func (s *Service) GetProjectsLst(ctx context.Context, groupID int) ([]Project, error)

GetProjectsLst returns the list of projects of the group.

func (*Service) GetProjectsOfGroup added in v1.11.0

func (s *Service) GetProjectsOfGroup(ctx context.Context, groupID int) ([]Project, error)

GetProjectsOfGroup returns the list of every projects of the group and subgroups.

func (*Service) GetSubgroups added in v1.11.0

func (s *Service) GetSubgroups(ctx context.Context, groupID int) ([]Group, error)

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

func (r *Service) SetGitlabEndpoint(gitlabAPIEndpoint string)

SetGitlabEndpoint sets the Gitlab API endpoint default: https://gitlab.com/v4/api/

func (*Service) SetToken added in v1.11.0

func (r *Service) SetToken(token string)

SetToken sets the Gitlab API token default: GITLAB_TOKEN env variable

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL