train

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger func(mrIID int, step string, message string)

Logger is a callback for the train to report progress.

type MRResult

type MRResult struct {
	MR         *gitlab.MergeRequest
	Status     MRStatus
	SkipReason string // empty if merged
}

MRResult holds the outcome of a single MR in the train.

type MRStatus

type MRStatus int

MRStatus represents the outcome of processing a single MR.

const (
	MRStatusPending MRStatus = iota
	MRStatusMerged
	MRStatusSkipped
)

type MockCall

type MockCall struct {
	Method string
	Args   []any
}

MockCall records a single method call made to the MockClient.

type MockClient

type MockClient struct {
	Calls []MockCall // records all calls made

	// Configurable responses per method
	GetCurrentUserFn          func(ctx context.Context) (*gitlab.User, error)
	ListProjectsFn            func(ctx context.Context, search string) ([]*gitlab.Project, error)
	ListMergeRequestsFullFn   func(ctx context.Context, projectPath string) ([]*gitlab.MergeRequest, error)
	GetMergeRequestFn         func(ctx context.Context, projectID, mrIID int) (*gitlab.MergeRequest, error)
	RebaseMergeRequestFn      func(ctx context.Context, projectID, mrIID int) (*gitlab.MergeRequest, error)
	MergeMergeRequestFn       func(ctx context.Context, projectID, mrIID int, sha string) (string, error)
	GetMergeRequestPipelineFn func(ctx context.Context, projectID, mrIID int) (*gitlab.Pipeline, string, error)
	ListPipelinesFn           func(ctx context.Context, projectID int, ref, status, sha string) ([]*gitlab.Pipeline, error)
}

MockClient is a hand-written mock for gitlab.Client used in tests.

func (*MockClient) CallsTo

func (m *MockClient) CallsTo(method string) []MockCall

CallsTo returns all calls to the given method name.

func (*MockClient) GetCurrentUser

func (m *MockClient) GetCurrentUser(ctx context.Context) (*gitlab.User, error)

func (*MockClient) GetMergeRequest

func (m *MockClient) GetMergeRequest(ctx context.Context, projectID, mrIID int) (*gitlab.MergeRequest, error)

func (*MockClient) GetMergeRequestPipeline

func (m *MockClient) GetMergeRequestPipeline(ctx context.Context, projectID, mrIID int) (*gitlab.Pipeline, string, error)

func (*MockClient) ListMergeRequestsFull

func (m *MockClient) ListMergeRequestsFull(ctx context.Context, projectPath string) ([]*gitlab.MergeRequest, error)

func (*MockClient) ListPipelines

func (m *MockClient) ListPipelines(ctx context.Context, projectID int, ref, status, sha string) ([]*gitlab.Pipeline, error)

func (*MockClient) ListProjects

func (m *MockClient) ListProjects(ctx context.Context, search string) ([]*gitlab.Project, error)

func (*MockClient) MergeMergeRequest

func (m *MockClient) MergeMergeRequest(ctx context.Context, projectID, mrIID int, sha string) (string, error)

func (*MockClient) MethodNames

func (m *MockClient) MethodNames() []string

MethodNames returns the ordered list of method names called.

func (*MockClient) RebaseMergeRequest

func (m *MockClient) RebaseMergeRequest(ctx context.Context, projectID, mrIID int) (*gitlab.MergeRequest, error)

type Result

type Result struct {
	MRResults          []MRResult
	MainPipelineURL    string
	MainPipelineStatus string
}

Result holds the overall train execution result.

type Runner

type Runner struct {

	// Configurable intervals for testing
	PollRebaseInterval      time.Duration
	PollPipelineInterval    time.Duration
	MaxMergeStatusRetries   int
	MaxMainPipelineAttempts int
	// contains filtered or unexported fields
}

Runner executes the merge train.

func NewRunner

func NewRunner(client gitlab.Client, projectID int, logger Logger) *Runner

NewRunner creates a new train runner.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, mrs []*gitlab.MergeRequest) (*Result, error)

Run executes the merge train for the given MRs in order. It can be cancelled via the context.

Jump to

Keyboard shortcuts

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