Documentation
¶
Overview ¶
Package github implements forge.Forge against the GitHub REST API. It is reached only through the forge.Forge interface; no view imports it.
Index ¶
- Variables
- type Client
- func (c *Client) Approvals(ctx context.Context, ref forge.Ref, mr int) (forge.Approvals, error)
- func (c *Client) Approve(ctx context.Context, ref forge.Ref, mr int) error
- func (c *Client) Capabilities() forge.Caps
- func (c *Client) Comment(ctx context.Context, ref forge.Ref, target, body string) error
- func (c *Client) CreateDiffThread(ctx context.Context, ref forge.Ref, mr int, dc forge.DiffComment) error
- func (c *Client) CreateThread(ctx context.Context, ref forge.Ref, target, body string) error
- func (c *Client) Epics(ctx context.Context, s forge.Scope) ([]forge.Epic, error)
- func (c *Client) EpicsStrict(ctx context.Context, s forge.Scope) ([]forge.Epic, error)
- func (c *Client) FileContent(ctx context.Context, ref forge.Ref, path, rev string) ([]byte, error)
- func (c *Client) GroupIssues(ctx context.Context, group string, f forge.IssueFilter) ([]forge.Issue, error)
- func (c *Client) Issue(ctx context.Context, ref forge.Ref, id int) (forge.Issue, error)
- func (c *Client) Issues(ctx context.Context, ref forge.Ref, f forge.IssueFilter) ([]forge.Issue, error)
- func (c *Client) JobLog(ctx context.Context, ref forge.Ref, jobID int) (io.ReadCloser, error)
- func (c *Client) Jobs(ctx context.Context, ref forge.Ref, pipelineID int) ([]forge.Job, error)
- func (c *Client) Labels(ctx context.Context, s forge.Scope) ([]string, error)
- func (c *Client) Members(ctx context.Context, s forge.Scope) ([]forge.User, error)
- func (c *Client) Merge(ctx context.Context, ref forge.Ref, mr int) error
- func (c *Client) MergeRequest(ctx context.Context, ref forge.Ref, mr int) (forge.MergeRequest, error)
- func (c *Client) MergeRequestDiff(ctx context.Context, ref forge.Ref, mr int) (string, error)
- func (c *Client) MergeRequests(ctx context.Context, ref forge.Ref, f forge.MRFilter) ([]forge.MergeRequest, error)
- func (c *Client) Milestones(ctx context.Context, s forge.Scope) ([]forge.Milestone, error)
- func (c *Client) MyWork(ctx context.Context, f forge.MyWorkFilter) ([]forge.WorkItem, error)
- func (c *Client) Namespaces(ctx context.Context, parent string) ([]forge.Namespace, error)
- func (c *Client) Pipelines(ctx context.Context, ref forge.Ref, f forge.PipelineFilter) ([]forge.Pipeline, error)
- func (c *Client) Rebase(ctx context.Context, ref forge.Ref, mr int) error
- func (c *Client) Repos(ctx context.Context, namespace string) ([]forge.Repo, error)
- func (c *Client) ResolveTodo(ctx context.Context, t forge.Todo) error
- func (c *Client) RetryPipeline(ctx context.Context, ref forge.Ref, pipelineID int) error
- func (c *Client) SetFields(ctx context.Context, ref forge.Ref, target string, patch forge.FieldPatch) error
- func (c *Client) Starred(ctx context.Context) ([]forge.Repo, error)
- func (c *Client) Statuses(ctx context.Context, s forge.Scope) ([]forge.Status, error)
- func (c *Client) StatusesStrict(ctx context.Context, s forge.Scope) ([]forge.Status, error)
- func (c *Client) SubmitReview(ctx context.Context, ref forge.Ref, mr int, r forge.Review) (forge.ReviewResult, error)
- func (c *Client) Threads(ctx context.Context, ref forge.Ref, target string) ([]forge.Thread, error)
- func (c *Client) Todos(ctx context.Context, f forge.TodoFilter) ([]forge.Todo, error)
- func (c *Client) Tree(ctx context.Context, ref forge.Ref, path, rev string) ([]forge.TreeEntry, error)
- func (c *Client) Unapprove(ctx context.Context, ref forge.Ref, mr int) error
- func (c *Client) Whoami(ctx context.Context) (forge.User, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNoApprovalToRevoke = errors.New("you have not approved this pull request")
ErrNoApprovalToRevoke is returned when there is nothing to unapprove: this account has not approved, so there is no review to dismiss.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client adapts the GitHub SDK to forge.Forge.
func New ¶
func New(profile, host, token string, transport http.RoundTripper) (*Client, error)
New builds a Client for one profile/host pair using a token obtained from the gh CLI. A host other than github.com is treated as GitHub Enterprise.
func (*Client) Approvals ¶ added in v0.7.0
Approvals reports where a pull request stands.
GitHub has no approval count to report — that lives in branch protection, not on the pull request — so Required stays zero and the caller reads By instead. Each reviewer's latest review is the one that counts: a change request followed by an approval is an approval.
func (*Client) Approve ¶ added in v0.7.0
Approve records this account's approval.
GitHub has no bare approval: an approval is a review with no remarks, which is what this sends.
func (*Client) Capabilities ¶
Capabilities reports what GitHub accepts. A multi-line suggestion is expressed by the comment's own line range rather than in the fence.
func (*Client) Comment ¶
Comment posts a note. GitHub comments on issues and pull requests through the same endpoint, so the target's kind does not matter here.
func (*Client) CreateDiffThread ¶
func (c *Client) CreateDiffThread(ctx context.Context, ref forge.Ref, mr int, dc forge.DiffComment) error
CreateDiffThread opens a review comment anchored to a place in the diff.
GitHub positions against the commit the diff was read at, and rejects the comment outright if that commit is no longer the head — which is the right behaviour: a line number from a diff that has since been force-pushed points at something else now.
func (*Client) CreateThread ¶
CreateThread posts a comment.
GitHub's issue comments are flat, so a "thread" is a single comment; the review-comment endpoint needs a diff position gu does not carry.
func (*Client) EpicsStrict ¶ added in v0.6.0
func (*Client) FileContent ¶
FileContent returns a file's bytes at a revision.
func (*Client) GroupIssues ¶
func (c *Client) GroupIssues(ctx context.Context, group string, f forge.IssueFilter) ([]forge.Issue, error)
GroupIssues lists issues across an organisation's repositories.
GitHub's org issue endpoint only covers repositories the user is a member of, which is the closest equivalent to a GitLab group board.
func (*Client) Issues ¶
func (c *Client) Issues(ctx context.Context, ref forge.Ref, f forge.IssueFilter) ([]forge.Issue, error)
Issues lists a repository's issues.
GitHub's issue endpoint also returns pull requests; they are filtered out so an issue list means the same thing on both providers.
func (*Client) JobLog ¶
JobLog downloads a job's log.
GitHub answers with a redirect to storage rather than the log itself, so this follows that URL and streams the body.
func (*Client) Labels ¶ added in v0.6.0
Labels lists a repository's labels.
GitHub has no organisation-wide label — every label belongs to a repository — so a group scope has nothing to return.
func (*Client) Members ¶ added in v0.6.0
Members lists who could be assigned something: a repository's collaborators for a project scope, an organisation's members for a group one.
func (*Client) MergeRequest ¶
func (c *Client) MergeRequest(ctx context.Context, ref forge.Ref, mr int) (forge.MergeRequest, error)
MergeRequest fetches one pull request by its number.
func (*Client) MergeRequestDiff ¶
MergeRequestDiff returns the pull request as a unified diff.
GitHub serves one directly, so unlike GitLab there are no headers to reconstruct.
func (*Client) MergeRequests ¶
func (c *Client) MergeRequests(ctx context.Context, ref forge.Ref, f forge.MRFilter) ([]forge.MergeRequest, error)
MergeRequests lists a repository's pull requests.
func (*Client) Milestones ¶ added in v0.6.0
Milestones lists a repository's milestones.
Same as Labels: GitHub has no organisation-wide milestone.
func (*Client) MyWork ¶
MyWork lists the current user's issues and pull requests across every repository, using the search API — the only endpoint that spans repos.
func (*Client) Namespaces ¶
Namespaces lists the user's organisations.
GitHub has no nested groups, so only the root level has anything to show; asking for the children of an organisation yields none.
func (*Client) Pipelines ¶
func (c *Client) Pipelines(ctx context.Context, ref forge.Ref, f forge.PipelineFilter) ([]forge.Pipeline, error)
Pipelines lists a repository's Actions workflow runs.
func (*Client) Rebase ¶
Rebase brings a pull request up to date with its base branch through GitHub's update-branch endpoint. gu never runs git locally.
func (*Client) Repos ¶
Repos lists an organisation's repositories, falling back to the user's own when the name is not an organisation.
func (*Client) ResolveTodo ¶ added in v0.11.0
ResolveTodo marks the notification read, which is GitHub's "done".
func (*Client) RetryPipeline ¶
RetryPipeline re-runs a workflow run.
func (*Client) SetFields ¶
func (c *Client) SetFields(ctx context.Context, ref forge.Ref, target string, patch forge.FieldPatch) error
SetFields applies a partial update to an issue or pull request.
func (*Client) Statuses ¶ added in v0.6.0
Statuses and Epics are both GitLab-only: GitHub issues have no work-item status field and no epic concept, so there is nothing to list. The Strict twins answer the same way: there is genuinely nothing here, which is not a failure the status or epic picker needs to hear about.
func (*Client) StatusesStrict ¶ added in v0.6.0
func (*Client) SubmitReview ¶ added in v0.7.0
func (c *Client) SubmitReview(ctx context.Context, ref forge.Ref, mr int, r forge.Review) (forge.ReviewResult, error)
SubmitReview publishes a review as one unit.
A review is GitHub's own unit, so this is one request carrying the verdict, the summary and every inline remark — and therefore one notification for the author.
func (*Client) Threads ¶
Threads lists the comments on an issue or pull request, together with the events in its history.
GitHub serves issue and pull-request comments through one endpoint, and they are flat: each becomes a thread of one. The history comes from the timeline endpoint and arrives as system notes, so a detail page can draw one activity stream whichever provider it is talking to. Review conversations live on a third endpoint and are not folded in here.
func (*Client) Todos ¶ added in v0.11.0
Todos lists the authenticated user's unread notifications, which is the closest thing GitHub has to GitLab's todo list.
A token without the notifications scope is refused outright, and that is reported as ErrTodoScope rather than as an empty list: "nothing is waiting" and "I was not allowed to look" must not draw the same.
func (*Client) Tree ¶
func (c *Client) Tree(ctx context.Context, ref forge.Ref, path, rev string) ([]forge.TreeEntry, error)
Tree lists the entries directly under a path.
GetContents already returns one directory level, which is exactly what a file browser descends through — no need for the recursive tree API.
func (*Client) Unapprove ¶ added in v0.7.0
Unapprove dismisses this account's own approval.
GitHub's dismissal endpoint is written for taking someone else's review out of the reckoning and needs a reason, so revoking one's own approval is spelled the same way. It requires push access to the repository, which is the one case where GitLab's plain unapprove has no exact counterpart.