api

package
v0.0.0-...-df82998 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPullRequestNotReopenable = errors.New("the closed pull request of this change cannot be reopened")

ErrPullRequestNotReopenable reports that a closed pull request could not be brought back, so the change it belongs to needs a new one.

Reopening keeps a conversation; reopening onto a base branch that already contains the pull request's head loses the conversation *and* the pull request, because a provider reads that as merged and will not reopen it a second time. So a base that has to move and will not is answered with this rather than with a reopen.

Functions

func ReportAbandonedConversation

func ReportAbandonedConversation(pr *PullRequest)

ReportAbandonedConversation tells the user which review a change is leaving behind when its closed pull request could not be brought back.

On stderr rather than in a log, and here rather than in each provider: the default verbosity prints no logs at all, a review that quietly opens a second one is the complaint this whole behaviour answers, and five providers saying it five ways would drift. It names no noun, so it reads right on GitLab, where a review is a merge request.

Types

type BodyFormatter

type BodyFormatter interface {
	Section(title string, content []string) []string
	Link(url, text string) string
	LineBreak() string
}

BodyFormatter controls how PR body sections (committer details, related changes, topics) are rendered.

type GitHub

type GitHub struct {
	GraphQLClient *api.GraphQLClient
	*github.Client
	Host       string
	Owner      string
	Repository string
	// contains filtered or unexported fields
}

GitHub implements the PullRequester interface allowing to create pull requests for a given repository

func NewGitHubUpserter

func NewGitHubUpserter(ctx context.Context, endpoint *transport.Endpoint) (*GitHub, error)

NewGitHubUpserter instanciates an upserter that uses the github API to create and update pull requests

func (*GitHub) BodyFormatter

func (g *GitHub) BodyFormatter() BodyFormatter

func (*GitHub) DefaultBranch

func (g *GitHub) DefaultBranch(ctx context.Context) string

DefaultBranch returns the default branch of the remote repository

func (*GitHub) Ensure

func (g *GitHub) Ensure(ctx context.Context, options PullRequestOptions) (*PullRequest, bool, error)

Ensure ensures a PR is opened for the head branch

func (*GitHub) Find

func (g *GitHub) Find(ctx context.Context, head string) (*PullRequest, error)

Find looks up the open pull request for head. It owns the list-and-count switch so Ensure cannot drift from what a plain lookup reports.

func (*GitHub) LinkedTopicIssues

func (g *GitHub) LinkedTopicIssues(topicSearchString string) string

LinkedTopicIssues returns the search URL for linked issues

func (*GitHub) RepoHost

func (g *GitHub) RepoHost() string

RepoHost implements the ghrepo.Interface interface required to call the github graphql API from https://github.com/cli/cli See https://github.com/cli/cli/blob/dc804d928714120a3f4b53f78847aec7ba282c63/internal/ghrepo/repo.go#L14

func (*GitHub) RepoName

func (g *GitHub) RepoName() string

RepoName implements the ghrepo.Interface interface required to call the github graphql API from https://github.com/cli/cli See https://github.com/cli/cli/blob/dc804d928714120a3f4b53f78847aec7ba282c63/internal/ghrepo/repo.go#L14

func (*GitHub) RepoOwner

func (g *GitHub) RepoOwner() string

RepoHost implements the ghrepo.Interface interface required to call the github graphql API from https://github.com/cli/cli See https://github.com/cli/cli/blob/dc804d928714120a3f4b53f78847aec7ba282c63/internal/ghrepo/repo.go#L14

func (*GitHub) StackManager

func (g *GitHub) StackManager() StackManager

StackManager returns the GitHub native stack manager.

func (*GitHub) Update

func (g *GitHub) Update(ctx context.Context, pr *PullRequest, options PullRequestOptions) (*PullRequest, error)

Update implements the Update interface to update an existing pull request

type GitHubStackManager

type GitHubStackManager struct {
	// contains filtered or unexported fields
}

GitHubStackManager implements StackManager using the GitHub REST API.

func NewGitHubStackManager

func NewGitHubStackManager(client *github.Client, owner, repository string) *GitHubStackManager

NewGitHubStackManager creates a new GitHubStackManager.

func (*GitHubStackManager) Available

func (s *GitHubStackManager) Available(ctx context.Context) bool

func (*GitHubStackManager) CreateOrUpdateStack

func (s *GitHubStackManager) CreateOrUpdateStack(ctx context.Context, prNumbers []int) (*Stack, error)

func (*GitHubStackManager) GetStack

func (s *GitHubStackManager) GetStack(ctx context.Context, prNumber int) (*Stack, error)

func (*GitHubStackManager) Unstack

func (s *GitHubStackManager) Unstack(ctx context.Context, stackID string) error

Unstack dissolves the stack.

The documented call is a POST to the stack's unstack endpoint with no body; a DELETE on the stack itself is not part of the published API. See https://docs.github.com/en/rest/pulls/stacks.

