Documentation
¶
Index ¶
- Variables
- func AuthConfigured(ctx context.Context, provider Provider, workDir string) bool
- func CLIAvailable(provider Provider) bool
- func ClampPRBody(body string, max int) string
- func ExtractHost(remote string) string
- func ExtractPRNumber(prURL string) (string, error)
- func MaxPRBodyChars(p Provider) int
- func PRBodyLen(s string) int
- func ResolveHost(ctx context.Context, remote string) string
- type AttestationPublicationIdentityReader
- type Capabilities
- type Check
- type CheckAttemptIdentity
- type CheckAttemptIdentityReader
- type CheckBucket
- type CheckRerunner
- type Host
- type MergeableState
- type PR
- type PRContent
- type PRState
- type Provider
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("operation not supported by this provider")
ErrUnsupported is returned by optional Host methods that the provider cannot fulfil. Callers should gate calls on Capabilities rather than relying on this error, but implementations return it as a fallback.
Functions ¶
func AuthConfigured ¶
func CLIAvailable ¶
func ClampPRBody ¶
ClampPRBody truncates body to at most max PRBodyLen units, cutting on a rune boundary and appending a truncation marker (kept inside the budget) when it cuts. max <= 0 means unlimited and returns body unchanged. This is the last-resort backstop: callers that can shed whole sections to fit a budget should do so before relying on a blind clamp.
func ExtractHost ¶
ExtractHost returns the lowercased host (without any port) from a git remote URL. It handles both scp-like syntax (git@host:group/project) and URL forms (https://host/group/project, ssh://git@host:22/group/project). It returns "" when no host can be determined.
func ExtractPRNumber ¶
ExtractPRNumber returns the trailing numeric segment from a PR/MR URL. Supports GitHub (/pull/N), GitLab (/-/merge_requests/N), Bitbucket (/pull-requests/N), and Azure DevOps (/pullrequest/N) URLs; all of them end in a digit path segment.
func MaxPRBodyChars ¶
MaxPRBodyChars returns the hard limit a provider enforces on a PR description, measured in PRBodyLen units, or 0 when the provider imposes no practical limit. Azure DevOps rejects `az repos pr create`/`update` with "Invalid argument value. ... A description for a pull request must not be longer than 4000 characters."; GitHub and GitLab allow far larger bodies than this tool ever produces, so they report 0 (unlimited).
func PRBodyLen ¶
PRBodyLen reports the length of s the way Azure DevOps (a .NET service) measures a PR description: in UTF-16 code units, so a non-BMP rune (an emoji, some CJK) counts as two. It is the strictest common denominator across providers, so a body that "fits" by this measure is genuinely safe to send.
Types ¶
type Capabilities ¶
Capabilities declares which optional Host methods return meaningful data. Callers must consult Capabilities before invoking optional methods.
type Check ¶
type Check struct {
Name string
Bucket CheckBucket
// State is the provider's own outcome string for the check (GitHub
// conclusions such as FAILURE, TIMED_OUT, CANCELLED). Buckets collapse
// several outcomes into one value, so callers that must tell an
// infrastructure outcome from a real job failure read this. Empty when the
// provider reported no state.
State string
CompletedAt time.Time // zero when unknown; used to detect CI re-runs between polls
// Link is the provider's details URL for this check. It identifies the job
// behind the check, so a rerun can target that job instead of the whole PR.
// Empty when the provider reported no link.
Link string
}
Check is a single CI check result on a PR.
type CheckAttemptIdentity ¶
type CheckAttemptIdentityReader ¶
type CheckAttemptIdentityReader interface {
GetCheckAttemptIdentity(ctx context.Context, check Check) (CheckAttemptIdentity, error)
}
type CheckBucket ¶
type CheckBucket string
CheckBucket is the normalized outcome of a CI check.
const ( CheckBucketPass CheckBucket = "pass" CheckBucketFail CheckBucket = "fail" CheckBucketPending CheckBucket = "pending" CheckBucketCancel CheckBucket = "cancel" CheckBucketSkip CheckBucket = "skipping" )
type CheckRerunner ¶
type CheckRerunner interface {
// RerunCheck asks the provider to run check again for the same commit. It
// returns an error when the request could not be made, including when the
// check names no job the provider can re-run.
RerunCheck(ctx context.Context, pr *PR, check Check) error
}
CheckRerunner re-runs the provider-side job behind a failed check without changing the commit under test. It is deliberately a separate interface rather than a Host method: a backend whose provider exposes no rerun primitive simply does not implement it, and callers type-assert (host.(CheckRerunner)) before use, so those backends keep compiling and keep their existing behavior.
type Host ¶
type Host interface {
Provider() Provider
Capabilities() Capabilities
// Available returns nil when the host is ready to use, or a descriptive
// error explaining why it is not (missing CLI, unauthenticated, etc).
Available(ctx context.Context) error
// FindPR returns the open PR for the source branch, or nil if none exists.
FindPR(ctx context.Context, branch, base string) (*PR, error)
CreatePR(ctx context.Context, branch, base string, content PRContent) (*PR, error)
UpdatePR(ctx context.Context, pr *PR, content PRContent) (*PR, error)
GetPRState(ctx context.Context, pr *PR) (PRState, error)
GetChecks(ctx context.Context, pr *PR) ([]Check, error)
// GetMergeableState is optional; implementations without Capabilities().MergeableState
// must return ErrUnsupported. Callers should consult Capabilities first.
GetMergeableState(ctx context.Context, pr *PR) (MergeableState, error)
// FetchFailedCheckLogs is optional; returns "" when no logs can be retrieved
// and ErrUnsupported when the provider has no log-fetching support at all.
FetchFailedCheckLogs(ctx context.Context, pr *PR, branch, headSHA string, failingNames []string) (string, error)
}
Host is the provider-agnostic interface to a PR-hosting service. Transport (CLI vs HTTP API) is an implementation detail.
type MergeableState ¶
type MergeableState string
MergeableState is the normalized merge-conflict status of a PR.
const ( MergeableOK MergeableState = "MERGEABLE" MergeableConflict MergeableState = "CONFLICTING" MergeablePending MergeableState = "PENDING" MergeableUnknown MergeableState = "UNKNOWN" )
func (MergeableState) Conflict ¶
func (s MergeableState) Conflict() bool
Conflict reports whether the state indicates a known merge conflict.
func (MergeableState) Resolved ¶
func (s MergeableState) Resolved() bool
Resolved reports whether the state is final (MERGEABLE or CONFLICTING).
type Provider ¶
type Provider string
func DetectProvider ¶
DetectProvider identifies the SCM provider for url. SSH host aliases are resolved through the user's SSH configuration before detection falls back to ProviderUnknown.
func DetectProviderContext ¶
DetectProviderContext is DetectProvider with caller-controlled cancellation.
func (Provider) AuthCheckCommand ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package azuredevops implements scm.Host backed by the az CLI with the azure-devops extension.
|
Package azuredevops implements scm.Host backed by the az CLI with the azure-devops extension. |
|
Package github implements scm.Host backed by the gh CLI.
|
Package github implements scm.Host backed by the gh CLI. |
|
Package gitlab implements scm.Host backed by the glab CLI.
|
Package gitlab implements scm.Host backed by the glab CLI. |