github

package
v0.16.0 Latest Latest
Warning

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

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

Documentation

Overview

Package github provides GitHub PR operations via the gh CLI.

Package github provides GitHub PR operations via the gh CLI.

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthFailed = errors.New("GitHub authentication failed")

ErrAuthFailed indicates GitHub authentication failed.

View Source
var ErrNoForkPRFound = fmt.Errorf("no open PR found for fork reference")

ErrNoForkPRFound indicates no PR exists for the given fork reference.

View Source
var ErrNoPRFound = errors.New("no pull request found")

ErrNoPRFound indicates no pull request exists for the given branch.

Functions

func ApprovePR

func ApprovePR(ctx context.Context, prNumber, body string) error

ApprovePR approves a PR with the given body.

func CheckGHAvailable added in v0.4.0

func CheckGHAvailable() error

CheckGHAvailable returns an error if the gh CLI is not available.

func GetCurrentPRNumber

func GetCurrentPRNumber(ctx context.Context, branch string) (string, error)

GetCurrentPRNumber returns the PR number for the given branch (or current branch). Returns ErrNoPRFound if no PR exists, ErrAuthFailed if authentication failed, or another error for other failures.

func GetCurrentUser

func GetCurrentUser(ctx context.Context) string

GetCurrentUser returns the username of the authenticated gh user. Returns empty string on error.

func GetPRAuthor

func GetPRAuthor(ctx context.Context, prNumber string) string

GetPRAuthor returns the username of the PR author. Returns empty string on error.

func GetPRBaseRef added in v0.9.0

func GetPRBaseRef(ctx context.Context, prNumber string) (string, error)

GetPRBaseRef returns the base branch name for a PR number. Returns ErrNoPRFound if no PR exists, ErrAuthFailed if authentication failed.

func GetPRBranch added in v0.9.0

func GetPRBranch(ctx context.Context, prNumber string) (string, error)

GetPRBranch returns the head branch name for a PR number. Returns ErrNoPRFound if no PR exists, ErrAuthFailed if authentication failed.

func GetRepoRemote added in v0.9.0

func GetRepoRemote(ctx context.Context) string

GetRepoRemote returns the git remote name that corresponds to the current gh repo. This handles fork workflows where "origin" may point to a fork, not the base repo. Falls back to "origin" if detection fails.

func IsGHAvailable

func IsGHAvailable() bool

IsGHAvailable checks if the gh CLI is available.

func IsSelfReview

func IsSelfReview(ctx context.Context, prNumber string) bool

IsSelfReview checks if the current user is the author of the PR.

func ParseForkNotation added in v0.8.0

func ParseForkNotation(ref string) (username, branch string, ok bool)

ParseForkNotation parses GitHub's "username:branch" fork notation. Returns the username, branch, and true if valid fork notation. Returns "", "", false if not fork notation or invalid.

func SubmitPRReview added in v0.4.1

func SubmitPRReview(ctx context.Context, prNumber, body string, requestChanges bool) error

SubmitPRReview submits a PR review with the given body. If requestChanges is true, uses --request-changes; otherwise uses --comment.

func ValidatePR added in v0.9.0

func ValidatePR(ctx context.Context, prNumber string) error

ValidatePR checks that a PR exists and is accessible. Returns nil if the PR exists, or a descriptive error: - ErrNoPRFound if the PR doesn't exist - ErrAuthFailed if authentication failed - Other error for unexpected failures

Types

type CICheck

type CICheck struct {
	Name   string `json:"name"`
	Bucket string `json:"bucket"`
}

CICheck represents a single CI check from the GitHub API.

type CIStatus

type CIStatus struct {
	AllPassed bool
	Pending   []string
	Failed    []string
	Error     string
}

CIStatus represents the CI check status for a PR.

func CheckCIStatus

func CheckCIStatus(ctx context.Context, prNumber string) CIStatus

CheckCIStatus checks the CI status for a PR.

func ParseCIChecks

func ParseCIChecks(data []byte) CIStatus

ParseCIChecks parses CI check JSON output and categorizes results.

type ForkRef added in v0.8.0

type ForkRef struct {
	Username   string // Fork owner username (e.g., "yunidbauza")
	Branch     string // Branch name (e.g., "feat/enable-pr-number-review")
	RepoURL    string // Clone URL (e.g., "https://github.com/yunidbauza/repo.git")
	RemoteName string // Temporary remote name (e.g., "fork-yunidbauza")
	PRNumber   int    // Associated PR number
}

ForkRef contains resolved information about a fork reference.

func ResolveForkRef added in v0.8.0

func ResolveForkRef(ctx context.Context, ref string) (*ForkRef, error)

ResolveForkRef detects and resolves "username:branch" fork notation. Returns (*ForkRef, nil) for valid fork refs with an open PR. Returns (nil, nil) if ref is not fork notation (caller should use ref as-is). Returns (nil, error) if fork notation is used but resolution fails.

Jump to

Keyboard shortcuts

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