Documentation
¶
Overview ¶
Package githubclt provides a github API client.
Index ¶
- Constants
- Variables
- func NewErrMergeConflict(cause error) error
- type CIJobStatus
- type CIStatus
- type Client
- func (clt *Client) AddLabel(ctx context.Context, owner, repo string, pullRequestOrIssueNumber int, ...) error
- func (clt *Client) BranchIsBehindBase(ctx context.Context, owner, repo, base, head string) (behind bool, err error)
- func (clt *Client) CreateCommitStatus(ctx context.Context, owner, repo, commit string, state StatusState, ...) error
- func (clt *Client) CreateHeadCommitStatus(ctx context.Context, owner, repo string, pullRequestNumber int, ...) error
- func (clt *Client) CreateIssueComment(ctx context.Context, owner, repo string, issueOrPRNr int, comment string) error
- func (clt *Client) ListPRs(ctx context.Context, owner, repo string) iter.Seq2[*PR, error]
- func (clt *Client) PRIsUptodate(ctx context.Context, owner, repo string, pullRequestNumber int) (isUptodate bool, headSHA string, err error)
- func (clt *Client) ReadyForMerge(ctx context.Context, owner, repo string, prNumber int) (*ReadyForMergeStatus, error)
- func (clt *Client) RemoveLabel(ctx context.Context, owner, repo string, pullRequestOrIssueNumber int, ...) error
- func (clt *Client) UpdateBranch(ctx context.Context, owner, repo string, pullRequestNumber int) (*UpdateBranchResult, error)
- type ErrMergeConflict
- type PR
- type PageInfo
- type ReadyForMergeStatus
- type ReviewDecision
- type Status
- type StatusState
- type UpdateBranchResult
Constants ¶
const ( ReviewDecisionApproved = ReviewDecision(githubv4.PullRequestReviewDecisionApproved) ReviewDecisionChangesRequested = ReviewDecision(githubv4.PullRequestReviewDecisionChangesRequested) ReviewDecisionReviewRequired = ReviewDecision(githubv4.PullRequestReviewDecisionReviewRequired) )
const DefaultHTTPClientTimeout = time.Minute
Variables ¶
var ErrPullRequestIsClosed = errors.New("pull request is closed")
Functions ¶
func NewErrMergeConflict ¶ added in v0.8.1
Types ¶
type CIJobStatus ¶
CIJobStatus is the status of a CI job. It represents the status of GitHub CheckRuns and Commit statuses.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an github API client. All methods return a goorderr.RetryableError when an operation can be retried. This can be e.g. the case when the API ratelimit is exceeded.
func (*Client) AddLabel ¶
func (clt *Client) AddLabel(ctx context.Context, owner, repo string, pullRequestOrIssueNumber int, label string) error
AddLabel adds a label to Pull-Request or Issue.
func (*Client) BranchIsBehindBase ¶
func (clt *Client) BranchIsBehindBase(ctx context.Context, owner, repo, base, head string) (behind bool, err error)
BranchIsBehindBase returns true if the head reference contains all changes of base.
func (*Client) CreateCommitStatus ¶ added in v0.8.0
func (clt *Client) CreateCommitStatus(ctx context.Context, owner, repo, commit string, state StatusState, description, context string) error
CreateCommitStatus submits a status for a commit. state must be one of StatusStatePending, StatusStateSuccess, StatusStateError, StatusStateFailure.
func (*Client) CreateHeadCommitStatus ¶ added in v0.8.0
func (clt *Client) CreateHeadCommitStatus(ctx context.Context, owner, repo string, pullRequestNumber int, state StatusState, description, context string) error
CreateCommitStatus submits a status for the HEAD commit of a pull request branch. state must be one of StatusStatePending, StatusStateSuccess, StatusStateError, StatusStateFailure.
func (*Client) CreateIssueComment ¶
func (clt *Client) CreateIssueComment(ctx context.Context, owner, repo string, issueOrPRNr int, comment string) error
CreateIssueComment creates a comment in a issue or pull request
func (*Client) ListPRs ¶ added in v0.8.0
ListPRs returns an iterator over all open non-draft pull requests of the repository. If an error happens when querying the GitHub GraphQL API, it is passed as second argument to the iterator.
func (*Client) PRIsUptodate ¶
func (clt *Client) PRIsUptodate(ctx context.Context, owner, repo string, pullRequestNumber int) (isUptodate bool, headSHA string, err error)
PullRequestIsUptodateWithBase returns true if the pull request is open and contains all changes from it's base branch. Additionally it returns the SHA of the head commit for which the status was checked. If the PR is closed PullRequestIsClosedError is returned.
func (*Client) ReadyForMerge ¶
func (clt *Client) ReadyForMerge(ctx context.Context, owner, repo string, prNumber int) (*ReadyForMergeStatus, error)
ReadyForMerge returns the review decision and status check rollup for a PR.
The status of checks that are not required is ignored. If a required check failed the returned [ReadyForMerge.CIStatus] is CIStatusFailure. If a check or status has not started yet but is required, it is CIStatusExpected. If a check or status is running and all others succeeded or also still it is CIStatusPending. It is CIStatusSuccess, if no check or status is in pending state and all required ones succeeded.
func (*Client) RemoveLabel ¶
func (clt *Client) RemoveLabel(ctx context.Context, owner, repo string, pullRequestOrIssueNumber int, label string) error
RemoveLabel removes a label from a Pull-Request or issue. If the issue or PR does not have the label, the operation succeeds.
func (*Client) UpdateBranch ¶
func (clt *Client) UpdateBranch(ctx context.Context, owner, repo string, pullRequestNumber int) (*UpdateBranchResult, error)
UpdateBranch schedules merging the base-branch into a pull request branch. If the PR contains all changes of it's base branch, false is returned for changed If it's not up-to-date and updating the PR was scheduled at github, true is returned for changed and scheduled. If the PR was updated while the method was executed, a goorderr.RetryableError is returned and the operation can be retried. If the branch can not be updated automatically because of a merge conflict, an ErrMergeConflict is returned
type ErrMergeConflict ¶ added in v0.8.1
type ErrMergeConflict struct {
Err error
}
func (*ErrMergeConflict) Error ¶ added in v0.8.1
func (e *ErrMergeConflict) Error() string
func (*ErrMergeConflict) Unwrap ¶ added in v0.8.1
func (e *ErrMergeConflict) Unwrap() error
type ReadyForMergeStatus ¶
type ReadyForMergeStatus struct {
ReviewDecision ReviewDecision
CIStatus CIStatus
Statuses []*CIJobStatus
Commit string
}
ReadyForMergeStatus represent the information deciding if a pull request is ready to be merged. It contains the review decision and CI job results.
type ReviewDecision ¶
type ReviewDecision string
ReviewDecision is the result of a pull request review.
type Status ¶ added in v0.8.0
type Status struct {
Context string
State StatusState
}
type StatusState ¶ added in v0.8.0
type StatusState string
const ( StatusStatePending StatusState = "pending" StatusStateSuccess StatusState = "success" StatusStateError StatusState = "error" StatusStateFailure StatusState = "failure" )