Documentation
¶
Index ¶
- type CheckResult
- type CheckStatus
- type Client
- func (c *Client) ClosePR(ctx context.Context, owner, repoName string, prNumber int) (headBranch string, err error)
- func (c *Client) DeleteBranch(ctx context.Context, owner, repoName, branch string) error
- func (c *Client) FindPRForBranch(ctx context.Context, owner, repo, branch string) (string, int, error)
- func (c *Client) GetFailedCheckLogs(ctx context.Context, owner, repoName string, prNumber int) (string, error)
- func (c *Client) GetPRCheckStatus(ctx context.Context, owner, repo string, prNumber int) (*CheckResult, error)
- func (c *Client) GetPRDiff(ctx context.Context, owner, repo string, prNumber int) (string, error)
- func (c *Client) GetPRMergeability(ctx context.Context, owner, repo string, prNumber int) (*PRMergeability, error)
- func (c *Client) IsPRMerged(ctx context.Context, owner, repo string, prNumber int) (bool, error)
- func (c *Client) ListAccessibleRepos(ctx context.Context) ([]*GitHubRepo, error)
- func (c *Client) UpdatePR(ctx context.Context, owner, repoName string, prNumber int, title, body string) error
- type GitHubRepo
- type IndividualCheck
- type PRMergeability
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 ¶
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 ¶
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 ¶
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 ¶
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.
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.