Documentation
¶
Overview ¶
Package patch2pr converts Git patches in to GitHub pull requests.
Index ¶
- Variables
- func IsUnsupported(err error) bool
- type Applier
- func (a *Applier) Apply(ctx context.Context, f *gitdiff.File) (*github.TreeEntry, error)
- func (a *Applier) Commit(ctx context.Context, tmpl *github.Commit, header *gitdiff.PatchHeader) (*github.Commit, error)
- func (a *Applier) CreateTree(ctx context.Context) (*github.Tree, error)
- func (a *Applier) Entries() []*github.TreeEntry
- func (a *Applier) Reset(c *github.Commit)
- type GraphQLApplier
- type Reference
- type Repository
Constants ¶
This section is empty.
Variables ¶
var DefaultCommitMessage = "Apply patch with patch2pr"
DefaultCommitMessage is the commit message used when no message is provided in a patch header.
Functions ¶
func IsUnsupported ¶ added in v0.7.0
IsUnsupported returns true if err is the result of trying an unsupported operation. It is equivalent to finding the first error in err's chain that implements
type unsupported interface { Unsupported() bool }
and then calling the Unsupported() method.
Types ¶
type Applier ¶
type Applier struct {
// contains filtered or unexported fields
}
Applier applies patches to create trees and commits in a repository.
func NewApplier ¶
NewApplier creates a new Applier for a repository. The Applier applies changes on top of commit c.
func (*Applier) Apply ¶
Apply applies the changes in a file, adds the result to the list of pending tree entries, and returns the entry. If the application succeeds, Apply creates a blob in the repository with the modified content.
func (*Applier) Commit ¶
func (a *Applier) Commit(ctx context.Context, tmpl *github.Commit, header *gitdiff.PatchHeader) (*github.Commit, error)
Commit commits the latest tree, optionally using the details in tmpl and header. If there are pending tree entries, it calls CreateTree before creating the commit. It returns an error if there are no pending trees or tree entries.
If tmpl is not nil, Commit uses it as a template for the new commit, overwriting fields as needed. If header is not nil, Commit uses it to set the message, author, and committer for the new commit. Values in header overwrite those in tmpl.
If both tmpl and header are nil or missing fields, Commit uses a default message, the current time, and the authenticated user as needed for the commit details.
func (*Applier) CreateTree ¶
CreateTree creates a tree from the pending tree entries and clears the entry list. The new tree serves as the base tree for future Apply calls. CreateTree returns an error if there are no pending tree entires.
type GraphQLApplier ¶ added in v0.7.0
type GraphQLApplier struct {
// contains filtered or unexported fields
}
GraphQLApplier applies patches to create commits in a repository. Compared to the normal Applier, the GraphqQLApplier:
- Generally makes fewer API requests
- Does not support setting a commit author or committer
- Does not create intermediate blobs and trees
- Uses more memory while applying patches with multiple files
- Updates a branch (which must exist) to reference the new commit
- Creates signed commits
Due to limitations in the GraphQL API, not all patches are supported; see Apply. Use the regular Applier if you need to apply arbitrary patches or if you are targeting a GitHub Enterprise instance that does not support the createCommitOnBranch GraphQL mutation.
func NewGraphQLApplier ¶ added in v0.7.0
func NewGraphQLApplier(client *githubv4.Client, repo Repository, base string) *GraphQLApplier
NewGraphQLApplier creates an applier for a repository. The applier applies changes on top of base, the full OID (SHA) of a commit.
func (*GraphQLApplier) Apply ¶ added in v0.7.0
Apply applies the changes in a file, adding the result to the list of pending file changes. It does not modify the repository.
Due to GraphQL limitations, some patches are not supported:
- Adding or renaming files that use a non-standard mode
- Changing the mode of an existing file
- Modifying or deleting binary files (without a V3 client)
- Modifying or deleting large files (without a V3 client)
When given an unsupported patch, Apply returns an error such that IsUnsupported(err) is true. Setting a V3 client with SetV3Client allows Apply to process some patches that are otherwise unsupported.
func (*GraphQLApplier) Commit ¶ added in v0.7.0
func (a *GraphQLApplier) Commit(ctx context.Context, ref string, header *gitdiff.PatchHeader) (string, error)
Commit creates a commit with all pending file changes. It updates the branch ref to point at the new commit and returns the OID (SHA) of the commit. The branch must already exist and reference at the current base commit of the GraphQLApplier.
If header is not nil, Apply uses it to set the commit message. It ignores other fields set in header. In particular, the commit timestamp, author, and committer are always set by GitHub.
func (*GraphQLApplier) Reset ¶ added in v0.7.0
func (a *GraphQLApplier) Reset(base string)
Reset resets the applier so that future Apply calls start from commit base. It removes all pending file changes. Reset does not modify the repository.
func (*GraphQLApplier) SetV3Client ¶ added in v0.7.0
func (a *GraphQLApplier) SetV3Client(client *github.Client)
SetV3Client sets a REST API client used to implement functionality missing in the GraphQL API. Without a V3 client, the applier will fail on patches that modify binary and very large files.
type Reference ¶
type Reference struct {
// contains filtered or unexported fields
}
Reference is a named reference in a repository.
func NewReference ¶
func NewReference(client *github.Client, repo Repository, ref string) *Reference
NewReference creates a new Reference for ref in repo.
func (*Reference) PullRequest ¶
func (r *Reference) PullRequest(ctx context.Context, spec *github.NewPullRequest) (*github.PullRequest, error)
PullRequest create a new pull request for the reference. The reference must be a branch (start with "refs/heads/".) The pull request takes values from spec, except for Head, which is set to the reference.
type Repository ¶
Repository identifies a GitHub repository.
func ParseRepository ¶
func ParseRepository(s string) (Repository, error)
ParseRepository parses a Repository from a string in "owner/name" format.
func (Repository) String ¶
func (r Repository) String() string