gitlab

package
v14.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowedParams

type AllowedParams struct {
	// RepoPath is an absolute path to the repository.
	RepoPath string
	// GitObjectDirectory is a path to git object directory.
	GitObjectDirectory string
	// GitAlternateObjectDirectories are the paths to alternate object directories.
	GitAlternateObjectDirectories []string
	// GLRepository is a name of the repository.
	GLRepository string
	// GLID is an identifier of the repository.
	GLID string
	// GLProtocol is a protocol used for operation.
	GLProtocol string
	// Changes is a set of changes to be applied.
	Changes string
}

AllowedParams compose set of parameters required to call 'GitlabAPI.Allowed' method.

type CheckInfo

type CheckInfo struct {
	// Version of the GitLab Rails component
	Version string `json:"gitlab_version"`
	// Revision of the Git object of the running GitLab
	Revision string `json:"gitlab_revision"`
	// APIVersion of GitLab, expected to be v4
	APIVersion string `json:"api_version"`
	// RedisReachable shows if GitLab can reach Redis. This can be false
	// while the check itself succeeds. Normal hook API calls will likely
	// fail.
	RedisReachable bool `json:"redis"`
}

CheckInfo represents the response of GitLabs `check` API endpoint

type Client

type Client interface {
	// Allowed queries the gitlab internal api /allowed endpoint to determine if a ref change for a given repository and user is allowed
	Allowed(ctx context.Context, params AllowedParams) (bool, string, error)
	// Check verifies that GitLab can be reached, and authenticated to
	Check(ctx context.Context) (*CheckInfo, error)
	// PreReceive queries the gitlab internal api /pre_receive to increase the reference counter
	PreReceive(ctx context.Context, glRepository string) (bool, error)
	// PostReceive queries the gitlab internal api /post_receive to decrease the reference counter
	PostReceive(ctx context.Context, glRepository, glID, changes string, pushOptions ...string) (bool, []PostReceiveMessage, error)
}

Client is an interface for accessing the GitLab internal API

func NewMockClient

func NewMockClient() Client

NewMockClient returns a new mock client for the internal GitLab API.

type HTTPClient

type HTTPClient struct {
	*client.GitlabNetClient
	// contains filtered or unexported fields
}

HTTPClient is an HTTP client used to talk to the internal GitLab Rails API.

func NewHTTPClient

func NewHTTPClient(
	gitlabCfg config.Gitlab,
	tlsCfg config.TLS,
	promCfg promcfg.Config,
) (*HTTPClient, error)

NewHTTPClient creates an HTTP client to talk to the Rails internal API

func (*HTTPClient) Allowed

func (c *HTTPClient) Allowed(ctx context.Context, params AllowedParams) (bool, string, error)

Allowed checks if a ref change for a given repository is allowed through the gitlab internal api /allowed endpoint

func (*HTTPClient) Check

func (c *HTTPClient) Check(ctx context.Context) (*CheckInfo, error)

Check performs an HTTP request to the internal/check API endpoint to verify the connection and tokens. It returns basic information of the installed GitLab

func (*HTTPClient) Collect

func (c *HTTPClient) Collect(metrics chan<- prometheus.Metric)

Collect collects Prometheus metrics exposed by the HTTPClient.

func (*HTTPClient) Describe

func (c *HTTPClient) Describe(descs chan<- *prometheus.Desc)

Describe describes Prometheus metrics exposed by the HTTPClient.

func (*HTTPClient) PostReceive

func (c *HTTPClient) PostReceive(ctx context.Context, glRepository, glID, changes string, pushOptions ...string) (bool, []PostReceiveMessage, error)

PostReceive decreases the reference counter for a push for a given gl_repository through the gitlab internal API /post_receive endpoint

func (*HTTPClient) PreReceive

func (c *HTTPClient) PreReceive(ctx context.Context, glRepository string) (bool, error)

PreReceive increases the reference counter for a push for a given gl_repository through the gitlab internal API /pre_receive endpoint

type MockClient

type MockClient struct{}

MockClient is a mock client of the internal GitLab API.

func (*MockClient) Allowed

func (m *MockClient) Allowed(ctx context.Context, params AllowedParams) (bool, string, error)

Allowed does nothing and always returns true.

func (*MockClient) Check

func (m *MockClient) Check(ctx context.Context) (*CheckInfo, error)

Check does nothing and always returns a CheckInfo prepopulated with static data.

func (*MockClient) PostReceive

func (m *MockClient) PostReceive(ctx context.Context, glRepository, glID, changes string, gitPushOptions ...string) (bool, []PostReceiveMessage, error)

PostReceive does nothing and always returns true.

func (*MockClient) PreReceive

func (m *MockClient) PreReceive(ctx context.Context, glRepository string) (bool, error)

PreReceive does nothing and always return true.

type PostReceiveMessage

type PostReceiveMessage struct {
	Message string `json:"message"`
	Type    string `json:"type"`
}

PostReceiveMessage encapsulates a message from the /post_receive endpoint that gets printed to stdout

Jump to

Keyboard shortcuts

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