Documentation
¶
Overview ¶
Package github is RunLore's GitHub forge client (curation + re-investigation) over the GitHub REST API, authenticated with short-lived GitHub App installation tokens. It satisfies providers.CurationForge / providers.ReinvestForge / curate.Forge.
Index ¶
- Constants
- func ParsePrivateKey(pemData string) (*rsa.PrivateKey, error)
- type AppTokenSource
- type Client
- func (c *Client) Close(ctx context.Context, number int) error
- func (c *Client) Comment(ctx context.Context, number int, body string) error
- func (c *Client) IsPROpen(ctx context.Context, number int) (bool, error)
- func (c *Client) ListClosedUnmergedPRsByLabel(ctx context.Context, label string) ([]providers.CuratedIssue, error)
- func (c *Client) ListIssueCommentBodies(ctx context.Context, number int) ([]string, error)
- func (c *Client) ListIssuesByLabel(ctx context.Context, label string) ([]providers.CuratedIssue, error)
- func (c *Client) ListPRsByLabel(ctx context.Context, label string) ([]providers.CuratedIssue, error)
- func (c *Client) OpenIssue(ctx context.Context, inv providers.Investigation) (providers.Ref, error)
- func (c *Client) OpenPR(ctx context.Context, e providers.KBEntry) (providers.Ref, error)
- func (c *Client) ReplaceLabel(ctx context.Context, number int, remove, add string) error
- type TokenFunc
Constants ¶
const DefaultBaseURL = "https://api.github.com"
DefaultBaseURL is the public GitHub REST API. Override for GitHub Enterprise Server (e.g. https://ghe.example.com/api/v3) or tests.
Variables ¶
This section is empty.
Functions ¶
func ParsePrivateKey ¶
func ParsePrivateKey(pemData string) (*rsa.PrivateKey, error)
ParsePrivateKey parses a PEM-encoded RSA private key (PKCS#1 or PKCS#8).
Types ¶
type AppTokenSource ¶
type AppTokenSource struct {
// contains filtered or unexported fields
}
AppTokenSource mints and caches GitHub App installation tokens.
func NewAppTokenSource ¶
func NewAppTokenSource(baseURL string, appID, installID int64, key *rsa.PrivateKey) *AppTokenSource
NewAppTokenSource builds a token source from an App ID, installation ID, and RSA private key. baseURL may be empty (defaults to DefaultBaseURL).
func (*AppTokenSource) Token ¶
func (s *AppTokenSource) Token(ctx context.Context) (string, error)
Token returns a valid installation token, refreshing when near expiry. The network refresh runs WITHOUT holding the lock (double-checked locking), so a slow/hung GitHub round-trip can't block every other token consumer.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a GitHub forge client scoped to one repo.
func New ¶
New builds a client. baseURL may be empty (defaults to DefaultBaseURL); baseBranch is the PR target (e.g. "main").
func (*Client) IsPROpen ¶ added in v0.8.0
IsPROpen reports whether number is an OPEN pull request. It deliberately hits the pulls endpoint (not issues): a number that is actually an issue 404s there instead of passing, so a caller gating "comment on the open KB PR" can never be fooled into treating an issue as a PR.
func (*Client) ListClosedUnmergedPRsByLabel ¶ added in v0.4.0
func (c *Client) ListClosedUnmergedPRsByLabel(ctx context.Context, label string) ([]providers.CuratedIssue, error)
ListClosedUnmergedPRsByLabel returns closed PRs carrying the label that were NOT merged — the KB entries a human deliberately rejected. It drives the curate suppression set: a rejected entry that keeps recurring is escalated via a knowledge-gap issue, never reopened.
It queries the GitHub Search API (is:pr is:closed is:unmerged) so merged PRs are filtered out server-side. The plain closed-issues endpoint returns every merged AND unmerged KB PR ever, and the closed set only grows: over time the merged entries (which we discard) dominate, so each curate run would download and decode the entire KB PR history to keep a handful of rejections. The search keeps the response bounded by the closed-unmerged set. The MergedAt filter below is retained as a correctness backstop should the query ever be loosened.
func (*Client) ListIssueCommentBodies ¶ added in v0.8.0
ListIssueCommentBodies fetches ALL pages of an issue/PR's comment bodies (the issues-comments endpoint serves both — PR discussion comments live there). Callers scan the bodies for hidden idempotency markers, so pagination matters: a marker past the first 100 comments would otherwise be invisible and the caller would re-post forever.
func (*Client) ListIssuesByLabel ¶
func (c *Client) ListIssuesByLabel(ctx context.Context, label string) ([]providers.CuratedIssue, error)
ListIssuesByLabel returns all open issues carrying the given label. Pull requests (which the issues API also returns) are filtered out.
func (*Client) ListPRsByLabel ¶
func (c *Client) ListPRsByLabel(ctx context.Context, label string) ([]providers.CuratedIssue, error)
ListPRsByLabel returns all open PRs carrying the given label — the inverse of ListIssuesByLabel (keeps only entries with a pull_request object).