github

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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

View Source
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

func New(baseURL, owner, repo, baseBranch string, token TokenFunc) *Client

New builds a client. baseURL may be empty (defaults to DefaultBaseURL); baseBranch is the PR target (e.g. "main").

func (*Client) Close

func (c *Client) Close(ctx context.Context, number int) error

Close closes an issue or PR (they share the issues endpoint for state).

func (*Client) Comment

func (c *Client) Comment(ctx context.Context, number int, body string) error

Comment posts a comment on an issue.

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) 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).

func (*Client) OpenIssue

func (c *Client) OpenIssue(ctx context.Context, inv providers.Investigation) (providers.Ref, error)

OpenIssue files an issue describing the investigation.

func (*Client) OpenPR

func (c *Client) OpenPR(ctx context.Context, e providers.KBEntry) (providers.Ref, error)

OpenPR drafts the KB entry on a new branch and opens a PR.

func (*Client) ReplaceLabel

func (c *Client) ReplaceLabel(ctx context.Context, number int, remove, add string) error

ReplaceLabel removes one label and adds another (best-effort on the removal — a 404 when the label isn't present is not fatal).

type TokenFunc

type TokenFunc func(ctx context.Context) (string, error)

TokenFunc returns a valid installation token (minted/cached by the caller).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL