Documentation
¶
Overview ¶
Package gitprovider offers a provider-agnostic interface for git hosting operations.
It defines the Provider interface covering PR lifecycle (create, edit, get, comment) and CI status queries, with concrete implementations for Forgejo and GitHub. DetectProvider auto-selects the correct backend by inspecting the git remote URL of a working directory.
Plane: shared
Index ¶
- Constants
- func IsWoodpeckerContext(ctx string) bool
- type CombinedStatus
- type Comment
- type CommitStatus
- type ForgejoProvider
- func (p *ForgejoProvider) CreateComment(owner, repo string, index int64, body string) (*Comment, error)
- func (p *ForgejoProvider) CreatePR(owner, repo, head, base, title, body string) (*PullRequest, error)
- func (p *ForgejoProvider) EditPR(owner, repo string, index int64, title, body string) (*PullRequest, error)
- func (p *ForgejoProvider) FindPR(owner, repo, head, base string) (*PullRequest, error)
- func (p *ForgejoProvider) FindPRByState(owner, repo, head, base, state string) (*PullRequest, error)
- func (p *ForgejoProvider) GetCIFailureDetails(owner, repo, sha string, tailLines int) ([]*JobFailure, error)
- func (p *ForgejoProvider) GetCombinedStatus(owner, repo, ref string) (*CombinedStatus, error)
- func (p *ForgejoProvider) GetPR(owner, repo string, index int64) (*PullRequest, error)
- func (p *ForgejoProvider) ListComments(owner, repo string, index int64) ([]*Comment, error)
- func (p *ForgejoProvider) Name() string
- type GitHubProvider
- func (p *GitHubProvider) CreateComment(owner, repo string, index int64, body string) (*Comment, error)
- func (p *GitHubProvider) CreatePR(owner, repo, head, base, title, body string) (*PullRequest, error)
- func (p *GitHubProvider) EditPR(owner, repo string, index int64, title, body string) (*PullRequest, error)
- func (p *GitHubProvider) FindPR(owner, repo, head, base string) (*PullRequest, error)
- func (p *GitHubProvider) FindPRByCommit(owner, repo, sha string) (*PullRequest, error)
- func (p *GitHubProvider) FindPRByState(owner, repo, head, base, state string) (*PullRequest, error)
- func (p *GitHubProvider) GetCIFailureDetails(owner, repo, sha string, tailLines int) ([]*JobFailure, error)
- func (p *GitHubProvider) GetCombinedStatus(owner, repo, ref string) (*CombinedStatus, error)
- func (p *GitHubProvider) GetPR(owner, repo string, index int64) (*PullRequest, error)
- func (p *GitHubProvider) ListComments(owner, repo string, index int64) ([]*Comment, error)
- func (p *GitHubProvider) Name() string
- type JobFailure
- type Provider
- func NewForgejoProvider(host string) (Provider, error)
- func NewForgejoProviderWithToken(host, token string) (Provider, error)
- func NewGitHubProviderWithToken(token string) (Provider, error)
- func NewGitHubProviderWithTokenAndAuthFailure(token string, onAuthFailure func()) (Provider, error)
- func NewProviderByNameWithToken(name, githubToken, host string) (Provider, error)
- func NewProviderWithToken(info *RepoInfo, githubToken string) (Provider, error)
- type ProviderType
- type PullRequest
- type RepoInfo
- type WoodpeckerClient
Constants ¶
const ( StatePending = "pending" StateSuccess = "success" StateFailure = "failure" StateError = "error" )
CI status state constants.
Variables ¶
This section is empty.
Functions ¶
func IsWoodpeckerContext ¶
IsWoodpeckerContext returns true if a commit status context was created by Woodpecker CI.
Types ¶
type CombinedStatus ¶
type CombinedStatus struct {
State string // Overall: "pending", "success", "error", "failure"
Statuses []*CommitStatus
}
CombinedStatus represents the overall status of all checks on a commit.
type CommitStatus ¶
type CommitStatus struct {
Context string // Check name (e.g. "ci/woodpecker", "lint")
State string // "pending", "success", "error", "failure"
Description string
TargetURL string
}
CommitStatus represents the status of a single CI check on a commit.
type ForgejoProvider ¶
type ForgejoProvider struct {
// contains filtered or unexported fields
}
func (*ForgejoProvider) CreateComment ¶
func (*ForgejoProvider) CreatePR ¶
func (p *ForgejoProvider) CreatePR(owner, repo, head, base, title, body string) (*PullRequest, error)
func (*ForgejoProvider) EditPR ¶
func (p *ForgejoProvider) EditPR(owner, repo string, index int64, title, body string) (*PullRequest, error)
func (*ForgejoProvider) FindPR ¶
func (p *ForgejoProvider) FindPR(owner, repo, head, base string) (*PullRequest, error)
func (*ForgejoProvider) FindPRByState ¶
func (p *ForgejoProvider) FindPRByState(owner, repo, head, base, state string) (*PullRequest, error)
func (*ForgejoProvider) GetCIFailureDetails ¶
func (p *ForgejoProvider) GetCIFailureDetails(owner, repo, sha string, tailLines int) ([]*JobFailure, error)
GetCIFailureDetails fetches CI failure details via Woodpecker CI API. Forgejo's native Actions API does not provide useful error info, so we use Woodpecker's API directly for failure details and step logs.
Note: this method requires WOODPECKER_URL and WOODPECKER_TOKEN to be set independently of the Forgejo credentials; Woodpecker is a separate service.
func (*ForgejoProvider) GetCombinedStatus ¶
func (p *ForgejoProvider) GetCombinedStatus(owner, repo, ref string) (*CombinedStatus, error)
func (*ForgejoProvider) GetPR ¶
func (p *ForgejoProvider) GetPR(owner, repo string, index int64) (*PullRequest, error)
func (*ForgejoProvider) ListComments ¶
func (p *ForgejoProvider) ListComments(owner, repo string, index int64) ([]*Comment, error)
func (*ForgejoProvider) Name ¶
func (p *ForgejoProvider) Name() string
type GitHubProvider ¶
type GitHubProvider struct {
// contains filtered or unexported fields
}
func (*GitHubProvider) CreateComment ¶
func (*GitHubProvider) CreatePR ¶
func (p *GitHubProvider) CreatePR(owner, repo, head, base, title, body string) (*PullRequest, error)
func (*GitHubProvider) EditPR ¶
func (p *GitHubProvider) EditPR(owner, repo string, index int64, title, body string) (*PullRequest, error)
func (*GitHubProvider) FindPR ¶
func (p *GitHubProvider) FindPR(owner, repo, head, base string) (*PullRequest, error)
func (*GitHubProvider) FindPRByCommit ¶
func (p *GitHubProvider) FindPRByCommit(owner, repo, sha string) (*PullRequest, error)
func (*GitHubProvider) FindPRByState ¶
func (p *GitHubProvider) FindPRByState(owner, repo, head, base, state string) (*PullRequest, error)
func (*GitHubProvider) GetCIFailureDetails ¶
func (p *GitHubProvider) GetCIFailureDetails(owner, repo, sha string, tailLines int) ([]*JobFailure, error)
func (*GitHubProvider) GetCombinedStatus ¶
func (p *GitHubProvider) GetCombinedStatus(owner, repo, ref string) (*CombinedStatus, error)
GetCombinedStatus queries GitHub Check Runs API (not the legacy Commit Status API). This only sees checks created via the Checks API (GitHub Actions, Apps); external CI tools that push commit statuses (Jenkins, CircleCI) are not captured.
func (*GitHubProvider) GetPR ¶
func (p *GitHubProvider) GetPR(owner, repo string, index int64) (*PullRequest, error)
func (*GitHubProvider) ListComments ¶
func (p *GitHubProvider) ListComments(owner, repo string, index int64) ([]*Comment, error)
func (*GitHubProvider) Name ¶
func (p *GitHubProvider) Name() string
type JobFailure ¶
type JobFailure struct {
WorkflowName string
JobName string
LogTail string // last ~50 lines of job log (best-effort)
HTMLURL string
}
JobFailure describes a single failed CI job with optional log tail.
type Provider ¶
type Provider interface {
Name() string
CreatePR(owner, repo, head, base, title, body string) (*PullRequest, error)
FindPR(owner, repo, head, base string) (*PullRequest, error)
FindPRByState(owner, repo, head, base, state string) (*PullRequest, error)
EditPR(owner, repo string, index int64, title, body string) (*PullRequest, error)
GetPR(owner, repo string, index int64) (*PullRequest, error)
CreateComment(owner, repo string, index int64, body string) (*Comment, error)
ListComments(owner, repo string, index int64) ([]*Comment, error)
GetCombinedStatus(owner, repo, ref string) (*CombinedStatus, error)
GetCIFailureDetails(owner, repo, sha string, tailLines int) ([]*JobFailure, error)
}
func NewForgejoProvider ¶
func NewGitHubProviderWithToken ¶
NewGitHubProviderWithToken creates a GitHub provider with an explicit token.
func NewGitHubProviderWithTokenAndAuthFailure ¶
NewGitHubProviderWithTokenAndAuthFailure creates a GitHub provider and reports confirmed credential rejection without retrying the request.
func NewProviderByNameWithToken ¶
NewProviderByNameWithToken creates a provider by name with an optional GitHub token override. Forgejo ignores the githubToken parameter.
type ProviderType ¶
type ProviderType string
const ( ProviderForgejo ProviderType = "forgejo" ProviderGeneric ProviderType = "generic" ProviderGitHub ProviderType = "github" )
type PullRequest ¶
type RepoInfo ¶
type RepoInfo struct {
Owner string
Repo string
Provider ProviderType
Host string
BaseURL string
CanonicalURL string
DefaultBranch string
}
func DetectProvider ¶
func ParseHTTPRemoteURL ¶
ParseHTTPRemoteURL parses an HTTP(S) repository URL and returns its canonical secret-free repository identity. It accepts harmless spelling differences, such as hostname case, a missing .git suffix, or a default port.
func ParseRemoteURL ¶
type WoodpeckerClient ¶
type WoodpeckerClient struct {
// contains filtered or unexported fields
}
WoodpeckerClient wraps the Woodpecker SDK for CI failure details.
func NewWoodpeckerClient ¶
func NewWoodpeckerClient() (*WoodpeckerClient, error)
NewWoodpeckerClient creates a Woodpecker API client from env vars. Requires WOODPECKER_URL and WOODPECKER_TOKEN.
func (*WoodpeckerClient) GetFailureDetails ¶
func (w *WoodpeckerClient) GetFailureDetails(owner, repo, sha string, tailLines int) ([]*JobFailure, error)
GetFailureDetails fetches failed pipeline steps and their logs for a commit SHA.