gitlab

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("gitlan client is missing credentials to run, you need at least `read_api`")
View Source
var ErrNoRFC5988LinkHeader = errors.New("given string is not valid under RFC5988")
View Source
var ErrRawFileNotFound = errors.New("raw file was not found")
View Source
var ErrUnauthorised = errors.New("gitlab client is missing valid credentials")

Functions

This section is empty.

Types

type Client

type Client struct {
	Host     string
	Token    string
	HTTPDoer HTTPDoer
	Logger   zerolog.Logger
}

Client holds all authentication and setup information for the GitLab connection.

func NewClient

func NewClient(host, token string, httpDoer HTTPDoer, logger zerolog.Logger) *Client

NewClient sets up a client struct for all relevant GitLab auth you can give it a custom http.Client as well for things like timeouts.

func (*Client) GetProjectFromPath added in v0.13.2

func (c *Client) GetProjectFromPath(ctx context.Context, projectPath string) (Project, error)

func (*Client) GetRawFileFromProject

func (c *Client) GetRawFileFromProject(ctx context.Context, projectID int, fileName, ref string) ([]byte, error)

GetRawFileFromProject wraps around the raw file endpoint of GitLab helping to fetch files from specific repos it will throw a typed ErrRawFileNotFound when it encounters a 404 response which you can errors.Is for to have cleaner logs.

func (*Client) StreamAllProjects

func (c *Client) StreamAllProjects(ctx context.Context, pageSize int, projectsChan chan<- Project) error

StreamAllProjects iterates through all projects in a GitLab and streams them in batches of pageSize into the projectsChan. Due to this you want to buffer the projectsChan channel to something like 2 x pageSize depending on the speed and complexity of your consuming function. The authentication check retries for max 30s using an exponential backoff but will exit immediately if a 401 has been returned. All calls after this are not retried and a failing API call will stop the stream currently.

type HTTPDoer

type HTTPDoer interface {
	Do(r *http.Request) (*http.Response, error)
}

type ParseError

type ParseError struct {
	Header string
	Err    error
}

func (*ParseError) Error

func (pe *ParseError) Error() string

func (*ParseError) Unwrap

func (pe *ParseError) Unwrap() error

type Project

type Project struct {
	ID                int    `json:"id"`
	DefaultBranch     string `json:"default_branch"`
	PathWithNamespace string `json:"path_with_namespace"`
}

Project is a minimalist representation of a GitLab project from https://docs.gitlab.com/ee/api/projects.html#get-single-project

type RawFileError

type RawFileError struct {
	Err       error
	Msg       string
	File      string
	Ref       string
	ProjectID int
}

func (*RawFileError) Error

func (re *RawFileError) Error() string

func (*RawFileError) Unwrap

func (re *RawFileError) Unwrap() error

Jump to

Keyboard shortcuts

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