Documentation
¶
Overview ¶
Package github provides a client for interacting with the GitHub API.
Package github provides a client for interacting with the GitHub API.
Package github provides a client for interacting with the GitHub API.
Package github provides a client for interacting with the GitHub API.
Package github provides a client for interacting with the GitHub API.
Index ¶
- Constants
- Variables
- func BatchGetPRChecksStatusGraphQL(ctx context.Context, runner git.Runner, owner, repo string, ...) (map[string]*CheckStatus, error)
- func BatchGetPRMergeableStates(ctx context.Context, runner git.Runner, prNodeIDs []string) (map[string]*PRMergeableState, error)
- func BatchGetPRTitlesGraphQL(ctx context.Context, runner git.Runner, owner, repo string, prNumbers []int) (map[int]string, error)
- func CreatePullRequest(ctx context.Context, client *github.Client, owner, repo string, ...) (*github.PullRequest, error)
- func DisableAutoMerge(ctx context.Context, runner git.Runner, prNodeID string) error
- func EnableAutoMerge(ctx context.Context, runner git.Runner, prNodeID string, ...) error
- func GetGitHubClient(ctx context.Context, runner git.Runner) (*github.Client, string, string, error)
- func GetPullRequestByBranch(ctx context.Context, client *github.Client, owner, repo, branchName string) (*github.PullRequest, error)
- func MergePullRequest(ctx context.Context, client *github.Client, owner, repo, branchName string, ...) error
- func ParseReviewers(reviewersStr string) ([]string, []string)
- func SyncPrInfo(ctx context.Context, runner git.Runner, branchNames []string, ...) error
- func UpdatePullRequest(ctx context.Context, client *github.Client, runner git.Runner, ...) ([]string, error)
- func WaitForPRMerge(ctx context.Context, runner git.Runner, prNodeID string, timeout time.Duration, ...) error
- type AutoMergeStatus
- type CheckDetail
- type CheckStatus
- type Client
- type CreatePROptions
- type EnableAutoMergeOptions
- type MergeMethod
- type MergeMethodSettings
- type MergePROptions
- type PRComment
- type PRMergeableState
- type PullRequestInfo
- type RepoInfo
- type StackitGitHubClient
- func (c *StackitGitHubClient) BatchGetPRChecksStatus(ctx context.Context, branchNames []string) (map[string]*CheckStatus, error)
- func (c *StackitGitHubClient) BatchGetPRTitles(ctx context.Context, owner, repo string, prNumbers []int) (map[int]string, error)
- func (c *StackitGitHubClient) ClosePullRequest(ctx context.Context, owner, repo string, prNumber int) error
- func (c *StackitGitHubClient) CreatePRComment(ctx context.Context, owner, repo string, prNumber int, body string) (int64, error)
- func (c *StackitGitHubClient) CreatePullRequest(ctx context.Context, owner, repo string, opts CreatePROptions) (*PullRequestInfo, error)
- func (c *StackitGitHubClient) DeletePRComment(ctx context.Context, owner, repo string, commentID int64) error
- func (c *StackitGitHubClient) GetAllowedMergeMethods(ctx context.Context) (*MergeMethodSettings, error)
- func (c *StackitGitHubClient) GetCurrentUser(ctx context.Context) (string, error)
- func (c *StackitGitHubClient) GetOwnerRepo() (string, string)
- func (c *StackitGitHubClient) GetPRChecksStatus(ctx context.Context, branchName string) (*CheckStatus, error)
- func (c *StackitGitHubClient) GetPullRequest(ctx context.Context, owner, repo string, prNumber int) (*PullRequestInfo, error)
- func (c *StackitGitHubClient) GetPullRequestByBranch(ctx context.Context, owner, repo, branchName string) (*PullRequestInfo, error)
- func (c *StackitGitHubClient) ListPRComments(ctx context.Context, owner, repo string, prNumber int) ([]PRComment, error)
- func (c *StackitGitHubClient) MergePullRequest(ctx context.Context, branchName string, opts MergePROptions) error
- func (c *StackitGitHubClient) UpdatePRComment(ctx context.Context, owner, repo string, commentID int64, body string) error
- func (c *StackitGitHubClient) UpdatePullRequest(ctx context.Context, owner, repo string, prNumber int, opts UpdatePROptions) ([]string, error)
- type UpdatePROptions
Constants ¶
const ( PRStateMerged = "MERGED" PRStateClosed = "CLOSED" )
PR state constants as returned by GitHub's GraphQL API.
const ( ReviewDecisionApproved = "APPROVED" ReviewDecisionChangesRequested = "CHANGES_REQUESTED" ReviewDecisionReviewRequired = "REVIEW_REQUIRED" )
Review decision constants
const ( // MaxGitHubConcurrency limits the number of concurrent requests to GitHub // to avoid triggering secondary rate limits. MaxGitHubConcurrency = 10 )
Variables ¶
var ( // ErrAutoMergeNotEnabled is returned when auto-merge is not enabled for the repository. ErrAutoMergeNotEnabled = errors.New("auto-merge is not enabled for this repository") // ErrPRCleanStatus is returned when a PR is already in a clean/mergeable status. ErrPRCleanStatus = errors.New("PR is already in clean status") // ErrPRAlreadyMerged is returned when a PR was merged while waiting. ErrPRAlreadyMerged = errors.New("PR was merged while waiting") )
Functions ¶
func BatchGetPRChecksStatusGraphQL ¶
func BatchGetPRChecksStatusGraphQL(ctx context.Context, runner git.Runner, owner, repo string, branchNames []string) (map[string]*CheckStatus, error)
BatchGetPRChecksStatusGraphQL returns the check status for multiple branches using a single GraphQL query. This function fetches both CI check status and PR review decisions in a single request for efficiency.
func BatchGetPRMergeableStates ¶
func BatchGetPRMergeableStates(ctx context.Context, runner git.Runner, prNodeIDs []string) (map[string]*PRMergeableState, error)
BatchGetPRMergeableStates checks mergeable state for multiple PRs in a single GraphQL query. Returns a map from node ID to PRMergeableState. If a PR fails to fetch, it won't be in the map.
func BatchGetPRTitlesGraphQL ¶
func BatchGetPRTitlesGraphQL(ctx context.Context, runner git.Runner, owner, repo string, prNumbers []int) (map[int]string, error)
BatchGetPRTitlesGraphQL fetches PR titles for multiple PR numbers using a single GraphQL query.
func CreatePullRequest ¶
func CreatePullRequest(ctx context.Context, client *github.Client, owner, repo string, opts CreatePROptions) (*github.PullRequest, error)
CreatePullRequest creates a new pull request
func DisableAutoMerge ¶
DisableAutoMerge disables GitHub's auto-merge feature on a PR.
func EnableAutoMerge ¶
func EnableAutoMerge(ctx context.Context, runner git.Runner, prNodeID string, opts EnableAutoMergeOptions) error
EnableAutoMerge enables GitHub's auto-merge feature on a PR. This requires the repository to have auto-merge enabled in settings.
func GetGitHubClient ¶
func GetGitHubClient(ctx context.Context, runner git.Runner) (*github.Client, string, string, error)
GetGitHubClient creates a GitHub client with authentication
func GetPullRequestByBranch ¶
func GetPullRequestByBranch(ctx context.Context, client *github.Client, owner, repo, branchName string) (*github.PullRequest, error)
GetPullRequestByBranch gets a pull request for a branch
func MergePullRequest ¶
func MergePullRequest(ctx context.Context, client *github.Client, owner, repo, branchName string, opts MergePROptions) error
MergePullRequest merges a pull request using the GitHub API. If opts.CommitBody is set, it is used as an additional commit message body for merge/squash strategies.
func ParseReviewers ¶
ParseReviewers parses a comma-separated string of reviewers Returns individual reviewers and team reviewers Team reviewers can be specified as "org/team" or just "team"
func SyncPrInfo ¶
func SyncPrInfo(ctx context.Context, runner git.Runner, branchNames []string, repoOwner, repoName string, onUpdate func(string, *PullRequestInfo)) error
SyncPrInfo syncs PR information for branches from GitHub
func UpdatePullRequest ¶
func UpdatePullRequest(ctx context.Context, client *github.Client, runner git.Runner, owner, repo string, prNumber int, opts UpdatePROptions) ([]string, error)
UpdatePullRequest updates an existing pull request Returns warnings (non-fatal issues like failed label/assignee additions) and error
Types ¶
type AutoMergeStatus ¶
AutoMergeStatus represents the state of GitHub's auto-merge feature on a PR
func GetAutoMergeStatus ¶
func GetAutoMergeStatus(ctx context.Context, runner git.Runner, prNodeID string) (*AutoMergeStatus, error)
GetAutoMergeStatus checks if auto-merge is enabled on a PR and returns its status.
type CheckDetail ¶
type CheckDetail struct {
Name string
Status string // QUEUED, IN_PROGRESS, COMPLETED
Conclusion string // SUCCESS, FAILURE, NEUTRAL, etc.
StartedAt time.Time
FinishedAt time.Time
}
CheckDetail represents the status of an individual CI check
type CheckStatus ¶
type CheckStatus struct {
Passing bool
Pending bool
Checks []CheckDetail
ReviewDecision string // "APPROVED", "CHANGES_REQUESTED", "REVIEW_REQUIRED", ""
Author string // GitHub username of PR author
State string // "OPEN", "CLOSED", "MERGED", or "" if unknown
}
CheckStatus represents the combined status of all CI checks for a PR
func (*CheckStatus) HasFailingChecks ¶
func (s *CheckStatus) HasFailingChecks() bool
HasFailingChecks returns true if any CI checks are failing
func (*CheckStatus) HasPendingChecks ¶
func (s *CheckStatus) HasPendingChecks() bool
HasPendingChecks returns true if any CI checks are pending
func (*CheckStatus) IsApproved ¶
func (s *CheckStatus) IsApproved() bool
IsApproved returns true if the review decision indicates approval
func (*CheckStatus) IsReady ¶
func (s *CheckStatus) IsReady() bool
IsReady returns true if all checks pass and the PR is approved
type Client ¶
type Client interface {
// CreatePullRequest creates a new pull request
CreatePullRequest(ctx context.Context, owner, repo string, opts CreatePROptions) (*PullRequestInfo, error)
// UpdatePullRequest updates an existing pull request
// Returns warnings (non-fatal issues like failed label/assignee additions) and error
UpdatePullRequest(ctx context.Context, owner, repo string, prNumber int, opts UpdatePROptions) (warnings []string, err error)
// GetPullRequestByBranch gets a pull request for a branch
GetPullRequestByBranch(ctx context.Context, owner, repo, branchName string) (*PullRequestInfo, error)
// GetPullRequest gets a pull request by number
GetPullRequest(ctx context.Context, owner, repo string, prNumber int) (*PullRequestInfo, error)
// MergePullRequest merges a pull request using the specified merge method
MergePullRequest(ctx context.Context, branchName string, opts MergePROptions) error
// GetAllowedMergeMethods returns the allowed merge methods for the repository
GetAllowedMergeMethods(ctx context.Context) (*MergeMethodSettings, error)
// GetPRChecksStatus returns the check status for a single branch
GetPRChecksStatus(ctx context.Context, branchName string) (*CheckStatus, error)
// BatchGetPRChecksStatus returns the check status for multiple branches
BatchGetPRChecksStatus(ctx context.Context, branchNames []string) (map[string]*CheckStatus, error)
// BatchGetPRTitles returns titles for multiple PRs by number
BatchGetPRTitles(ctx context.Context, owner, repo string, prNumbers []int) (map[int]string, error)
// GetOwnerRepo returns the repository owner and name
GetOwnerRepo() (owner, repo string)
// ClosePullRequest closes a pull request
ClosePullRequest(ctx context.Context, owner, repo string, prNumber int) error
// Comment methods for navigation location support
// CreatePRComment creates a new comment on a pull request
CreatePRComment(ctx context.Context, owner, repo string, prNumber int, body string) (int64, error)
// UpdatePRComment updates an existing pull request comment
UpdatePRComment(ctx context.Context, owner, repo string, commentID int64, body string) error
// DeletePRComment deletes a pull request comment
DeletePRComment(ctx context.Context, owner, repo string, commentID int64) error
// ListPRComments lists all comments on a pull request
ListPRComments(ctx context.Context, owner, repo string, prNumber int) ([]PRComment, error)
// GetCurrentUser returns the authenticated GitHub username
GetCurrentUser(ctx context.Context) (string, error)
}
Client is an interface for GitHub API interactions
type CreatePROptions ¶
type CreatePROptions struct {
Title string
Body string
Head string
Base string
Draft bool
Reviewers []string
TeamReviewers []string
Labels []string
Assignees []string
}
CreatePROptions contains options for creating a pull request
type EnableAutoMergeOptions ¶
type EnableAutoMergeOptions struct {
MergeMethod MergeMethod
CommitBody string // optional — omit for default GitHub behavior
}
EnableAutoMergeOptions contains options for enabling auto-merge on a PR.
type MergeMethod ¶
type MergeMethod string
MergeMethod represents a GitHub PR merge method
const ( // MergeMethodMerge creates a merge commit MergeMethodMerge MergeMethod = "merge" // MergeMethodSquash squashes commits before merging MergeMethodSquash MergeMethod = "squash" // MergeMethodRebase rebases commits onto base branch MergeMethodRebase MergeMethod = "rebase" )
type MergeMethodSettings ¶
type MergeMethodSettings struct {
AllowMergeCommit bool
AllowSquashMerge bool
AllowRebaseMerge bool
}
MergeMethodSettings contains the allowed merge methods for a repository
type MergePROptions ¶
type MergePROptions struct {
Method MergeMethod
CommitBody string // Optional commit body for merge/squash commit message.
}
MergePROptions configures how a pull request should be merged.
type PRMergeableState ¶
type PRMergeableState struct {
Mergeable bool // True if PR can be merged without conflicts
MergeStateText string // MERGEABLE, CONFLICTING, UNKNOWN
State string // OPEN, CLOSED, MERGED
}
PRMergeableState represents the mergeable state of a PR
func GetPRMergeableState ¶
func GetPRMergeableState(ctx context.Context, runner git.Runner, prNodeID string) (*PRMergeableState, error)
GetPRMergeableState checks if a PR has merge conflicts.
func WaitForMergeable ¶
func WaitForMergeable(ctx context.Context, runner git.Runner, prNodeID string, timeout time.Duration, pollInterval time.Duration) (*PRMergeableState, error)
WaitForMergeable polls until a PR's mergeStateStatus becomes CLEAN or HAS_HOOKS (ready to merge). Returns the final PRMergeableState when ready. Returns ErrPRAlreadyMerged if the PR is merged during polling. Returns an error if the PR is CLOSED, DIRTY (conflicts), times out, or the context is canceled.
type PullRequestInfo ¶
type PullRequestInfo struct {
Number int
NodeID string
HTMLURL string
Title string
Body string
State string
Draft bool
Base string
Head string
// Warnings contains non-fatal issues that occurred during PR creation/update
// (e.g., failed to add labels or assignees)
Warnings []string
}
PullRequestInfo contains information about a pull request This is a simplified struct to avoid coupling to go-github library
func ToPullRequestInfo ¶
func ToPullRequestInfo(pr *github.PullRequest) *PullRequestInfo
ToPullRequestInfo converts a github.PullRequest to PullRequestInfo
type RepoInfo ¶
RepoInfo contains parsed information from a git remote URL
func ParseGitHubRemoteURL ¶
ParseGitHubRemoteURL parses a git remote URL and extracts hostname, owner, and repo Supports both github.com and GitHub Enterprise URLs Examples:
- https://github.com/owner/repo.git
- git@github.com:owner/repo.git
- https://github.company.com/owner/repo.git
- git@github.company.com:owner/repo.git
type StackitGitHubClient ¶
type StackitGitHubClient struct {
// contains filtered or unexported fields
}
StackitGitHubClient implements Client using the real GitHub API
func NewGitHubClient ¶
NewGitHubClient creates a new RealGitHubClient
func (*StackitGitHubClient) BatchGetPRChecksStatus ¶
func (c *StackitGitHubClient) BatchGetPRChecksStatus(ctx context.Context, branchNames []string) (map[string]*CheckStatus, error)
BatchGetPRChecksStatus returns the check status for multiple branches
func (*StackitGitHubClient) BatchGetPRTitles ¶
func (c *StackitGitHubClient) BatchGetPRTitles(ctx context.Context, owner, repo string, prNumbers []int) (map[int]string, error)
BatchGetPRTitles returns titles for multiple PRs by number
func (*StackitGitHubClient) ClosePullRequest ¶
func (c *StackitGitHubClient) ClosePullRequest(ctx context.Context, owner, repo string, prNumber int) error
ClosePullRequest closes a pull request
func (*StackitGitHubClient) CreatePRComment ¶
func (c *StackitGitHubClient) CreatePRComment(ctx context.Context, owner, repo string, prNumber int, body string) (int64, error)
CreatePRComment creates a new comment on a pull request
func (*StackitGitHubClient) CreatePullRequest ¶
func (c *StackitGitHubClient) CreatePullRequest(ctx context.Context, owner, repo string, opts CreatePROptions) (*PullRequestInfo, error)
CreatePullRequest creates a new pull request
func (*StackitGitHubClient) DeletePRComment ¶
func (c *StackitGitHubClient) DeletePRComment(ctx context.Context, owner, repo string, commentID int64) error
DeletePRComment deletes a pull request comment
func (*StackitGitHubClient) GetAllowedMergeMethods ¶
func (c *StackitGitHubClient) GetAllowedMergeMethods(ctx context.Context) (*MergeMethodSettings, error)
GetAllowedMergeMethods returns the allowed merge methods for the repository
func (*StackitGitHubClient) GetCurrentUser ¶
func (c *StackitGitHubClient) GetCurrentUser(ctx context.Context) (string, error)
GetCurrentUser returns the authenticated GitHub username
func (*StackitGitHubClient) GetOwnerRepo ¶
func (c *StackitGitHubClient) GetOwnerRepo() (string, string)
GetOwnerRepo returns the repository owner and name
func (*StackitGitHubClient) GetPRChecksStatus ¶
func (c *StackitGitHubClient) GetPRChecksStatus(ctx context.Context, branchName string) (*CheckStatus, error)
GetPRChecksStatus returns the check status for a single branch
func (*StackitGitHubClient) GetPullRequest ¶
func (c *StackitGitHubClient) GetPullRequest(ctx context.Context, owner, repo string, prNumber int) (*PullRequestInfo, error)
GetPullRequest gets a pull request by number
func (*StackitGitHubClient) GetPullRequestByBranch ¶
func (c *StackitGitHubClient) GetPullRequestByBranch(ctx context.Context, owner, repo, branchName string) (*PullRequestInfo, error)
GetPullRequestByBranch gets a pull request for a branch
func (*StackitGitHubClient) ListPRComments ¶
func (c *StackitGitHubClient) ListPRComments(ctx context.Context, owner, repo string, prNumber int) ([]PRComment, error)
ListPRComments lists all comments on a pull request with pagination
func (*StackitGitHubClient) MergePullRequest ¶
func (c *StackitGitHubClient) MergePullRequest(ctx context.Context, branchName string, opts MergePROptions) error
MergePullRequest merges a pull request using the specified merge method
func (*StackitGitHubClient) UpdatePRComment ¶
func (c *StackitGitHubClient) UpdatePRComment(ctx context.Context, owner, repo string, commentID int64, body string) error
UpdatePRComment updates an existing pull request comment
func (*StackitGitHubClient) UpdatePullRequest ¶
func (c *StackitGitHubClient) UpdatePullRequest(ctx context.Context, owner, repo string, prNumber int, opts UpdatePROptions) ([]string, error)
UpdatePullRequest updates an existing pull request