Documentation
¶
Overview ¶
Package gitprovider defines the provider-neutral git host seam.
Index ¶
- Variables
- func WrapError(kind error, op Operation, err error) error
- type CommentID
- type Credential
- type Fake
- func (f *Fake) Capabilities() ProviderCaps
- func (f *Fake) GetDiff(_ context.Context, ref PRRef) (UnifiedDiff, error)
- func (f *Fake) GetFileAtRef(_ context.Context, ref PRRef, gitRef string, path string) ([]byte, error)
- func (f *Fake) GetPR(_ context.Context, ref PRRef) (PR, error)
- func (f *Fake) ListInlineThreads(_ context.Context, ref PRRef) ([]InlineThread, error)
- func (f *Fake) ListIssueComments(_ context.Context, ref PRRef) ([]IssueComment, error)
- func (f *Fake) ListReviews(_ context.Context, ref PRRef) ([]Review, error)
- func (f *Fake) ListTreeAtRef(_ context.Context, ref PRRef, gitRef string, path string) ([]TreeEntry, error)
- func (f *Fake) PostInlineComment(_ context.Context, ref PRRef, c InlineComment) (CommentID, error)
- func (f *Fake) PostIssueComment(_ context.Context, ref PRRef, body string) (CommentID, error)
- func (f *Fake) RecordedInlineComments(ref PRRef) []InlineComment
- func (f *Fake) RecordedIssueComments(ref PRRef) []string
- func (f *Fake) RecordedResolvedThreads(ref PRRef) []ThreadID
- func (f *Fake) RecordedReviews(ref PRRef) []ReviewRequest
- func (f *Fake) RecordedThreadReplies(ref PRRef) []ThreadReply
- func (f *Fake) ReplyToThread(_ context.Context, ref PRRef, threadID ThreadID, body string) (CommentID, error)
- func (f *Fake) ResolveThread(_ context.Context, ref PRRef, threadID ThreadID) error
- func (f *Fake) ReviewAuthority(_ context.Context, ref PRRef, identity Identity) (ReviewAuthority, error)
- func (f *Fake) SetCallHook(hook func(Operation))
- func (f *Fake) SetCapabilities(caps ProviderCaps)
- func (f *Fake) SetDiff(ref PRRef, diff UnifiedDiff) error
- func (f *Fake) SetError(op Operation, err error)
- func (f *Fake) SetFileAtRef(ref PRRef, gitRef, path string, contents []byte) error
- func (f *Fake) SetIdentity(identity Identity)
- func (f *Fake) SetInlineThreads(ref PRRef, threads []InlineThread) error
- func (f *Fake) SetIssueComments(ref PRRef, comments []IssueComment) error
- func (f *Fake) SetPR(ref PRRef, pr PR) error
- func (f *Fake) SetReviewAuthority(ref PRRef, login string, authority ReviewAuthority) error
- func (f *Fake) SetReviews(ref PRRef, reviews []Review) error
- func (f *Fake) SetTreeAtRef(ref PRRef, gitRef, path string, entries []TreeEntry) error
- func (f *Fake) SubmitReview(_ context.Context, ref PRRef, r ReviewRequest) (ReviewID, error)
- func (f *Fake) WhoAmI(_ context.Context, _ Credential) (Identity, error)
- type GitProvider
- type Identity
- type InlineComment
- type InlineThread
- type IssueComment
- type Operation
- type PR
- type PRBranchRef
- type PRRef
- type PRState
- type ProviderCaps
- type ProviderError
- type Review
- type ReviewAuthority
- type ReviewID
- type ReviewRequest
- type ReviewState
- type ThreadComment
- type ThreadID
- type ThreadReply
- type TreeEntry
- type UnifiedDiff
Constants ¶
This section is empty.
Variables ¶
var ( ErrAuth = errors.New("gitprovider: authentication failed") ErrPermission = errors.New("gitprovider: permission denied") // ErrThreadResolutionUnsupported indicates the provider accepted review // posting writes, but the active credential cannot resolve review threads. ErrThreadResolutionUnsupported = errors.New("gitprovider: thread resolution unsupported for current credential") // ErrIneligibleReviewAuthority indicates the credential can talk to the // host, but the resolved posting identity is not eligible for GitHub to // count APPROVE/REQUEST_CHANGES toward PR state on the target repository. ErrIneligibleReviewAuthority = errors.New("gitprovider: posting identity cannot create opinionated reviews for this repository") ErrNotFound = errors.New("gitprovider: target not found") ErrRetryable = errors.New("gitprovider: retryable upstream error") ErrConflict = errors.New("gitprovider: already exists") ErrStaleSHA = errors.New("gitprovider: pinned SHA is no longer current") // ErrDiffTooLarge indicates the host declined to return a diff because it // exceeds the host API's size limit. GitHub, for example, responds with // HTTP 406 for pull request diffs beyond its line cap instead of returning // a truncated diff. ErrDiffTooLarge = errors.New("gitprovider: diff too large for host API") )
Typed provider errors. Concrete adapters map host-specific failures into these sentinels so callers can classify outcomes without knowing wire details.
Functions ¶
Types ¶
type Credential ¶
Credential carries already-resolved credential material. This package never reads config, keyrings, environment variables, or files.
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
Fake is an importable, concurrency-safe GitProvider test double.
func (*Fake) Capabilities ¶
func (f *Fake) Capabilities() ProviderCaps
Capabilities returns the configured fake provider capabilities.
func (*Fake) GetFileAtRef ¶
func (f *Fake) GetFileAtRef(_ context.Context, ref PRRef, gitRef string, path string) ([]byte, error)
GetFileAtRef returns the canned file contents for the full ref/path selector.
func (*Fake) ListInlineThreads ¶
ListInlineThreads returns the canned inline threads for ref.
func (*Fake) ListIssueComments ¶
ListIssueComments returns the canned issue comments for ref.
func (*Fake) ListReviews ¶
ListReviews returns the canned reviews for ref.
func (*Fake) ListTreeAtRef ¶
func (f *Fake) ListTreeAtRef(_ context.Context, ref PRRef, gitRef string, path string) ([]TreeEntry, error)
ListTreeAtRef returns the canned tree entries for the full ref/path selector.
func (*Fake) PostInlineComment ¶
PostInlineComment validates and records an inline comment write.
func (*Fake) PostIssueComment ¶
PostIssueComment validates and records an issue comment write.
func (*Fake) RecordedInlineComments ¶
func (f *Fake) RecordedInlineComments(ref PRRef) []InlineComment
RecordedInlineComments returns successful inline-comment writes for ref.
func (*Fake) RecordedIssueComments ¶
RecordedIssueComments returns successful issue-comment writes for ref.
func (*Fake) RecordedResolvedThreads ¶
RecordedResolvedThreads returns successful thread resolutions for ref.
func (*Fake) RecordedReviews ¶
func (f *Fake) RecordedReviews(ref PRRef) []ReviewRequest
RecordedReviews returns successful review submissions for ref.
func (*Fake) RecordedThreadReplies ¶
func (f *Fake) RecordedThreadReplies(ref PRRef) []ThreadReply
RecordedThreadReplies returns successful thread replies for ref.
func (*Fake) ReplyToThread ¶
func (f *Fake) ReplyToThread(_ context.Context, ref PRRef, threadID ThreadID, body string) (CommentID, error)
ReplyToThread validates and records a thread reply write.
func (*Fake) ResolveThread ¶
ResolveThread validates and records a thread resolution write.
func (*Fake) ReviewAuthority ¶ added in v0.9.190
func (f *Fake) ReviewAuthority(_ context.Context, ref PRRef, identity Identity) (ReviewAuthority, error)
ReviewAuthority returns the configured authority for ref/login.
func (*Fake) SetCallHook ¶ added in v0.10.238
SetCallHook configures a function called before each GitProvider operation. Passing nil clears the hook.
func (*Fake) SetCapabilities ¶
func (f *Fake) SetCapabilities(caps ProviderCaps)
SetCapabilities configures the capabilities returned by Capabilities.
func (*Fake) SetDiff ¶
func (f *Fake) SetDiff(ref PRRef, diff UnifiedDiff) error
SetDiff configures the unified diff for ref.
func (*Fake) SetFileAtRef ¶
SetFileAtRef configures file contents for a full ref/path selector.
func (*Fake) SetIdentity ¶
SetIdentity configures the identity returned by WhoAmI.
func (*Fake) SetInlineThreads ¶
func (f *Fake) SetInlineThreads(ref PRRef, threads []InlineThread) error
SetInlineThreads configures inline threads for ref.
func (*Fake) SetIssueComments ¶
func (f *Fake) SetIssueComments(ref PRRef, comments []IssueComment) error
SetIssueComments configures issue comments for ref.
func (*Fake) SetReviewAuthority ¶ added in v0.9.190
func (f *Fake) SetReviewAuthority(ref PRRef, login string, authority ReviewAuthority) error
SetReviewAuthority configures the authority lookup for ref/login.
func (*Fake) SetReviews ¶
SetReviews configures reviews for ref.
func (*Fake) SetTreeAtRef ¶
SetTreeAtRef configures tree entries for a full ref/path selector.
func (*Fake) SubmitReview ¶
SubmitReview validates and records a review submission write.
type GitProvider ¶
type GitProvider interface {
WhoAmI(ctx context.Context, creds Credential) (Identity, error)
ReviewAuthority(ctx context.Context, ref PRRef, identity Identity) (ReviewAuthority, error)
GetPR(ctx context.Context, ref PRRef) (PR, error)
GetDiff(ctx context.Context, ref PRRef) (UnifiedDiff, error)
GetFileAtRef(ctx context.Context, ref PRRef, gitRef string, path string) ([]byte, error)
ListTreeAtRef(ctx context.Context, ref PRRef, gitRef string, path string) ([]TreeEntry, error)
ListInlineThreads(ctx context.Context, ref PRRef) ([]InlineThread, error)
ListReviews(ctx context.Context, ref PRRef) ([]Review, error)
ListIssueComments(ctx context.Context, ref PRRef) ([]IssueComment, error)
PostInlineComment(ctx context.Context, ref PRRef, c InlineComment) (CommentID, error)
ReplyToThread(ctx context.Context, ref PRRef, threadID ThreadID, body string) (CommentID, error)
ResolveThread(ctx context.Context, ref PRRef, threadID ThreadID) error
PostIssueComment(ctx context.Context, ref PRRef, body string) (CommentID, error)
SubmitReview(ctx context.Context, ref PRRef, r ReviewRequest) (ReviewID, error)
Capabilities() ProviderCaps
}
GitProvider is the host-agnostic seam for pull-request reads and writes.
type Identity ¶
Identity describes a git-host user without binding callers to one host's account schema.
type InlineComment ¶
type InlineComment struct {
CommitSHA string
Body string
Path string
Side review.DiffSide
Line int
SubjectType review.AnchorKind
DiffPosition int
}
InlineComment is the write request for posting an inline comment.
func (InlineComment) Validate ¶
func (c InlineComment) Validate() error
Validate checks provider-seam invariants for an inline comment write.
type InlineThread ¶
type InlineThread struct {
ID ThreadID
Resolved bool
Path string
Side review.DiffSide
Line int
SubjectType review.AnchorKind
CommitSHA string
Comments []ThreadComment
}
InlineThread is a provider-neutral inline review thread.
type IssueComment ¶
type IssueComment struct {
ID CommentID
Body string
Author Identity
URL string
CreatedAt time.Time
UpdatedAt time.Time
}
IssueComment is a provider-neutral issue or pull-request comment.
type Operation ¶
type Operation string
Operation identifies a GitProvider method for fake error injection and provider-error metadata.
const ( OperationWhoAmI Operation = "WhoAmI" OperationReviewAuthority Operation = "ReviewAuthority" OperationGetPR Operation = "GetPR" OperationGetDiff Operation = "GetDiff" OperationGetDiffBetweenRefs Operation = "GetDiffBetweenRefs" OperationGetFileAtRef Operation = "GetFileAtRef" OperationListTreeAtRef Operation = "ListTreeAtRef" OperationListInlineThreads Operation = "ListInlineThreads" OperationListReviews Operation = "ListReviews" OperationListIssueComments Operation = "ListIssueComments" OperationPostInlineComment Operation = "PostInlineComment" OperationReplyToThread Operation = "ReplyToThread" OperationResolveThread Operation = "ResolveThread" OperationPostIssueComment Operation = "PostIssueComment" OperationSubmitReview Operation = "SubmitReview" )
GitProvider operation names.
type PR ¶
type PR struct {
Ref PRRef
Title string
Body string
URL string
State PRState
Author Identity
Head PRBranchRef
Base PRBranchRef
}
PR is the provider-neutral pull request snapshot used by later pipeline stages.
type PRBranchRef ¶
PRBranchRef identifies a base or head ref. Host/Owner/Repo are explicit because a pull request head may live in a fork.
type PRState ¶
type PRState string
PRState is a normalized provider-neutral pull request state.
type ProviderCaps ¶
type ProviderCaps struct {
NativeFileLevelComments bool
ThreadResolution bool
BundleInlineOnSubmit bool
}
ProviderCaps advertises host features that affect posting choices.
type ProviderError ¶
ProviderError annotates a typed provider failure with the operation that produced it and, when available, a more specific wrapped cause.
func (*ProviderError) Error ¶
func (e *ProviderError) Error() string
func (*ProviderError) Is ¶
func (e *ProviderError) Is(target error) bool
Is makes Kind errors.Is-matchable. Unwrap exposes Err to the standard chain.
func (*ProviderError) Unwrap ¶
func (e *ProviderError) Unwrap() error
type Review ¶
type Review struct {
ID ReviewID
Body string
Author Identity
State ReviewState
Event review.ReviewEvent
CommitSHA string
URL string
SubmittedAt time.Time
}
Review is a provider-neutral pull-request review record.
type ReviewAuthority ¶ added in v0.9.190
ReviewAuthority describes whether the resolved posting identity can create a GitHub review that counts as APPROVE/REQUEST_CHANGES for a specific repo.
type ReviewRequest ¶
type ReviewRequest struct {
CommitSHA string
Event review.ReviewEvent
Body string
Comments []InlineComment
}
ReviewRequest is the write request for submitting a pull request review.
func (ReviewRequest) Validate ¶
func (r ReviewRequest) Validate() error
Validate checks provider-seam invariants for a review submission.
type ReviewState ¶
type ReviewState string
ReviewState is a normalized provider-neutral pull request review state.
const ( ReviewStateApproved ReviewState = "approved" ReviewStateChangesRequested ReviewState = "changes_requested" ReviewStateCommented ReviewState = "commented" ReviewStateDismissed ReviewState = "dismissed" ReviewStatePending ReviewState = "pending" )
Pull request review states.
func (ReviewState) Valid ¶
func (s ReviewState) Valid() bool
Valid reports whether s is one of the known review states.
type ThreadComment ¶
type ThreadComment struct {
ID CommentID
ThreadID ThreadID
Body string
Author Identity
CommitSHA string
Path string
Side review.DiffSide
Line int
SubjectType review.AnchorKind
URL string
CreatedAt time.Time
UpdatedAt time.Time
}
ThreadComment is one host comment inside an inline thread.
type ThreadReply ¶
ThreadReply records one ReplyToThread write.
type UnifiedDiff ¶
type UnifiedDiff struct {
Raw string
}
UnifiedDiff is a provider-neutral unified diff payload.