gitlab

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: GPL-3.0 Imports: 11 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.
	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
)
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 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 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 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) SetHTTPClient added in v1.11.0

func (r *Service) SetHTTPClient(httpClient *http.Client)

SetHTTPClient sets the http client default: http.Client{}

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