gitlab

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectInstanceAndProject added in v1.0.0

func DetectInstanceAndProject(dir string) (string, string, error)

DetectInstanceAndProject detects both GitLab instance URL and project path from .git/config. Returns (instanceURL, projectPath, error).

If instance URL cannot be determined, both return values will be empty strings. If project path cannot be determined but instance can, instance URL will be populated and project path will be empty.

func DetectInstanceForFile added in v1.0.0

func DetectInstanceForFile(filePath string) (string, string, error)

DetectInstanceForFile detects the GitLab instance URL for a specific file. It searches upward from the file's directory to find the git repository root.

Returns (instanceURL, projectPath, error). Returns ("", "", nil) if not in a git repository.

func DetectProjectForFile deprecated added in v0.3.0

func DetectProjectForFile(filePath string) (string, error)

DetectProjectForFile attempts to detect the GitLab project for a specific file It searches upward from the file's directory to find the git repository root Handles both regular git repos and git submodules

Deprecated: Use DetectInstanceForFile instead, which returns both instance and project.

func DetectProjectFromGitRepo added in v0.3.0

func DetectProjectFromGitRepo(dir string) (string, error)

DetectProjectFromGitRepo attempts to detect the GitLab project path from a git repository It reads .git/config and extracts the project path from remote.origin.url Returns empty string if not a git repo or cannot determine the project

func ExtractTokenFromNetrc

func ExtractTokenFromNetrc(instance string) (string, error)

ExtractTokenFromNetrc attempts to find credentials for the given host in .netrc file

The .netrc file format:

machine <host> login <username> password <token>
machine gitlab.com login gitlab-ci-lint password glpat-...

This function searches for a matching machine entry and returns the password field. Returns empty string with no error if .netrc doesn't exist or has no matching entry. Returns error only if .netrc exists but cannot be read.

func NormalizeInstanceURL

func NormalizeInstanceURL(instance string) string

NormalizeInstanceURL ensures the instance URL has a proper format

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a GitLab API client

func NewClient

func NewClient(instance, token string, timeout time.Duration) *Client

NewClient creates a new GitLab API client

func (*Client) Lint

func (c *Client) Lint(ctx context.Context, content []byte, projectRef string, debug DebugLogger) (*LintResponse, error)

Lint validates a CI configuration using the GitLab API

func (*Client) ValidateToken

func (c *Client) ValidateToken(ctx context.Context) error

ValidateToken checks if the current token is valid by making a simple API call

type ClientRegistry added in v1.0.0

type ClientRegistry struct {
	// contains filtered or unexported fields
}

ClientRegistry manages multiple GitLab clients for different instances. It provides automatic routing of files to their corresponding GitLab instances based on .git/config detection.

func NewClientRegistry added in v1.0.0

func NewClientRegistry(instances []InstanceConfig, defaultTimeout time.Duration, debug DebugLogger) *ClientRegistry

NewClientRegistry creates a new client registry with the given instance configurations.

Parameters:

  • instances: Slice of instance configurations from config file
  • defaultTimeout: Default timeout for instances without specific timeout
  • debug: Optional debug logger (can be nil)

The registry initializes clients for all configured instances during creation. Clients are keyed by normalized instance URL for easy lookup.

func (*ClientRegistry) GetAllInstances added in v1.0.0

func (r *ClientRegistry) GetAllInstances() []InstanceInfo

GetAllInstances returns all configured instance names and URLs. Useful for listing instances in CLI output.

func (*ClientRegistry) GetClient added in v1.0.0

func (r *ClientRegistry) GetClient(instanceURL string) (*Client, error)

GetClient returns a client for the specified instance URL. The URL is normalized before lookup.

Returns an error if no client is configured for the instance.

func (*ClientRegistry) GetClientForInstanceName added in v1.0.0

func (r *ClientRegistry) GetClientForInstanceName(name string) (*Client, string, error)

GetClientForInstanceName returns a client for the specified instance name.

Returns (client, instanceName, error). If not found, returns (nil, "", error).

func (*ClientRegistry) HasInstanceForURL added in v1.0.0

func (r *ClientRegistry) HasInstanceForURL(instanceURL string) bool

HasInstanceForURL checks if a client is configured for the given instance URL.

func (*ClientRegistry) ValidateAllTokens added in v1.0.0

func (r *ClientRegistry) ValidateAllTokens(ctx context.Context) map[string]error

ValidateAllTokens validates tokens for all configured instances. Returns a map of instance name to validation error (nil if validation succeeded).

This is useful for setup wizard to test all configurations.

type DebugLogger added in v1.0.0

type DebugLogger interface {
	LogAPIRequest(endpoint, method string, hasProject bool, project string)
	Log(category, message string)
}

DebugLogger is an interface for debug logging (avoids import cycle)

type InstanceConfig added in v1.0.0

type InstanceConfig struct {
	Name    string
	URL     string
	Token   string
	Timeout *time.Duration
}

InstanceConfig represents a GitLab instance configuration (avoids import cycle with config package)

type InstanceInfo added in v1.0.0

type InstanceInfo struct {
	Name     string
	URL      string
	HasToken bool
}

InstanceInfo holds information about an instance for display purposes.

type LintRequest

type LintRequest struct {
	Content     string `json:"content"`
	DryRun      bool   `json:"dry_run,omitempty"`
	IncludeJobs bool   `json:"include_jobs,omitempty"`
}

LintRequest represents the request body for the GitLab CI lint API

type LintResponse

type LintResponse struct {
	Valid      bool     `json:"valid"`
	Errors     []string `json:"errors,omitempty"`
	Warnings   []string `json:"warnings,omitempty"`
	MergedYaml string   `json:"merged_yaml,omitempty"`
}

LintResponse represents the response from the GitLab CI lint API (project-specific) This matches gitlab.com/gitlab-org/api/client-go ProjectLintResult

Jump to

Keyboard shortcuts

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