Documentation
¶
Overview ¶
Package github provides verified GitHub publication and comment operations for existing Go tools. Clients and credentials are supplied by the caller; the package does not run candidate code or grant publication authority. Prow-specific maintenance operations live in the prow subpackage.
Index ¶
- Constants
- Variables
- func CommentMarker(key, head string) string
- type Check
- type Client
- func (c *Client) Actor(ctx context.Context) (string, error)
- func (c *Client) BaseContains(ctx context.Context, base, commit string) error
- func (c *Client) CI(ctx context.Context, head string) (CommitCI, error)
- func (c *Client) OpenProposals(ctx context.Context, actor, marker, branchPrefix string) ([]int, error)
- func (c *Client) OpenPullRequests(ctx context.Context) ([]PullRequest, error)
- func (c *Client) PostComment(ctx context.Context, number int, expectedHead, key, body string) (Receipt, error)
- func (c *Client) Publish(ctx context.Context, r PublicationRequest) (Receipt, error)
- func (c *Client) PullRequest(ctx context.Context, number int) (PullRequest, error)
- func (c *Client) Snapshot(ctx context.Context, number int, expectedHead string) (Snapshot, error)
- func (c *Client) WithActor(actor string) (*Client, error)
- func (c *Client) WithCIReader(reader *gh.Client) (*Client, error)
- func (c *Client) WithWriter(writer *gh.Client) (*Client, error)
- type Comment
- type CommitCI
- type HoldEvent
- type PublicationRequest
- type PullRequest
- type Receipt
- type Snapshot
- type Status
Constants ¶
const MaxPublicationFiles = 3000
MaxPublicationFiles is the exclusive changed-file limit for publications whose complete file inventory must be verifiable.
Variables ¶
var ErrConflict = errors.New("remote state conflicts with expectation")
ErrConflict reports a failed remote precondition.
var ErrEvidenceIncomplete = errors.New("remote evidence is incomplete")
ErrEvidenceIncomplete reports missing or ambiguous remote evidence.
var ErrIndeterminate = errors.New("remote write result is indeterminate")
ErrIndeterminate reports a write whose result could not be verified; callers must reconcile, not blindly retry.
Functions ¶
func CommentMarker ¶
CommentMarker identifies an idempotency key on exactly one commit; invalid inputs return an empty marker.
Types ¶
type Check ¶
type Check struct {
ID int `json:"id"`
Name string `json:"name"`
HeadSHA string `json:"headSHA"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
DetailsURL string `json:"detailsURL"`
}
Check is one check run.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client accesses one repository through caller-authenticated clients.
func NewClient ¶
NewClient constructs a client without reading credentials or changing authentication.
func (*Client) Actor ¶
Actor returns the explicitly trusted writer identity, or discovers a user-token identity. App installation tokens should use WithActor because GitHub does not support /user for them.
func (*Client) BaseContains ¶
BaseContains fails when commit is not part of base, so a stale or foreign checkout can never publish a diff computed against an unrelated branch.
func (*Client) CI ¶
CI reads every status and latest-check page for a full commit SHA without collecting PR history.
func (*Client) OpenProposals ¶
func (c *Client) OpenProposals(ctx context.Context, actor, marker, branchPrefix string) ([]int, error)
OpenProposals reports the numbers of open pull requests authored by actor that carry marker or whose head branch starts with branchPrefix. A run uses it to stop before doing expensive work while its own proposal is still pending.
func (*Client) OpenPullRequests ¶
func (c *Client) OpenPullRequests(ctx context.Context) ([]PullRequest, error)
OpenPullRequests reads the complete open pull request inventory, rejecting pages that could hide an entry or describe a foreign target.
func (*Client) PostComment ¶
func (c *Client) PostComment(ctx context.Context, number int, expectedHead, key, body string) (Receipt, error)
PostComment posts once after a complete trusted-author deduplication read and verifies the returned comment by ID. Fresh reads require the pull to remain open, unmerged, and bound to its original author, repositories, refs, and head. A failed write or readback is indeterminate: callers must reconcile before attempting another write. GitHub provides no atomic state- or head-conditioned comment write; a change first observed after writing is indeterminate.
func (*Client) Publish ¶
Publish finds, creates or updates exactly one owned proposal and verifies all remote evidence. Write failures are indeterminate, never automatically retried. Concurrent publishers require external serialization. GitHub cannot atomically condition PR metadata writes on the head or current text.
func (*Client) PullRequest ¶
PullRequest reads complete identity metadata for one positive pull-request number.
func (*Client) Snapshot ¶
Snapshot collects every evidence page, retains commit attribution and rechecks identity after collection.
func (*Client) WithActor ¶
WithActor returns an independent client bound to a trusted expected writer login, including App bot logins. The caller must obtain this identity from trusted configuration, not untrusted proposal metadata.
func (*Client) WithCIReader ¶
WithCIReader returns an independent client with a separate credential for CI evidence.
type Comment ¶
type Comment struct {
ID int `json:"id"`
Author string `json:"author"`
Body string `json:"body"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
Comment is one issue comment.
type HoldEvent ¶
type HoldEvent struct {
ID int `json:"id"`
Event string `json:"event"`
Actor string `json:"actor"`
CreatedAt string `json:"createdAt"`
}
HoldEvent is one hold-label transition.
type PublicationRequest ¶
type PublicationRequest struct {
// ExpectedNumber restricts publication to this exact open owned proposal; zero permits creation.
ExpectedNumber int
// ExpectedTitle and ExpectedBody bind a numbered update to the authorized PR text.
ExpectedTitle string
ExpectedBody string
HeadRepository string
HeadRef string
ExpectedHead string
BaseRef string
ExpectedBase string
Actor string
Marker string
// PreviousMarker authorizes the exact prior marker during an ownership-preserving update only.
// Post-write verification always requires Marker and the new exact body.
PreviousMarker string
Title string
Body string
ExpectedFiles []string
// ReadyForReview explicitly opts new PRs into the caller's ready-publication policy.
// It never changes an existing proposal's readiness.
ReadyForReview bool
}
PublicationRequest describes a caller-prepared, already-pushed branch. Publish never changes Git refs. HeadRepository is the exact source repository, including a fork when publishing across repositories. ExpectedBase is the required base branch tip, checked read-only before and after publication. Marker must be an exact standalone HTML comment owned by the caller, not a substring of another marker. Existing proposals retain their readiness; new proposals default to drafts.
type PullRequest ¶
type PullRequest struct {
Number int `json:"number"`
Author string `json:"author"`
State string `json:"state"`
Draft bool `json:"draft"`
Merged bool `json:"merged"`
Title string `json:"title"`
Body string `json:"body"`
Labels []string `json:"labels"`
HeadRef string `json:"headRef"`
HeadSHA string `json:"headSHA"`
HeadRepo string `json:"headRepo"`
BaseRef string `json:"baseRef"`
BaseRepo string `json:"baseRepo"`
}
PullRequest is the identity and review state of one proposal.
func (PullRequest) URL ¶
func (p PullRequest) URL(repository string) string
URL returns the canonical proposal URL.
type Receipt ¶
type Receipt struct {
Number int
URL string
Author string
HeadRepo string
Base string
HeadSHA string
CommentID int
RequestedHead string
ObservedHead string
Outcome string
}
Receipt describes verified observations, not authorization to act.
type Snapshot ¶
type Snapshot struct {
Pull PullRequest `json:"pull"`
Commits []string `json:"commits"`
Comments []Comment `json:"comments"`
HoldEvents []HoldEvent `json:"holdEvents"`
Statuses []Status `json:"statuses"`
Checks []Check `json:"checks"`
// CommitDetails is the complete ordered SDK evidence underlying Commits.
CommitDetails []*gh.RepositoryCommit `json:"-"`
}
Snapshot is a complete, head-bound evidence set.