gitlab

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gitlab provides utilities for GitLab API operations

Package gitlab provides utilities for GitLab API operations

Package gitlab provides utilities for GitLab API operations

Package gitlab provides utilities for GitLab API operations

Package gitlab provides utilities for GitLab API operations

Index

Constants

View Source
const (
	// Default branch prefixes
	DefaultBranchPrefix = "feature/"
	UpdateBranchPrefix  = "update-tag/"

	// Branch name constraints
	MaxBranchNameLength = 100
	MinBranchNameLength = 1
)
View Source
const (
	// GitLab URLs
	DefaultGitLabURL = "https://gitlab.com"

	// API version and endpoints
	DefaultAPIVersion     = "v4"
	ProjectsEndpoint      = "/api/v4/projects"
	MergeRequestsEndpoint = "/api/v4/projects/%d/merge_requests"

	// Timeout and retry settings
	DefaultTimeout   = 30 * time.Second
	MaxRetryAttempts = 3
	RetryDelayBase   = 1 * time.Second

	// Rate limiting
	DefaultRateLimitRPS = 10
	MaxConcurrentReqs   = 5

	// Response size limits
	MaxResponseSize = 10 * 1024 * 1024 // 10MB
)
View Source
const (
	// Conflict detection constants
	MaxConflictCheckAttempts = 15
	ConflictCheckInterval    = 10 * time.Second
	DefaultWaitTimeout       = 15 * time.Minute

	// MR states for conflict checking
	StateOpened = "opened"
	StateMerged = "merged"
	StateClosed = "closed"
)
View Source
const (
	// DefaultCommitMessage for file updates
	DefaultCommitMessage = "Update file via go-tag-updater"
	// MaxFileSize defines maximum file size for processing
	MaxFileSize = 1024 * 1024 // 1MB
	// DefaultBranch is the default branch name
	DefaultBranch = "main"
)
View Source
const (
	// Project resolution constants
	ProjectsAPIEndpoint  = "/api/v4/projects"
	MaxProjectNameLength = 255
	MinProjectIDValue    = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BranchInfo

type BranchInfo struct {
	Name               string
	Protected          bool
	Default            bool
	DevelopersCanPush  bool
	DevelopersCanMerge bool
	Commit             *gitlab.Commit
	WebURL             string
}

BranchInfo represents branch information

type BranchManager

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

BranchManager handles GitLab branch operations

func NewBranchManager

func NewBranchManager(client *gitlab.Client, projectID interface{}) *BranchManager

NewBranchManager creates a new branch manager

func (*BranchManager) BranchExists

func (bm *BranchManager) BranchExists(ctx context.Context, branchName string) (bool, error)

BranchExists checks if a branch exists

func (*BranchManager) CreateBranch

func (bm *BranchManager) CreateBranch(ctx context.Context, branchName, ref string) (*BranchInfo, error)

CreateBranch creates a new branch from a reference

func (*BranchManager) DeleteBranch

func (bm *BranchManager) DeleteBranch(ctx context.Context, branchName string) error

DeleteBranch deletes a branch

func (*BranchManager) FindBranchesByTag

func (bm *BranchManager) FindBranchesByTag(ctx context.Context, tag string) ([]*BranchInfo, error)

FindBranchesByTag finds branches that might be related to a specific tag

func (*BranchManager) GenerateUniqueBranchName

func (bm *BranchManager) GenerateUniqueBranchName(ctx context.Context, prefix, tag string) (string, error)

GenerateUniqueBranchName generates a unique branch name with timestamp

func (*BranchManager) GetBranch

func (bm *BranchManager) GetBranch(ctx context.Context, branchName string) (*BranchInfo, error)

GetBranch retrieves branch information

func (*BranchManager) GetProtectedBranches

func (bm *BranchManager) GetProtectedBranches(ctx context.Context) ([]*gitlab.ProtectedBranch, error)

GetProtectedBranches lists protected branches

func (*BranchManager) ListBranches

func (bm *BranchManager) ListBranches(ctx context.Context, search string, maxResults int) ([]*BranchInfo, error)

ListBranches lists branches with optional search filter

type Client

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

Client wraps the GitLab API client with additional functionality

func NewClient

func NewClient(token, baseURL string) (*Client, error)

NewClient creates a new GitLab client instance

func NewClientWithConfig

func NewClientWithConfig(token, baseURL string, debug bool, timeout time.Duration, retryCount int) (*Client, error)

NewClientWithConfig creates a new GitLab client with custom configuration

func (*Client) GetBaseURL

func (c *Client) GetBaseURL() string

GetBaseURL returns the base URL of the GitLab instance

func (*Client) GetGitLabClient

func (c *Client) GetGitLabClient() *gitlab.Client

GetGitLabClient returns the underlying GitLab client

func (*Client) GetProject

func (c *Client) GetProject(projectID interface{}) (*gitlab.Project, error)

GetProject retrieves project information by ID or path

func (*Client) GetRetryCount

func (c *Client) GetRetryCount() int

GetRetryCount returns the configured retry count

func (*Client) GetTimeout

func (c *Client) GetTimeout() time.Duration

GetTimeout returns the configured timeout

func (*Client) IsDebugEnabled

func (c *Client) IsDebugEnabled() bool

IsDebugEnabled returns true if debug mode is enabled

func (*Client) IsHealthy

func (c *Client) IsHealthy() error

IsHealthy checks if the GitLab instance is accessible

func (*Client) ResolveProjectID

func (c *Client) ResolveProjectID(projectIdentifier string) (int, error)

ResolveProjectID converts a project path to numeric ID using ProjectManager

type ConflictDetector

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

ConflictDetector handles merge request conflict detection and prevention

func NewConflictDetector

func NewConflictDetector(client *gitlab.Client, projectID interface{}) *ConflictDetector

NewConflictDetector creates a new conflict detector

func (*ConflictDetector) CheckForConflicts

func (cd *ConflictDetector) CheckForConflicts(ctx context.Context, sourceBranch, targetBranch, filePath string) (*ConflictInfo, error)

CheckForConflicts performs comprehensive conflict detection

func (*ConflictDetector) WaitForConflictsToResolve

func (cd *ConflictDetector) WaitForConflictsToResolve(ctx context.Context, conflicts *ConflictInfo, maxWaitTime time.Duration) error

WaitForConflictsToResolve waits for conflicting merge requests to be resolved

type ConflictInfo

type ConflictInfo struct {
	ConflictingMRs []ConflictingMR
	TotalConflicts int
	Recommendation string
}

ConflictInfo contains information about conflicting merge requests

type ConflictingMR

type ConflictingMR struct {
	ID           int
	IID          int
	Title        string
	SourceBranch string
	TargetBranch string
	State        string
	WebURL       string
	CreatedAt    *time.Time
	UpdatedAt    *time.Time
	Author       string
	ConflictType string // "same_branch", "same_file", "same_target"
}

ConflictingMR represents a merge request that conflicts with our operation

type FileInfo

type FileInfo struct {
	FilePath   string
	Content    string
	SHA        string
	Size       int64
	Encoding   string
	Branch     string
	LastCommit *gitlab.Commit
}

FileInfo represents file information

type FileManager

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

FileManager handles repository file operations

func NewFileManager

func NewFileManager(client *gitlab.Client, projectID interface{}) *FileManager

NewFileManager creates a new file manager

func (*FileManager) DeleteFile

func (fm *FileManager) DeleteFile(ctx context.Context, filePath, branch, commitMessage string) error

DeleteFile deletes a file from repository

func (*FileManager) FileExists

func (fm *FileManager) FileExists(ctx context.Context, filePath, branch string) (bool, error)

FileExists checks if a file exists in the repository

func (*FileManager) GetFile

func (fm *FileManager) GetFile(ctx context.Context, filePath, branch string) (*FileInfo, error)

GetFile retrieves file content from repository

func (*FileManager) GetFileContent

func (fm *FileManager) GetFileContent(ctx context.Context, filePath, branch string) (string, error)

GetFileContent retrieves just the content of a file as a string

func (*FileManager) GetFileHistory

func (fm *FileManager) GetFileHistory(ctx context.Context, filePath, branch string, maxResults int) ([]*gitlab.Commit, error)

GetFileHistory retrieves the commit history for a specific file

func (*FileManager) UpdateFile

func (fm *FileManager) UpdateFile(ctx context.Context, filePath string, opts *FileUpdateOptions) (*gitlab.FileInfo, error)

UpdateFile updates file content in repository

func (*FileManager) UpdateFileContent

func (fm *FileManager) UpdateFileContent(ctx context.Context, filePath string, opts *FileUpdateOptions) (*gitlab.FileInfo, error)

UpdateFileContent updates file content using the existing UpdateFile method

func (*FileManager) UpdateYAMLTag

func (fm *FileManager) UpdateYAMLTag(ctx context.Context, filePath, newTag, branch string, opts *FileUpdateOptions) (*gitlab.FileInfo, error)

UpdateYAMLTag updates a tag value in a YAML file

type FileUpdateOptions

type FileUpdateOptions struct {
	Branch        string
	Content       string
	CommitMessage string
	AuthorEmail   string
	AuthorName    string
	StartBranch   string
}

FileUpdateOptions contains options for file updates

type ProjectInfo

type ProjectInfo struct {
	ID                int
	Name              string
	Path              string
	PathWithNamespace string
	WebURL            string
	DefaultBranch     string
	Description       string
	Visibility        string
	CreatedAt         string
	LastActivityAt    string
	ForksCount        int
	StarCount         int
}

ProjectInfo contains detailed project information

type ProjectManager

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

ProjectManager handles GitLab project operations and resolution

func NewProjectManager

func NewProjectManager(client *gitlab.Client) *ProjectManager

NewProjectManager creates a new project manager

func (*ProjectManager) GetProjectDefaultBranch

func (pm *ProjectManager) GetProjectDefaultBranch(ctx context.Context, projectID int) (string, error)

GetProjectDefaultBranch returns the default branch for a project

func (*ProjectManager) GetProjectInfo

func (pm *ProjectManager) GetProjectInfo(ctx context.Context, projectID int) (*ProjectInfo, error)

GetProjectInfo retrieves detailed project information

func (*ProjectManager) ListUserProjects

func (pm *ProjectManager) ListUserProjects(ctx context.Context, maxResults int) ([]*ProjectInfo, error)

ListUserProjects lists projects accessible to the authenticated user

func (*ProjectManager) ResolveProjectIdentifier

func (pm *ProjectManager) ResolveProjectIdentifier(ctx context.Context, identifier string) (int, error)

ResolveProjectIdentifier resolves project identifier to numeric ID Supports both numeric IDs and human-readable paths (group/subgroup/project)

func (*ProjectManager) ResolveProjectPath

func (pm *ProjectManager) ResolveProjectPath(ctx context.Context, projectPath string) (int, error)

ResolveProjectPath resolves a human-readable project path to numeric ID Handles paths like "group/subgroup/project" or "user/project"

func (*ProjectManager) SearchProjects

func (pm *ProjectManager) SearchProjects(ctx context.Context, query string, maxResults int) ([]*ProjectInfo, error)

SearchProjects searches for projects by name or path

func (*ProjectManager) ValidateProjectExists

func (pm *ProjectManager) ValidateProjectExists(ctx context.Context, projectID int) (bool, error)

ValidateProjectExists checks if a project exists and is accessible

type SimpleMergeRequestManager

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

SimpleMergeRequestManager handles basic GitLab merge request operations

func NewSimpleMergeRequestManager

func NewSimpleMergeRequestManager(client *gitlab.Client, projectID interface{}) *SimpleMergeRequestManager

NewSimpleMergeRequestManager creates a new simple merge request manager

func (*SimpleMergeRequestManager) CreateMergeRequest

CreateMergeRequest creates a new merge request with basic options

func (*SimpleMergeRequestManager) GetMergeRequest

func (smr *SimpleMergeRequestManager) GetMergeRequest(ctx context.Context, mrIID int) (*gitlab.MergeRequest, error)

GetMergeRequest retrieves merge request by IID

func (*SimpleMergeRequestManager) ListMergeRequests

func (smr *SimpleMergeRequestManager) ListMergeRequests(ctx context.Context, state string) ([]*gitlab.BasicMergeRequest, error)

ListMergeRequests lists merge requests with basic filtering

type SimpleMergeRequestOptions

type SimpleMergeRequestOptions struct {
	Title        string
	Description  string
	SourceBranch string
	TargetBranch string
}

SimpleMergeRequestOptions contains basic options for creating merge requests

Jump to

Keyboard shortcuts

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