{"modulePath":"github.com/wloophq/wloop","version":"v0.7.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\nPackage github reads pull requests over GitHub's HTTPS API, batching every pull request of a sweep into aliased GraphQL queries.\n\n## Constants\n\n```go\nconst (\n\tStateOpen   = \"OPEN\"\n\tStateMerged = \"MERGED\"\n\tStateClosed = \"CLOSED\"\n)\n```\n\n```go\nconst BriefFilesMax = 300\n```\nBriefFilesMax bounds the changed files BriefFacts lists.\n\n```go\nconst DiscoveryFirst = 10\n```\nDiscoveryFirst is the first page size of the fast discovery searches: a search pays its first times every nested connection, and a quiet window returns a handful of pull requests.\n\n```go\nconst MaxThreads = 50\n```\nMaxThreads caps the review threads Threads reads of one pull request.\n\n```go\nconst SearchFirst = 100\n```\nSearchFirst is the page size of a listing expected to fill pages.\n\n```go\nconst SearchesPerRequest = 3\n```\nSearchesPerRequest bounds the searches one SearchCandidatesEach request carries: GitHub refuses a request that reads 100 candidates.\n\n```go\nconst StubBatch = 40\n```\nStubBatch is the largest by-ref stub batch GitHub prices at one point.\n\n```go\nconst TokenRecheck = time.Minute\n```\nTokenRecheck is the least time between two reads of a refused token.\n\n## Variables\n\n```go\nvar (\n\tErrRateLimited  error = \u0026unavailable{\"GitHub rate limited\"}\n\tErrUnavailable  error = \u0026unavailable{\"GitHub unreachable\"}\n\tErrUnauthorized       = errors.New(\"GitHub token refused\")\n\tErrEmpty              = errors.New(\"GitHub returned an empty response\")\n)\n```\n\n```go\nvar ErrBudget = errors.New(\"GitHub budget low\")\n```\n\n## Functions\n\n```go\nfunc DefaultHost() string\n```\nDefaultHost is the host gh uses when none is named: GH\\_HOST, else the one host gh's hosts.yml lists, else github.com.\n\n```go\nfunc PickByBranch(matches []BranchMatch) (int, string)\n```\nPickByBranch accepts a single match, or a single open one among several: branch names repeat across time, and a guess could revive a finished review.\n\n```go\nfunc Transient(err error) bool\n```\nTransient says whether err is worth a split or a later retry: 502, 503, 504, an attempt timeout, a GraphQL timeout, ErrUnavailable or ErrEmpty. The caller's own cancellation or deadline never is.\n\n```go\nfunc ValidLogin(s string) bool\n```\n\n```go\nfunc WithPriority(ctx context.Context, p Priority) context.Context\n```\nWithPriority tags ctx.\n\n## Types\n\n```go\ntype BranchMatch struct {\n\tNumber int\n\tState  string\n}\n```\n\n```go\ntype BranchQuery struct {\n\tOwner, Repo, Branch string\n}\n```\n\n```go\ntype BriefFacts struct {\n\tTitle, Body string\n\tFiles       []BriefFile\n\t// MoreFiles is how many changed files are past BriefFilesMax.\n\tMoreFiles int\n\t// Issue is the first issue the pull request closes, nil when none.\n\tIssue *BriefIssue\n}\n```\nBriefFacts is what a brief reads of a pull request besides its diff.\n\n```go\ntype BriefFile struct {\n\tPath                 string\n\tAdditions, Deletions int\n}\n```\n\n```go\ntype BriefIssue struct{ Title, Body string }\n```\n\n```go\ntype BudgetError struct {\n\tLimit    Limit\n\tPriority Priority\n}\n```\nBudgetError is a call refused because its bucket fell below the floor of its priority.\n\n```go\nfunc (e *BudgetError) Error() string\n```\n\n```go\nfunc (e *BudgetError) Is(target error) bool\n```\n\n```go\ntype Candidate struct {\n\tRef            pr.Ref    `json:\"ref\"`\n\tURL            string    `json:\"url\"`\n\tTitle          string    `json:\"title\"`\n\tAuthor         string    `json:\"author\"`\n\tState          string    `json:\"state\"`\n\tIsDraft        bool      `json:\"draft\"`\n\tCreatedAt      time.Time `json:\"created_at\"`\n\tUpdatedAt      time.Time `json:\"updated_at\"`\n\tAdditions      int       `json:\"additions\"`\n\tDeletions      int       `json:\"deletions\"`\n\tChangedFiles   int       `json:\"changed_files\"`\n\tHeadBranch     string    `json:\"head\"`\n\tBaseBranch     string    `json:\"base\"`\n\tReviewDecision string    `json:\"review_decision\"`\n\tReviewRequests []string  `json:\"review_requests\"` // logins and team:org/slug\n\tChecksState    string    `json:\"checks\"`\n\tComments       int       `json:\"comments\"`\n\t// MyReview is the viewer's latest review state, \"\" when none.\n\tMyReview       string `json:\"my_review\"`\n\tMyReviewOnHead bool   `json:\"my_review_on_head\"`\n}\n```\nCandidate is a pull request Explore found, with what deciding whether to help on it needs.\n\n```go\ntype CandidatePage struct {\n\tCandidates []Candidate\n\tTotal      int\n\tRateLimit  RateLimit\n}\n```\n\n```go\ntype Client struct {\n\t// contains filtered or unexported fields\n}\n```\nClient is the loop's one connection to GitHub. Safe for concurrent use.\n\n```go\nfunc NewClient(o Options) *Client\n```\n\n```go\nfunc (c *Client) Allow(p Priority) bool\n```\nAllow says, without I/O, whether a call of p would be admitted now on the GraphQL bucket, the one every job spends.\n\n```go\nfunc (c *Client) Basics(ctx context.Context, r Ref) (*pr.PullRequest, error)\n```\n\n```go\nfunc (c *Client) BriefFacts(ctx context.Context, ref Ref) (BriefFacts, error)\n```\nBriefFacts reads ref's title, body, first closing issue and changed files in one GraphQL call, and one more per further 100 files up to BriefFilesMax.\n\n```go\nfunc (c *Client) Budget() map[Resource]Limit\n```\nBudget is the lowest live bucket of each resource seen so far.\n\n```go\nfunc (c *Client) CandidateByRef(ctx context.Context, ref Ref, viewer string) (CandidatePage, error)\n```\nCandidateByRef reads one pull request as a candidate, in any state.\n\n```go\nfunc (c *Client) Diff(ctx context.Context, ref Ref, limit int) (diff []byte, cut bool, err error)\n```\nDiff reads ref's diff, at most limit bytes when limit \u003e 0: it reads limit+1 bytes and closes the response, with cut true when there were more.\n\n```go\nfunc (c *Client) FindByBranch(ctx context.Context, queries []BranchQuery) (map[BranchQuery][]BranchMatch, error)\n```\n\n```go\nfunc (c *Client) GraphQL(ctx context.Context, query string, vars map[string]any) (map[string]json.RawMessage, map[string]string, error)\n```\nGraphQL posts a read query and returns the data by top-level alias and the error per alias; an error with no alias in its path fails the whole call. It refuses a document with a mutation or a subscription. The cost a selected rateLimit reports goes to the meter.\n\n```go\nfunc (c *Client) InventoryByRef(ctx context.Context, refs []Ref) (map[Ref]Snapshot, map[Ref]error, RateLimit, error)\n```\nInventoryByRef reads full snapshots by reference. The rate limit adds up the cost of every batch and keeps the budget the last one reported.\n\n```go\nfunc (c *Client) IsUser(ctx context.Context, login string) (bool, error)\n```\nIsUser reports whether login names a GitHub user; an organization or an unknown login is not one.\n\n```go\nfunc (c *Client) REST(ctx context.Context, r Request) (Response, error)\n```\nREST sends r. A 304 is a Response with Status 304 and no error; any other status outside 2xx is a \\*StatusError, with the Response.\n\n```go\nfunc (c *Client) ResolveReviewThread(ctx context.Context, threadID string) error\n```\nResolveReviewThread resolves review thread threadID, by its GraphQL node id, in an exchange of its own: the one mutation the client sends, which GraphQL refuses. Like a REST mutation, it is never retried once its request was written.\n\n```go\nfunc (c *Client) Restore(limits []Limit)\n```\nRestore seeds the budget, as a store kept it; a bucket already reset is dropped.\n\n```go\nfunc (c *Client) SearchCandidates(ctx context.Context, q, viewer string, first int) (CandidatePage, error)\n```\nSearchCandidates reads the first page of a pull request search; viewer names whose review is \"mine\", \"\" asks for none. It does not retry: the caller pauses before it does.\n\n```go\nfunc (c *Client) SearchCandidatesEach(ctx context.Context, qs []string, viewer string, first int) (pages []CandidatePage, errs []error, err error)\n```\nSearchCandidatesEach reads the first page of each search in qs as aliases of one GraphQL request, the pages in the order of qs; every page carries the request's rate limit, and errs holds, per query, the error of that search alone. It does not retry: the caller pauses before it does.\n\n```go\nfunc (c *Client) SearchStubs(ctx context.Context, q, after string) (StubPage, error)\n```\nSearchStubs reads one page of a pull request search; after is the previous page's EndCursor, empty for the first page.\n\n```go\nfunc (c *Client) SearchStubsFirst(ctx context.Context, qs []string, first int) (pages []StubPage, errs []error, err error)\n```\nSearchStubsFirst reads the first page, of first stubs, of every query in one request; errs holds, per query, the error of that search alone.\n\n```go\nfunc (c *Client) SetFloors(f Floors)\n```\nSetFloors replaces the floors the client admits calls by.\n\n```go\nfunc (c *Client) StubsByRef(ctx context.Context, refs []Ref) (map[Ref]Stub, map[Ref]error, error)\n```\nStubsByRef reads the stub of every ref in requests of StubBatch aliases. errs holds the refs GitHub did not return; err fails the whole read.\n\n```go\nfunc (c *Client) TeamMembers(ctx context.Context, org, slug string) ([]string, error)\n```\n\n```go\nfunc (c *Client) Threads(ctx context.Context, refs map[Ref]int) (threads map[Ref][]pr.Thread, errs map[Ref]error, err error)\n```\nThreads reads the unresolved threads among the newest refs\\[ref] review threads of each ref, at most MaxThreads, in batches of 20 aliases. Per-ref failures are in errs; a failed request is err, returned with what the earlier requests read.\n\n```go\nfunc (c *Client) Viewer(ctx context.Context) (string, error)\n```\n\n```go\ntype DatedCommit struct {\n\tOid     string\n\tParents int\n\tAt      time.Time\n}\n```\n\n```go\ntype DraftEvent struct {\n\tActor string\n\tAt    time.Time\n}\n```\nDraftEvent is the pull request going back to draft.\n\n```go\ntype Floors struct{ User, Background float64 }\n```\nFloors are, per priority, the fraction of Limit below which a call of that priority is refused until the bucket resets.\n\n```go\nfunc DefaultFloors(f float64) Floors\n```\nDefaultFloors takes plugins.github.rate\\_limit\\_fraction as f.\n\n```go\ntype Limit struct {\n\tResource         Resource\n\tLimit, Remaining int\n\tResetAt          time.Time\n}\n```\nLimit is one bucket as a response reported it.\n\n```go\ntype Meter func(ctx context.Context, s Sample)\n```\nMeter hears the client's samples.\n\n```go\ntype Options struct {\n\t// Host is the GitHub hostname as gh names it; empty is DefaultHost(). A\n\t// host other than github.com is served the Enterprise Server layout\n\t// (/api/v3 and /api/graphql); it may carry its scheme.\n\tHost string\n\t// Base is the transport; nil is HTTP/2 with IdleConnTimeout 30 s and\n\t// MaxIdleConnsPerHost 4.\n\tBase http.RoundTripper\n\t// Token is nil for `gh auth token --hostname \u003cHost\u003e`; it runs once, and\n\t// again after a 401 at most once per TokenRecheck.\n\tToken func(ctx context.Context) (string, error)\n\t// Floors is zero for DefaultFloors(0.5).\n\tFloors      Floors\n\tRetry       Retry\n\tMaxInFlight int           // 2; one slot is kept for PriorityUser\n\tTimeout     time.Duration // per attempt; 30 s\n\tNow         func() time.Time\n\tSleep       func(ctx context.Context, d time.Duration) error\n\t// GH runs gh for the token; nil is gh on the PATH.\n\tGH gh.Runner\n\t// UserAgent names the caller to GitHub.\n\tUserAgent string\n\t// Meter hears every request and every cost a response reported; nil\n\t// meters nothing.\n\tMeter Meter\n}\n```\n\n```go\ntype Priority uint8\n```\nPriority orders who may spend the budget when it runs low.\n\n```go\nconst (\n\tPriorityUser       Priority = iota // a user action; keeps the reserve\n\tPriorityBackground                 // jobs and reads the plugin runs on its own\n)\n```\n\n```go\nfunc PriorityOf(ctx context.Context) Priority\n```\nPriorityOf is the priority ctx is tagged with, else the one the host's call carries.\n\n```go\ntype RateLimit struct {\n\tCost      int       `json:\"cost\"`\n\tRemaining int       `json:\"remaining\"`\n\tLimit     int       `json:\"limit\"`\n\tResetAt   time.Time `json:\"reset_at\"`\n}\n```\n\n```go\ntype RateLimitedError struct {\n\tResource  Resource\n\tRetryAt   time.Time\n\tSecondary bool\n}\n```\nRateLimitedError is a resource GitHub asked to leave alone until RetryAt. Secondary is a secondary (abuse) limit; otherwise the bucket ran out.\n\n```go\nfunc (e *RateLimitedError) Error() string\n```\n\n```go\nfunc (e *RateLimitedError) Is(target error) bool\n```\n\n```go\ntype Ref = pr.Ref\n```\n\n```go\nfunc ParseURL(raw string) (Ref, error)\n```\n\n```go\ntype Request struct {\n\tMethod, Path, Accept         string // Path from the host root, with its query\n\tIfNoneMatch, IfModifiedSince string\n\tMaxBytes                     int64 // \u003e 0: read at most this many body bytes, then close\n\tBody                         []byte\n\t// Mutation is never retried once its request was written; only a failure\n\t// before the write (dial, breaker) is retried.\n\tMutation bool\n}\n```\nRequest is a REST call.\n\n```go\ntype Resource string\n```\nResource is a rate-limit bucket family, as x-ratelimit-resource names it.\n\n```go\nconst (\n\tResourceGraphQL Resource = \"graphql\"\n\tResourceCore    Resource = \"core\"\n\tResourceSearch  Resource = \"search\"\n)\n```\n\n```go\ntype Response struct {\n\tStatus       int\n\tBody         []byte\n\tTruncated    bool // the body had more than MaxBytes\n\tETag         string\n\tLastModified string\n\tPollInterval time.Duration\n\tLimit        Limit\n\t// contains filtered or unexported fields\n}\n```\n\n```go\ntype Retry struct {\n\tAttempts   int           // tries in all; 3\n\tBase, Max  time.Duration // full-jitter backoff bounds; 1 s, 30 s\n\tBreakAfter int           // consecutive network failures that open the breaker; 3\n\tBreakFor   time.Duration // how long the open breaker fails fast; 60 s\n}\n```\nRetry bounds the retries of one call and the breaker every call shares.\n\n```go\ntype ReviewRequestEvent struct {\n\tReviewer string\n\tActor    string\n\tAt       time.Time\n}\n```\n\n```go\ntype Sample struct {\n\tOp          string\n\tSpawn       bool\n\tDur         time.Duration\n\tFailed      bool\n\tNotModified bool\n\tPoints      int64\n\tBytes       int64\n\tSpend       bool\n}\n```\nSample is one request the client sent, or, with Spend, the points a response reported for a request already counted.\n\n```go\ntype Snapshot struct {\n\tpr.PullRequest\n\tURL            string\n\tCreatedAt      time.Time\n\tUpdatedAt      time.Time\n\tMergedAt       time.Time\n\tClosedAt       time.Time\n\tLastEditedAt   time.Time // last edit of the description; zero when never edited\n\tChangedFiles   int\n\tReadyAt        time.Time\n\tReviewRequests []ReviewRequestEvent\n\tCommitsDated   []DatedCommit\n\tMergedBy       string\n\tMergeCommit    string\n\tDrafts         []DraftEvent\n\tRemovedReviews []ReviewRequestEvent\n\t// TimelineMissed counts the earliest timeline events the read left out.\n\tTimelineMissed int\n\t// ThreadsRead says OpenThreads is known: Threads read it, or there are\n\t// no threads. A full read only counts them.\n\tThreadsRead bool\n}\n```\nSnapshot is one pull request as the inventory sees it.\n\n```go\ntype StatusError struct {\n\tStatus  int\n\tMessage string\n}\n```\nStatusError is a response GitHub answered with a status the call does not take as an answer.\n\n```go\nfunc (e *StatusError) Error() string\n```\n\n```go\ntype Stub struct {\n\tRef            Ref\n\tAuthor         string\n\tUpdatedAt      time.Time\n\tIsDraft        bool\n\tHeadOid        string\n\tReviewDecision string\n\tReviewRequests []string // logins and team:org/slug\n\tNameWithOwner  string\n\t// ChecksState is the head commit's status check rollup, as in Snapshot:\n\t// checks concluding do not move UpdatedAt.\n\tChecksState string\n\t// FailedChecks are the names of the head's failed checks, sorted: a\n\t// check can fail or recover without moving UpdatedAt or the rollup.\n\tFailedChecks []string\n\tState        string // OPEN, CLOSED or MERGED\n\t// Mergeable, as in PullRequest: a base that moves leaves UpdatedAt.\n\tMergeable string\n}\n```\nStub is what the cheap search or by-ref read returns: enough to decide whether to read the full snapshot.\n\n```go\ntype StubPage struct {\n\tStubs     []Stub\n\tHasNext   bool\n\tEndCursor string\n\tRateLimit RateLimit\n}\n```\n\n","path":"github.com/wloophq/wloop/plugins/github/api","name":"api","synopsis":"Package github reads pull requests over GitHub's HTTPS API, batching every pull request of a sweep into aliased GraphQL queries.","isRedistributable":true}