type HTMLBodyFormatter

type HTMLBodyFormatter struct{}

HTMLBodyFormatter renders sections as collapsible <details> blocks.

func (HTMLBodyFormatter) LineBreak

func (HTMLBodyFormatter) LineBreak() string
func (HTMLBodyFormatter) Link(url, text string) string

func (HTMLBodyFormatter) Section

func (HTMLBodyFormatter) Section(title string, content []string) []string

type PullRequest

type PullRequest struct {
	ID  string
	URL string
	// State is what the provider reports the pull request as. An empty one is a
	// provider that does not say, which every caller treats as open, because that is
	// what the only lookup maiao had before this reported.
	State PullRequestState
	// Base is the branch the pull request currently targets on the provider. It
	// is what tells a review whose stack has been reordered which pull requests
	// have to be moved out of the way before the branches are pushed.
	Base string
}

PullRequest defines the object

type PullRequestOptions

type PullRequestOptions struct {
	Base             string
	Head             string
	Title            string
	Body             string
	WIP              bool
	Ready            bool
	ParentPullNumber string
}

PullRequestOptions are the options available to create or update a pull request

type PullRequestState

type PullRequestState string

PullRequestState is the state a provider reports a pull request in.

It exists because the three cases differ in what a review may do with the pull request it found, and a bare "is it open" cannot tell the last two apart.

const (
	// PullRequestOpen is a pull request a review can carry on using as it is.
	PullRequestOpen PullRequestState = "open"
	// PullRequestClosed is a pull request that is closed and can be reopened, so a
	// review reuses it rather than opening a second one for the same change.
	PullRequestClosed PullRequestState = "closed"
	// PullRequestMerged is a pull request the provider considers merged. GitHub
	// refuses to reopen one — `422: state cannot be changed. The pull request cannot
	// be reopened.` — whether or not anything was really merged, which is how a
	// reorder that outran the parking pass strands a conversation for good.
	PullRequestMerged PullRequestState = "merged"
)

type PullRequester

type PullRequester interface {
	// Update defines the interface to create or update a pull request to match options
	Update(context.Context, *PullRequest, PullRequestOptions) (*PullRequest, error)
	// Ensure ensures one and only one pull request exists for the given head
	Ensure(context.Context, PullRequestOptions) (*PullRequest, bool, error)
	// Find returns the pull request for the given head branch whatever state it is
	// in, or nil when there is none. Unlike Ensure it never creates one, so it can
	// be called before the head branch exists on the remote.
	//
	// It reports closed pull requests because a review that only looked at the open
	// ones opened a second pull request beside a closed one for the same change,
	// leaving its conversation behind. The caller decides what a given state is
	// good for: State says which.
	Find(ctx context.Context, head string) (*PullRequest, error)
	LinkedTopicIssues(topicSearchString string) string
	DefaultBranch(context.Context) string
	// StackManager returns the stack manager if native stacks are supported, or nil.
	StackManager() StackManager
	// BodyFormatter returns the formatter used to render PR body sections.
	BodyFormatter() BodyFormatter
}

PullRequester defines the interface to implement to handle pull requests

type Repo

type Repo struct {
	// Domain is the domain the API is exposed on
	Domain string
	// Repository is the name of the repository exposed on the API
	// (owner/repository for github repositories)
	Repository string
	// Username contains the name of the authenticated user
	// accessing the repository API
	Username string
	// Password contains the password of the authenticated user
	// accessing the repository API
	Password string
}

Repo describes how to reach a repository using an API

func NewRepoFromGitRemote

func NewRepoFromGitRemote(remoteName string) (*Repo, error)

NewRepoFromGitRemote parses the a git remote URL to determine the API configuration

type Stack

type Stack struct {
	ID  string
	PRs []int
}

Stack represents a GitHub native stack of pull requests.

type StackManager

type StackManager interface {
	// CreateOrUpdateStack registers a set of PRs as a GitHub native stack.
	// prNumbers must be ordered bottom-to-top (first targets the base branch).
	CreateOrUpdateStack(ctx context.Context, prNumbers []int) (*Stack, error)
	// GetStack retrieves the stack associated with a given PR number.
	GetStack(ctx context.Context, prNumber int) (*Stack, error)
	// Unstack dissolves a stack, leaving each pull request open on the base
	// branch it currently targets.
	//
	// It is all or nothing: GitHub offers no way to take one pull request out of
	// a stack, and none to reorder one, so a stack whose order has changed can
	// only be rebuilt by dissolving it and creating it again.
	// See https://docs.github.com/en/rest/pulls/stacks.
	//
	// Pull requests that cannot be unstacked, such as those queued for merge, are
	// left in the stack, and the call still succeeds.
	Unstack(ctx context.Context, stackID string) error
	// Available reports whether the GitHub Stack API is supported on this instance.
	Available(ctx context.Context) bool
}

StackManager defines the interface for GitHub native stack operations.

Jump to

Keyboard shortcuts

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