ghapi

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseRepo

func ParseRepo(url string) (owner, repo string, err error)

ParseRepo extracts owner/repo from a git remote URL in either form:

https://github.com/owner/repo.git
git@github.com:owner/repo.git

Types

type Asset

type Asset struct {
	ID   int64
	Name string
	Size int
	URL  string
}

Asset is a trimmed release-asset view.

type CheckRun

type CheckRun struct {
	Name       string
	Status     string // queued, in_progress, completed
	Conclusion string // success, failure, neutral, cancelled, ... (empty until completed)
}

CheckRun is a trimmed view of one CI check on a commit.

type Client

type Client struct {
	Owner string
	Repo  string
	// contains filtered or unexported fields
}

Client wraps the go-github client plus the resolved owner/repo.

func New

func New(ctx context.Context, owner, repo string) (*Client, error)

New builds an authenticated client. The token is resolved from, in order:

  1. the GITHUB_TOKEN process environment variable
  2. a .env file (walking up from the working directory)
  3. the persisted user environment variable (Windows), via `gh auth token`

The first non-empty source wins.

func (*Client) AddAssignees

func (c *Client) AddAssignees(ctx context.Context, owner, repo string, number int, users []string) error

AddAssignees adds users as assignees on an issue or pull request.

func (*Client) AddLabels

func (c *Client) AddLabels(ctx context.Context, owner, repo string, number int, labels []string) error

AddLabels adds labels to an issue or PR (PRs are issues here).

func (*Client) CancelRun

func (c *Client) CancelRun(ctx context.Context, owner, repo string, runID int64) error

CancelRun cancels an in-progress workflow run. Requires a token with the workflow scope.

func (*Client) CommentPR

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

CommentPR posts a comment on a PR or issue (they share the comment endpoint).

func (*Client) CreateIssue

func (c *Client) CreateIssue(ctx context.Context, owner, repo, title, body string) (int, string, error)

CreateIssue opens an issue. Returns the new issue number and its HTML URL.

func (*Client) CreateLabel

func (c *Client) CreateLabel(ctx context.Context, owner, repo, name, color, description string) error

