platform

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package platform provides a unified abstraction layer for GitLab and GitHub operations.

The Provider interface defines a common API for merge/pull request lifecycle operations that both platforms implement. This allows the main application logic to be platform-agnostic.

Use NewProvider to create the appropriate adapter based on the detected platform:

provider, err := platform.NewProvider(git.PlatformGitHub, cfg, logger)
provider.Initialize(remoteURL)
mr, _ := provider.Create(platform.CreateParams{...})
status, _ := provider.WaitForPipeline(30 * time.Minute)
provider.Merge(platform.MergeParams{MRID: mr.ID, ...})

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyExists is returned when a merge/pull request already exists for the branch.
	ErrAlreadyExists = errors.New("merge/pull request already exists for this branch")

	// ErrNotFound is returned when no merge/pull request is found for the branch.
	ErrNotFound = errors.New("no merge/pull request found for branch")
)

Sentinel errors for platform operations.

Functions

This section is empty.

Types

type CreateParams

type CreateParams struct {
	SourceBranch string
	TargetBranch string
	Title        string
	Body         string
	Labels       []string
	Squash       bool
}

CreateParams holds parameters for creating a merge/pull request. Assignees and reviewers are not included here; they come from the config stored in each adapter at construction time.

type GitHubAdapter

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

GitHubAdapter wraps a GitHub client to implement the Provider interface. It translates between the platform-agnostic types and the GitHub-specific API.

func NewGitHubAdapter

func NewGitHubAdapter(client *ghclient.Client, cfg config.GitHubConfig, log *bullets.Logger) *GitHubAdapter

NewGitHubAdapter creates a new GitHub adapter.

func (*GitHubAdapter) Approve

func (a *GitHubAdapter) Approve(_ int64) error

Approve is a no-op for GitHub (GitHub doesn't require self-approval).

func (*GitHubAdapter) Create

func (a *GitHubAdapter) Create(params CreateParams) (*MergeRequest, error)

Create creates a new pull request on GitHub.

func (*GitHubAdapter) GetByBranch

func (a *GitHubAdapter) GetByBranch(sourceBranch, targetBranch string) (*MergeRequest, error)

GetByBranch fetches an existing pull request by source and target branches.

func (*GitHubAdapter) Initialize

func (a *GitHubAdapter) Initialize(remoteURL string) error

Initialize sets up the GitHub repository from a remote URL.

func (*GitHubAdapter) ListLabels

func (a *GitHubAdapter) ListLabels() ([]Label, error)

ListLabels returns all available labels, converted to platform-agnostic format.

func (*GitHubAdapter) Merge

func (a *GitHubAdapter) Merge(params MergeParams) error

Merge merges a GitHub pull request and deletes the remote branch.

func (*GitHubAdapter) PipelineTimeout

func (a *GitHubAdapter) PipelineTimeout() string

PipelineTimeout returns the configured pipeline timeout string.

func (*GitHubAdapter) PlatformName

func (a *GitHubAdapter) PlatformName() string

PlatformName returns "GitHub".

func (*GitHubAdapter) WaitForPipeline

func (a *GitHubAdapter) WaitForPipeline(timeout time.Duration) (string, error)

WaitForPipeline waits for GitHub workflow completion.

type GitLabAdapter

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

GitLabAdapter wraps a GitLab client to implement the Provider interface. It translates between the platform-agnostic types and the GitLab-specific API.

func NewGitLabAdapter

func NewGitLabAdapter(client *gitlab.Client, cfg config.GitLabConfig, _ *bullets.Logger) *GitLabAdapter

NewGitLabAdapter creates a new GitLab adapter.

func (*GitLabAdapter) Approve

func (a *GitLabAdapter) Approve(mrID int64) error

Approve approves a GitLab merge request.

func (*GitLabAdapter) Create

func (a *GitLabAdapter) Create(params CreateParams) (*MergeRequest, error)

Create creates a new merge request on GitLab.

func (*GitLabAdapter) GetByBranch

func (a *GitLabAdapter) GetByBranch(sourceBranch, targetBranch string) (*MergeRequest, error)

GetByBranch fetches an existing merge request by source and target branches.

func (*GitLabAdapter) Initialize

func (a *GitLabAdapter) Initialize(remoteURL string) error

Initialize sets up the GitLab project from a remote URL.

func (*GitLabAdapter) ListLabels

func (a *GitLabAdapter) ListLabels() ([]Label, error)

ListLabels returns all available labels, converted to platform-agnostic format.

func (*GitLabAdapter) Merge

func (a *GitLabAdapter) Merge(params MergeParams) error

Merge merges a GitLab merge request. Branch deletion is handled by GitLab's RemoveSourceBranch flag set during creation.

func (*GitLabAdapter) PipelineTimeout

func (a *GitLabAdapter) PipelineTimeout() string

PipelineTimeout returns the configured pipeline timeout string.

func (*GitLabAdapter) PlatformName

func (a *GitLabAdapter) PlatformName() string

PlatformName returns "GitLab".

func (*GitLabAdapter) WaitForPipeline

func (a *GitLabAdapter) WaitForPipeline(timeout time.Duration) (string, error)

WaitForPipeline waits for GitLab pipeline completion.

type Label

type Label struct {
	Name string
}

Label represents a platform-agnostic label.

type MergeParams

type MergeParams struct {
	MRID         int64
	Squash       bool
	CommitTitle  string
	SourceBranch string // GitHub: for branch deletion; GitLab: unused
}

MergeParams holds parameters for merging a merge/pull request.

type MergeRequest

type MergeRequest struct {
	ID           int64  // GitLab: MR IID; GitHub: PR Number
	WebURL       string // Browser URL
	SourceBranch string // Needed for GitHub post-merge branch deletion
}

MergeRequest represents a platform-agnostic merge/pull request.

type Provider

type Provider interface {
	// Initialize sets up the client from a git remote URL.
	Initialize(remoteURL string) error

	// ListLabels returns all available labels.
	ListLabels() ([]Label, error)

	// Create creates a new merge/pull request.
	Create(params CreateParams) (*MergeRequest, error)

	// GetByBranch fetches an existing merge/pull request by source and target branches.
	GetByBranch(sourceBranch, targetBranch string) (*MergeRequest, error)

	// WaitForPipeline waits for CI/CD pipeline or workflow completion.
	// Returns the overall status/conclusion or an error on timeout.
	WaitForPipeline(timeout time.Duration) (string, error)

	// Approve approves a merge/pull request.
	// No-op for GitHub (returns nil).
	Approve(mrID int64) error

	// Merge merges a merge/pull request.
	// GitHub: also deletes the remote branch internally.
	Merge(params MergeParams) error

	// PlatformName returns "GitLab" or "GitHub".
	PlatformName() string

	// PipelineTimeout returns the config value for timeout resolution.
	PipelineTimeout() string
}

Provider defines the unified interface for GitLab and GitHub operations. Implementations are GitLabAdapter and GitHubAdapter, created via NewProvider.

func NewProvider

func NewProvider(p git.Platform, cfg *config.Config, logger *bullets.Logger) (Provider, error)

NewProvider creates the appropriate Provider implementation based on the detected platform. It creates the underlying API client, configures logging, and wraps it in the appropriate adapter.

Parameters:

Returns errUnsupportedPlatform if the platform is not GitLab or GitHub.

Jump to

Keyboard shortcuts

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