Documentation
¶
Overview ¶
Package github provides GitHub PR operations via the gh CLI.
Package github provides GitHub PR operations via the gh CLI.
Index ¶
- Variables
- func ApprovePR(ctx context.Context, prNumber, body string) error
- func CheckGHAvailable() error
- func GetCurrentPRNumber(ctx context.Context, branch string) (string, error)
- func GetCurrentUser(ctx context.Context) string
- func GetPRAuthor(ctx context.Context, prNumber string) string
- func GetPRBaseRef(ctx context.Context, prNumber string) (string, error)
- func GetPRBranch(ctx context.Context, prNumber string) (string, error)
- func GetRepoRemote(ctx context.Context) string
- func IsGHAvailable() bool
- func IsSelfReview(ctx context.Context, prNumber string) bool
- func ParseForkNotation(ref string) (username, branch string, ok bool)
- func SubmitPRReview(ctx context.Context, prNumber, body string, requestChanges bool) error
- func ValidatePR(ctx context.Context, prNumber string) error
- type CICheck
- type CIStatus
- type ForkRef
Constants ¶
This section is empty.
Variables ¶
var ErrAuthFailed = errors.New("GitHub authentication failed")
ErrAuthFailed indicates GitHub authentication failed.
var ErrNoForkPRFound = fmt.Errorf("no open PR found for fork reference")
ErrNoForkPRFound indicates no PR exists for the given fork reference.
var ErrNoPRFound = errors.New("no pull request found")
ErrNoPRFound indicates no pull request exists for the given branch.
Functions ¶
func CheckGHAvailable ¶ added in v0.4.0
func CheckGHAvailable() error
CheckGHAvailable returns an error if the gh CLI is not available.
func GetCurrentPRNumber ¶
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 ¶
GetCurrentUser returns the username of the authenticated gh user. Returns empty string on error.
func GetPRAuthor ¶
GetPRAuthor returns the username of the PR author. Returns empty string on error.
func GetPRBaseRef ¶ added in v0.9.0
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
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
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 IsSelfReview ¶
IsSelfReview checks if the current user is the author of the PR.
func ParseForkNotation ¶ added in v0.8.0
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
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
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 CIStatus ¶
CIStatus represents the CI check status for a PR.
func CheckCIStatus ¶
CheckCIStatus checks the CI status for a PR.
func ParseCIChecks ¶
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
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.