CreateLabel creates a new label definition (color = 6-hex, no #).

func (*Client) CreatePR

func (c *Client) CreatePR(ctx context.Context, owner, repo, title, body, head, base string) (int, string, error)

CreatePR opens a pull request from head into base. head is a branch name (e.g. "feature/x"); base is usually the default branch (e.g. "live"). Returns the new PR number and its HTML URL.

func (*Client) CreateRelease

func (c *Client) CreateRelease(ctx context.Context, owner, repo, tag, name, body string, draft, prerelease bool) (Release, error)

CreateRelease creates a release on the given tag.

func (*Client) CreateRepo

func (c *Client) CreateRepo(ctx context.Context, name, description string, private bool) (string, error)

CreateRepo creates a new repository under the authenticated user's account. Passing "" as the org means "create it on my own account."

func (*Client) DefaultBranch

func (c *Client) DefaultBranch(ctx context.Context, owner, repo string) (string, error)

DefaultBranch returns the repository's default branch (e.g. "main"/"live"), used as the sensible base when opening a pull request.

func (*Client) DeleteAsset

func (c *Client) DeleteAsset(ctx context.Context, owner, repo string, assetID int64) error

DeleteAsset removes an asset from a release.

func (*Client) DeleteIssueComment

func (c *Client) DeleteIssueComment(ctx context.Context, owner, repo string, commentID int64) error

DeleteIssueComment deletes an issue/PR comment by its ID.

func (*Client) DeleteLabel

func (c *Client) DeleteLabel(ctx context.Context, owner, repo, name string) error

DeleteLabel removes a label definition from the repo.

func (*Client) DeleteRelease

func (c *Client) DeleteRelease(ctx context.Context, owner, repo string, id int64) error

DeleteRelease removes a release by ID (does NOT delete the underlying tag).

func (*Client) DownloadAsset

func (c *Client) DownloadAsset(ctx context.Context, owner, repo string, assetID int64) ([]byte, error)

DownloadAsset returns the raw bytes of a release asset.

func (*Client) EditIssueComment

func (c *Client) EditIssueComment(ctx context.Context, owner, repo string, commentID int64, body string) error

EditIssueComment edits the body of an existing issue/PR comment by its ID.

func (*Client) EditLabel

func (c *Client) EditLabel(ctx context.Context, owner, repo, name, newName, color, description string) error

EditLabel updates an existing label. newName can equal name to keep it.

func (*Client) EditRelease

func (c *Client) EditRelease(ctx context.Context, owner, repo string, id int64, name, body string, draft, prerelease bool) (Release, error)

EditRelease updates an existing release by ID.

func (*Client) GenerateReleaseNotes

func (c *Client) GenerateReleaseNotes(ctx context.Context, owner, repo, tag string) (name, body string, err error)

GenerateReleaseNotes asks GitHub to auto-generate notes for a tag.

func (*Client) GetRun

func (c *Client) GetRun(ctx context.Context, owner, repo string, runID int64) (WorkflowRun, error)

GetRun returns a single run's summary.

func (*Client) IssueListGraphQL

func (c *Client) IssueListGraphQL(ctx context.Context, owner, repo, state string) ([]IssueListItem, error)

IssueListGraphQL fetches issues (by state) with labels + assignees in one query. state: "open"/"closed"/"all".

func (*Client) JobLogs

func (c *Client) JobLogs(ctx context.Context, owner, repo string, jobID int64) (JobLog, error)

JobLogs downloads a single job's log (completed runs only) and returns it, best-effort split per step using GitHub's "##[group]" markers. On any parse uncertainty the Raw whole-job log is always available as a fallback.

func (*Client) ListAssets

func (c *Client) ListAssets(ctx context.Context, owner, repo string, releaseID int64) ([]Asset, error)

ListAssets returns the assets attached to a release.

func (*Client) ListDispatchableWorkflows

func (c *Client) ListDispatchableWorkflows(ctx context.Context, owner, repo string) ([]DispatchableWorkflow, error)

ListDispatchableWorkflows returns workflows that declare a workflow_dispatch trigger, with their inputs parsed from the workflow YAML. This drives a dynamic dispatch form (render a field per declared input).

func (*Client) ListIssueComments

func (c *Client) ListIssueComments(ctx context.Context, owner, repo string, number int) ([]IssueComment, error)

ListIssueComments returns the general (non-line) comment stream on a PR.

func (*Client) ListIssues

func (c *Client) ListIssues(ctx context.Context, owner, repo, state string) ([]Issue, error)

ListIssues returns issues for owner/repo — with PRs filtered out.

func (*Client) ListLabels

func (c *Client) ListLabels(ctx context.Context, owner, repo string) ([]Label, error)

ListLabels returns all label definitions in the repo.

func (*Client) ListMilestones

func (c *Client) ListMilestones(ctx context.Context, owner, repo, state string) ([]Milestone, error)

ListMilestones returns the repository's milestones (open by default; pass "all" or "closed" for others).

func (*Client) ListPRs

func (c *Client) ListPRs(ctx context.Context, owner, repo, state string) ([]PR, error)

ListPRs returns pull requests for owner/repo in the given state ("open", "closed", or "all").

func (*Client) ListReleases

func (c *Client) ListReleases(ctx context.Context, owner, repo string) ([]Release, error)

ListReleases returns the repo's releases, newest first.

func (*Client) ListRequestedReviewers

func (c *Client) ListRequestedReviewers(ctx context.Context, owner, repo string, number int) ([]Reviewer, error)

ListRequestedReviewers returns users whose review has been requested but not yet submitted.

func (*Client) ListReviewComments

func (c *Client) ListReviewComments(ctx context.Context, owner, repo string, number int) ([]ExistingComment, error)

ListReviewComments returns the line-anchored review comments on a PR.

func (*Client) ListReviews

func (c *Client) ListReviews(ctx context.Context, owner, repo string, number int) ([]Review, error)

ListReviews returns the submitted reviews on a PR, oldest first.

func (*Client) ListRunJobs

func (c *Client) ListRunJobs(ctx context.Context, owner, repo string, runID int64) ([]Job, error)

ListRunJobs returns the jobs (with steps) for a run.

func (*Client) ListRuns

func (c *Client) ListRuns(ctx context.Context, owner, repo string, limit int) ([]WorkflowRun, error)

ListRuns returns recent workflow runs for the repo, newest first.

func (*Client) ListWorkflows

func (c *Client) ListWorkflows(ctx context.Context, owner, repo string) ([]Workflow, error)

ListWorkflows returns the repo's workflow definitions.

func (*Client) LockConversation

func (c *Client) LockConversation(ctx context.Context, owner, repo string, number int, reason string) error

LockConversation locks an issue or PR conversation. reason may be "off-topic", "too heated", "resolved", "spam", or "" for no reason.

func (*Client) MergePR

func (c *Client) MergePR(ctx context.Context, owner, repo string, number int, method string) (string, error)

MergePR merges a pull request. method is "merge", "squash", or "rebase". Returns the merge commit SHA on success.

func (*Client) PRChecks

func (c *Client) PRChecks(ctx context.Context, owner, repo string, number int) ([]CheckRun, error)

PRChecks returns the CI check runs for a PR's head commit — this is how you see whether GitHub Actions (your own CI) passed on the PR.

func (*Client) PRDetailGraphQL

func (c *Client) PRDetailGraphQL(ctx context.Context, owner, repo string, number int) (*PRDetail, error)

PRDetailGraphQL fetches everything about a PR in a single GraphQL query.

func (*Client) PRDiff

func (c *Client) PRDiff(ctx context.Context, owner, repo string, number int) ([]gitops.FileDiff, error)

PRDiff fetches the PR's unified diff and parses it into the same []gitops.FileDiff that DiffView already renders.

func (*Client) PRListGraphQL

func (c *Client) PRListGraphQL(ctx context.Context, owner, repo, state string) ([]PRListItem, error)

PRListGraphQL fetches PRs (by state) with per-PR review decision + check rollup in a single query. state: "OPEN", "CLOSED", "MERGED" (GraphQL enums).

func (*Client) RateLimit

func (c *Client) RateLimit(ctx context.Context) (remaining, limit int, err error)

RateLimit reports remaining core API calls — useful to watch while you learn, since unauthenticated requests are capped at 60/hour.

func (*Client) RemoveAssignees

func (c *Client) RemoveAssignees(ctx context.Context, owner, repo string, number int, users []string) error

RemoveAssignees removes users from the assignees of an issue or pull request.

func (*Client) RemoveLabel

func (c *Client) RemoveLabel(ctx context.Context, owner, repo string, number int, label string) error

RemoveLabel removes a single label from an issue or PR.

func (*Client) RemoveReviewer

func (c *Client) RemoveReviewer(ctx context.Context, owner, repo string, number int, login string) error

RemoveReviewer withdraws a review request from a user.

func (*Client) ReplyToReviewComment

func (c *Client) ReplyToReviewComment(ctx context.Context, owner, repo string, number int, commentID int64, body string) error

ReplyToReviewComment posts a reply to an existing review comment thread.

func (*Client) RequestReviewers

func (c *Client) RequestReviewers(ctx context.Context, owner, repo string, number int, logins []string) error

RequestReviewers asks the given users to review the PR.

func (*Client) RerunFailed

func (c *Client) RerunFailed(ctx context.Context, owner, repo string, runID int64) error

RerunFailed re-runs only the failed jobs of a completed run.

func (*Client) RerunRun

func (c *Client) RerunRun(ctx context.Context, owner, repo string, runID int64) error

RerunRun re-runs all jobs of a completed run.

func (*Client) ResolveThread

func (c *Client) ResolveThread(ctx context.Context, threadID string) error

ResolveThread marks a review thread resolved (GraphQL-only; no REST equivalent).

func (*Client) RunJobGraph

func (c *Client) RunJobGraph(ctx context.Context, owner, repo string, runID int64) ([]JobNode, error)

RunJobGraph returns the job dependency graph for a run's workflow, parsed from the workflow YAML (jobs.<name>.needs). The GUI overlays live job status onto this to draw a flowchart. Falls back to a flat (no-edges) graph if YAML parse fails or needs aren't declared.

func (*Client) SetIssueState

func (c *Client) SetIssueState(ctx context.Context, owner, repo string, number int, state string) error

SetIssueState closes or reopens an issue. state is "closed" or "open".

func (*Client) SetLabels

func (c *Client) SetLabels(ctx context.Context, owner, repo string, number int, labels []string) error

SetLabels replaces all labels on an issue or PR with the given set.

func (*Client) SetMilestone

func (c *Client) SetMilestone(ctx context.Context, owner, repo string, number, milestone int) error

SetMilestone assigns an issue/PR to a milestone by number; pass 0 to clear it.

func (*Client) SetPRState

func (c *Client) SetPRState(ctx context.Context, owner, repo string, number int, state string) error

SetPRState closes or reopens a pull request. state is "closed" or "open".

func (*Client) SubmitReview

func (c *Client) SubmitReview(ctx context.Context, owner, repo string, number int, event, body string, comments []ReviewComment) error

SubmitReview posts a whole-PR review. event is "APPROVE", "REQUEST_CHANGES", or "COMMENT". body is optional for APPROVE but required by GitHub for REQUEST_CHANGES and COMMENT.

func (*Client) TriggerDispatch

func (c *Client) TriggerDispatch(ctx context.Context, owner, repo, workflowFile, ref string, inputs map[string]interface{}) error

TriggerDispatch fires a workflow_dispatch event on the given workflow file (e.g. "release.yml") for a ref (branch/tag), with input values.

func (*Client) UnlockConversation

func (c *Client) UnlockConversation(ctx context.Context, owner, repo string, number int) error

UnlockConversation unlocks a previously locked issue or PR conversation.

func (*Client) UnresolveThread

func (c *Client) UnresolveThread(ctx context.Context, threadID string) error

UnresolveThread reopens a resolved review thread.

func (*Client) UploadAsset

func (c *Client) UploadAsset(ctx context.Context, owner, repo string, releaseID int64, name string, data []byte) (Asset, error)

UploadAsset attaches a file (name + raw bytes) to a release.

func (*Client) Whoami

func (c *Client) Whoami(ctx context.Context) (string, error)

Whoami returns the authenticated user's login — a cheap call to confirm the token works and to see your rate-limit headers.

type DispatchInput

type DispatchInput struct {
	Name        string
	Description string
	Required    bool
	Default     string
	Type        string   // string, boolean, choice, number, environment
	Options     []string // for type=choice
}

DispatchInput describes one workflow_dispatch input the workflow defines.

type DispatchableWorkflow

type DispatchableWorkflow struct {
	ID     int64
	Name   string
	Path   string
	Inputs []DispatchInput
}

DispatchableWorkflow is a workflow that has a workflow_dispatch trigger, with its declared inputs (parsed from the workflow YAML).

type ExistingComment

type ExistingComment struct {
	ID        int64
	Path      string
	Line      int
	Author    string
	Body      string
	InReplyTo int64
}

ExistingComment is a review comment already posted on the PR, anchored to a file + line. ReplyToID (0 if top-level) links a reply to its parent thread.

type Issue

type Issue struct {
	Number int
	Title  string
	Author string
	State  string
	When   time.Time
	Labels []string
}

Issue is a trimmed issue view.

type IssueComment

type IssueComment struct {
	ID     int64
	Author string
	Body   string
}

IssueComment is a general (not line-anchored) PR comment from the issue stream.

type IssueListItem

type IssueListItem struct {
	Number    int
	Title     string
	Author    string
	State     string
	Labels    []string
	Assignees []string
}

IssueListItem is an issue with its labels + assignees, fetched via GraphQL's issues connection (which — unlike the REST issues endpoint — returns ONLY issues, never PRs, so no client-side PR filtering is needed).

type Job

type Job struct {
	ID         int64
	Name       string
	Status     string
	Conclusion string
	Steps      []Step
}

Job is a job within a run; Steps are its steps.

type JobLog

type JobLog struct {
	JobName string
	Steps   []StepLog
	Raw     string // full log; shown when per-step split isn't reliable
}

JobLog is a job's captured log, split (best-effort) into per-step sections.

type JobNode

type JobNode struct {
	Name  string
	Needs []string
}

JobNode is a job in the workflow's dependency graph: its name and the jobs it needs (must complete first). Parsed from the workflow YAML.

type Label

type Label struct {
	Name        string
	Color       string
	Description string
}

Label is a repo label definition: name, hex color (no leading #), description.

type Milestone

type Milestone struct {
	Number int
	Title  string
	State  string
}

Milestone is a repository milestone (number + title + open/closed state).

type PR

type PR struct {
	Number int
	Title  string
	Author string
	State  string
	When   time.Time
	Draft  bool
	Labels []string
}

PR is a trimmed pull-request view.

type PRDetail

type PRDetail struct {
	Number    int
	Title     string
	State     string
	Body      string
	Author    string
	Labels    []string
	Assignees []string
	Reviews   []PRDetailReview
	Threads   []PRDetailThread
	Checks    []PRDetailCheck
}

PRDetail is the aggregated PR view fetched in ONE GraphQL query — the whole point of the GraphQL path: reviews + review threads + checks + labels + assignees together, instead of many REST round-trips.

type PRDetailCheck

type PRDetailCheck struct {
	Name       string
	Status     string
	Conclusion string
}

PRDetailCheck is a CI check on a PR's head commit (name + status + conclusion).

type PRDetailReview

type PRDetailReview struct {
	Author string
	State  string
	Body   string
}

PRDetailReview is a review on a PR (author + state + body) from the aggregated GraphQL query.

type PRDetailThread

type PRDetailThread struct {
	ID         string
	Path       string
	Line       int
	IsResolved bool
	Comments   []PRDetailThreadComment
}

PRDetailThread is a review-comment thread with its resolve state and GraphQL node ID (needed for the resolve/unresolve mutations — REST has no equivalent).

type PRDetailThreadComment

type PRDetailThreadComment struct {
	Author string
	Body   string
}

PRDetailThreadComment is one comment within a review thread.

type PRListItem

type PRListItem struct {
	Number         int
	Title          string
	Author         string
	State          string
	Draft          bool
	Labels         []string
	ReviewDecision string // APPROVED / CHANGES_REQUESTED / REVIEW_REQUIRED / ""
	ChecksTotal    int
	ChecksPassed   int
	ChecksFailed   int
	ChecksPending  int
}

PRListItem is a PR in a list view WITH its rollup status (labels, review decision, CI check summary) — fetched in ONE GraphQL query for the whole list, instead of REST's N+1 (list + per-PR checks/reviews).

type Release

type Release struct {
	ID         int64
	TagName    string
	Name       string
	Body       string
	Draft      bool
	Prerelease bool
	Immutable  bool
	URL        string
}

Release is a trimmed GitHub release view.

type Review

type Review struct {
	ID     int64
	Author string
	State  string // APPROVED, CHANGES_REQUESTED, COMMENTED, DISMISSED, PENDING
	Body   string
}

Review is a trimmed PR review (a whole-PR verdict).

type ReviewComment

type ReviewComment struct {
	Path string
	Line int
	Body string
}

ReviewComment is a pending line comment to attach to a submitted review. Path is the file path; Line is the line number in the file's new version; Body is the comment text.

type Reviewer

type Reviewer struct {
	Login string
}

Reviewer is a requested (not-yet-submitted) reviewer on a PR.

type Step

type Step struct {
	Name       string
	Status     string
	Conclusion string
	Number     int
}

Step is a single step within an Actions job (name + status/conclusion).

type StepLog

type StepLog struct {
	Name string
	Text string
}

StepLog is the parsed log output for one step of a job (name + its log lines).

type Workflow

type Workflow struct {
	ID    int64
	Name  string
	State string
	Path  string
}

Workflow is a repo workflow definition.

type WorkflowRun

type WorkflowRun struct {
	ID           int64
	Name         string
	WorkflowID   int64
	WorkflowName string // for grouping (falls back to Name)
	Status       string // queued, in_progress, completed
	Conclusion   string // success, failure, cancelled, "" while running
	Branch       string
	Event        string
	Number       int
	CreatedAt    string
	Duration     string // human-readable run duration ("1m23s"), "" if not finished/started
	URL          string
}

WorkflowRun is one execution of a workflow.

Jump to

Keyboard shortcuts

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