github

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	Status           CheckStatus
	Summary          string  // Human-readable summary of failures
	FailedRunIDs     []int64 // GitHub Actions job IDs for failed check runs
	FailedNames      []string
	CheckRunsSkipped bool              // True when check runs API returned 403 (fine-grained PAT)
	Checks           []IndividualCheck // Individual check details
}

CheckResult holds the result of a PR check query.

type CheckStatus

type CheckStatus string

CheckStatus represents the combined CI check result for a PR.

const (
	CheckStatusPending CheckStatus = "pending"
	CheckStatusSuccess CheckStatus = "success"
	CheckStatusFailure CheckStatus = "failure"
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles GitHub API interactions.

func NewClient

func NewClient(token string, insecureSkipVerify bool) *Client

NewClient creates a new GitHub API client. Returns nil if token is empty. If insecureSkipVerify is true, TLS certificate verification is disabled. This may be required in networks with TLS-intercepting proxies.

func (*Client) ClosePR

func (c *Client) ClosePR(ctx context.Context, owner, repoName string, prNumber int) (headBranch string, err error)

ClosePR closes an open pull request and returns the head branch name.

func (*Client) DeleteBranch

func (c *Client) DeleteBranch(ctx context.Context, owner, repoName, branch string) error

DeleteBranch deletes a branch from a repository.

func (*Client) FindPRForBranch

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

FindPRForBranch searches for an open PR with the given head branch. Returns the PR URL, number, and nil error if found. Returns empty/0 if no PR exists.

func (*Client) GetFailedCheckLogs

func (c *Client) GetFailedCheckLogs(ctx context.Context, owner, repoName string, prNumber int) (string, error)

GetFailedCheckLogs fetches the log output of failed check runs for a PR. For each failed job it identifies the exact failed step and returns the last 150 lines of that step's logs. Returns a combined, truncated string (~8KB max).

func (*Client) GetPRCheckStatus

func (c *Client) GetPRCheckStatus(ctx context.Context, owner, repo string, prNumber int) (*CheckResult, error)

GetPRCheckStatus returns the combined check status for a PR's head commit. It checks both GitHub Actions (check runs) and legacy commit statuses. The check runs endpoint requires the "Checks" permission which is not available on fine-grained PATs, so a 403 is handled gracefully by falling back to commit statuses only.

func (*Client) GetPRDiff

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

GetPRDiff fetches the unified diff for a pull request using the GitHub API. It uses the Accept: application/vnd.github.v3.diff header to get raw diff text. The response body is limited to maxDiffSize bytes.

func (*Client) GetPRMergeability

func (c *Client) GetPRMergeability(ctx context.Context, owner, repo string, prNumber int) (*PRMergeability, error)

GetPRMergeability checks whether a PR has merge conflicts.

func (*Client) IsPRMerged

func (c *Client) IsPRMerged(ctx context.Context, owner, repo string, prNumber int) (bool, error)

IsPRMerged checks if a PR has been merged for the given owner/repo.

func (*Client) ListAccessibleRepos

func (c *Client) ListAccessibleRepos(ctx context.Context) ([]*GitHubRepo, error)

ListAccessibleRepos returns repositories the authenticated user has access to.

func (*Client) UpdatePR

func (c *Client) UpdatePR(ctx context.Context, owner, repoName string, prNumber int, title, body string) error

UpdatePR updates the title and body of an existing pull request.

type GitHubRepo

type GitHubRepo struct {
	FullName    string `json:"full_name"`
	Owner       string `json:"owner_login"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Private     bool   `json:"private"`
	HTMLURL     string `json:"html_url"`
}

GitHubRepo represents a repository returned by the GitHub API.

type IndividualCheck

type IndividualCheck struct {
	Name       string `json:"name"`
	Status     string `json:"status"`     // "queued", "in_progress", "completed", "pending", "success", "failure", "error"
	Conclusion string `json:"conclusion"` // "success", "failure", "neutral", "cancelled", "skipped", "timed_out", ""
	URL        string `json:"url"`        // Link to the check on GitHub
}

IndividualCheck represents a single CI check with its status and link.

type PRMergeability

type PRMergeability struct {
	Mergeable      *bool  // nil = not yet computed by GitHub
	MergeableState string // "clean", "dirty", "blocked", "behind", "unstable"
	HasConflicts   bool   // true when mergeable_state == "dirty"
}

PRMergeability holds the mergeability state of a PR.

Jump to

Keyboard shortcuts

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