Documentation
¶
Index ¶
- func DetectInstanceAndProject(dir string) (string, string, error)
- func DetectInstanceForFile(filePath string) (string, string, error)
- func DetectProjectForFile(filePath string) (string, error)deprecated
- func DetectProjectFromGitRepo(dir string) (string, error)
- func ExtractTokenFromNetrc(instance string) (string, error)
- func NormalizeInstanceURL(instance string) string
- type Client
- type ClientRegistry
- func (r *ClientRegistry) GetAllInstances() []InstanceInfo
- func (r *ClientRegistry) GetClient(instanceURL string) (*Client, error)
- func (r *ClientRegistry) GetClientForInstanceName(name string) (*Client, string, error)
- func (r *ClientRegistry) HasInstanceForURL(instanceURL string) bool
- func (r *ClientRegistry) ValidateAllTokens(ctx context.Context) map[string]error
- type DebugLogger
- type InstanceConfig
- type InstanceInfo
- type LintRequest
- type LintResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectInstanceAndProject ¶ added in v1.0.0
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
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
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
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 ¶
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 ¶
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 (*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
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
InstanceConfig represents a GitLab instance configuration (avoids import cycle with config package)
type InstanceInfo ¶ added in v1.0.0
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