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 ¶
- Variables
- type CreateParams
- type ForgejoAdapter
- func (a *ForgejoAdapter) Approve(_ int64) error
- func (a *ForgejoAdapter) Create(params CreateParams) (*MergeRequest, error)
- func (a *ForgejoAdapter) GetByBranch(sourceBranch, targetBranch string) (*MergeRequest, error)
- func (a *ForgejoAdapter) Initialize(remoteURL string) error
- func (a *ForgejoAdapter) ListLabels() ([]Label, error)
- func (a *ForgejoAdapter) Merge(params MergeParams) error
- func (a *ForgejoAdapter) PipelineTimeout() string
- func (a *ForgejoAdapter) PlatformName() string
- func (a *ForgejoAdapter) WaitForPipeline(timeout time.Duration) (string, error)
- type GitHubAdapter
- func (a *GitHubAdapter) Approve(_ int64) error
- func (a *GitHubAdapter) Create(params CreateParams) (*MergeRequest, error)
- func (a *GitHubAdapter) GetByBranch(sourceBranch, targetBranch string) (*MergeRequest, error)
- func (a *GitHubAdapter) Initialize(remoteURL string) error
- func (a *GitHubAdapter) ListLabels() ([]Label, error)
- func (a *GitHubAdapter) Merge(params MergeParams) error
- func (a *GitHubAdapter) PipelineTimeout() string
- func (a *GitHubAdapter) PlatformName() string
- func (a *GitHubAdapter) WaitForPipeline(timeout time.Duration) (string, error)
- type GitLabAdapter
- func (a *GitLabAdapter) Approve(mrID int64) error
- func (a *GitLabAdapter) Create(params CreateParams) (*MergeRequest, error)
- func (a *GitLabAdapter) GetByBranch(sourceBranch, targetBranch string) (*MergeRequest, error)
- func (a *GitLabAdapter) Initialize(remoteURL string) error
- func (a *GitLabAdapter) ListLabels() ([]Label, error)
- func (a *GitLabAdapter) Merge(params MergeParams) error
- func (a *GitLabAdapter) PipelineTimeout() string
- func (a *GitLabAdapter) PlatformName() string
- func (a *GitLabAdapter) WaitForPipeline(timeout time.Duration) (string, error)
- type Label
- type MergeParams
- type MergeRequest
- type Provider
Constants ¶
This section is empty.
Variables ¶
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.Client, 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(_ 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(params CreateParams) (*MergeRequest, error)
Create creates a new pull request on Forgejo.
func (*ForgejoAdapter) GetByBranch ¶ added in v0.14.0
func (a *ForgejoAdapter) GetByBranch(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(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() ([]Label, error)
ListLabels returns all available labels, converted to platform-agnostic format.
func (*ForgejoAdapter) Merge ¶ added in v0.14.0
func (a *ForgejoAdapter) Merge(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(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.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 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", "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.
func NewProvider ¶
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:
- p: the detected platform (git.PlatformGitLab, git.PlatformGitHub, or git.PlatformForgejo)
- cfg: the loaded configuration (must not be nil)
- logger: the logger instance for debug output
Returns errUnsupportedPlatform if the platform is not GitLab, GitHub, or Forgejo.