platform

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 ForgejoAdapter added in v0.14.0

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

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

func NewForgejoAdapter added in v0.14.0

func NewForgejoAdapter(client forgejo.APIClient, cfg config.ForgejoConfig, log *bullets.Logger) *ForgejoAdapter

NewForgejoAdapter creates a new Forgejo adapter.

func (*ForgejoAdapter) Approve added in v0.14.0

func (a *ForgejoAdapter) Approve(_ context.Context, _ int64) error

Approve is a no-op for Forgejo (Forgejo doesn't gate merges on approval).

func (*ForgejoAdapter) Create added in v0.14.0

func (a *ForgejoAdapter) Create(ctx context.Context, params CreateParams) (*MergeRequest, error)

Create creates a new pull request on Forgejo.

func (*ForgejoAdapter) GetByBranch added in v0.14.0

func (a *ForgejoAdapter) GetByBranch(ctx context.Context, sourceBranch, targetBranch string) (*MergeRequest, error)

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

func (*ForgejoAdapter) Initialize added in v0.14.0

func (a *ForgejoAdapter) Initialize(ctx context.Context, remoteURL string) error

Initialize sets up the Forgejo repository from a remote URL.

func (*ForgejoAdapter) ListLabels added in v0.14.0

func (a *ForgejoAdapter) ListLabels(ctx context.Context) ([]Label, error)

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

func (*ForgejoAdapter) Merge added in v0.14.0

func (a *ForgejoAdapter) Merge(ctx context.Context, params MergeParams) error

Merge merges a Forgejo pull request. Branch deletion is handled inside the client via DeleteBranchAfterMerge.

func (*ForgejoAdapter) PipelineTimeout added in v0.14.0

func (a *ForgejoAdapter) PipelineTimeout() string

PipelineTimeout returns the configured pipeline timeout string.

func (*ForgejoAdapter) PlatformName added in v0.14.0

func (a *ForgejoAdapter) PlatformName() string

PlatformName returns "Forgejo".

func (*ForgejoAdapter) WaitForPipeline added in v0.14.0

func (a *ForgejoAdapter) WaitForPipeline(ctx context.Context, timeout time.Duration) (string, error)

WaitForPipeline waits for Forgejo Actions / commit-status CI completion.

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.APIClient, cfg config.GitHubConfig, log *bullets.Logger) *GitHubAdapter

NewGitHubAdapter creates a new GitHub adapter.

func (*GitHubAdapter) Approve

func (a *GitHubAdapter) Approve(_ context.Context, _ int64) error

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

func (*GitHubAdapter) Create

func (a *GitHubAdapter) Create(ctx context.Context, params CreateParams) (*MergeRequest, error)

Create creates a new pull request on GitHub.

func (*GitHubAdapter) GetByBranch

func (a *GitHubAdapter) GetByBranch(ctx context.Context, sourceBranch, targetBranch string) (*MergeRequest, error)

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

func (*GitHubAdapter) Initialize

func (a *GitHubAdapter) Initialize(ctx context.Context, remoteURL string) error

Initialize sets up the GitHub repository from a remote URL.

func (*GitHubAdapter) ListLabels

func (a *GitHubAdapter) ListLabels(ctx context.Context) ([]Label, error)

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

func (*GitHubAdapter) Merge

func (a *GitHubAdapter) Merge(ctx context.Context, 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(ctx context.Context, 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.APIClient, cfg config.GitLabConfig, _ *bullets.Logger) *GitLabAdapter

NewGitLabAdapter creates a new GitLab adapter.

func (*GitLabAdapter) Approve

func (a *GitLabAdapter) Approve(ctx context.Context, mrID int64) error

Approve approves a GitLab merge request.

func (*GitLabAdapter) Create

func (a *GitLabAdapter) Create(ctx context.Context, params CreateParams) (*MergeRequest, error)

Create creates a new merge request on GitLab.

func (*GitLabAdapter) GetByBranch

func (a *GitLabAdapter) GetByBranch(ctx context.Context, sourceBranch, targetBranch string) (*MergeRequest, error)

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

func (*GitLabAdapter) Initialize

func (a *GitLabAdapter) Initialize(ctx context.Context, remoteURL string) error

Initialize sets up the GitLab project from a remote URL.

func (*GitLabAdapter) ListLabels

func (a *GitLabAdapter) ListLabels(ctx context.Context) ([]Label, error)

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

func (*GitLabAdapter) Merge

func (a *GitLabAdapter) Merge(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, remoteURL string) error

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

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

	// GetByBranch fetches an existing merge/pull request by source and target branches.
	GetByBranch(ctx context.Context, 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(ctx context.Context, timeout time.Duration) (string, error)

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

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

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

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

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

Every method that performs I/O takes a context.Context as its first parameter. Cancelling it aborts the in-flight request, which is what makes the configured pipeline timeout enforceable: without it a stalled response blocks forever regardless of the budget.

func NewProvider

func NewProvider(
	ctx context.Context, 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, GitHub, or Forgejo.

Jump to

Keyboard shortcuts

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