gitpr

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPRAlreadyExists = errors.New("PR already exists")

ErrPRAlreadyExists is returned when a PR already exists for the given branch.

Functions

func ApprovePR

func ApprovePR(nodeID string, auther githubutil.HTTPRequestAuther) error

ApprovePR adds an approving review on the target GraphQL PR node ID. The review author is the user associated with the PAT.

func EnablePRAutoMerge

func EnablePRAutoMerge(nodeID string, auther githubutil.HTTPRequestAuther) error

EnablePRAutoMerge enables PR automerge on the target GraphQL PR node ID.

func MutateGraphQL

func MutateGraphQL(auther githubutil.HTTPRequestAuther, query string, variables map[string]any) error

func QueryGraphQL

func QueryGraphQL(auther githubutil.HTTPRequestAuther, query string, variables map[string]any, result any) error

Types

type ExistingPR

type ExistingPR struct {
	Title  string
	ID     string
	Number int
}

func FindExistingPR

func FindExistingPR(r *GitHubRequest, head, target *Remote, headBranch, submitterUser string, auther githubutil.HTTPRequestAuther) (*ExistingPR, error)

FindExistingPR looks for a PR submitted to a target branch with a set of filters. Returns the result's graphql identity if one match is found, empty string if no matches are found, and an error if more than one match was found.

type GitHubRequest

type GitHubRequest struct {
	Head                string `json:"head"`
	Base                string `json:"base"`
	Title               string `json:"title"`
	Body                string `json:"body"`
	MaintainerCanModify bool   `json:"maintainer_can_modify"`
	Draft               bool   `json:"draft"`
}

GitHubRequest is the payload for a GitHub PR creation API call, marshallable as JSON.

type GitHubRequestError

type GitHubRequestError struct {
	Message string `json:"message"`
}

type GitHubResponse

type GitHubResponse struct {
	// GitHub success response:
	HTMLURL string `json:"html_url"`
	NodeID  string `json:"node_id"`
	Number  int    `json:"number"`
}

GitHubResponse is a successful PR creation response from GitHub.

func PostGitHub

func PostGitHub(ownerRepo string, request *GitHubRequest, auther githubutil.HTTPRequestAuther) (*GitHubResponse, error)

PostGitHub creates a PR on GitHub using pat for the given owner/repo and request details. If the PR already exists, returns a wrapped ErrPRAlreadyExists.

type MirrorRefSet

type MirrorRefSet struct {
	UpstreamPattern string
}

MirrorRefSet calculates the set of refs that correspond to a pure mirroring operation, where the set of mirrored branches is specified by a pattern.

func (MirrorRefSet) UpstreamMirrorFetchRefspec

func (b MirrorRefSet) UpstreamMirrorFetchRefspec() string

UpstreamMirrorFetchRefspec fetches the remote refs that match the pattern to local branches.

func (MirrorRefSet) UpstreamMirrorLocalBranchPattern

func (b MirrorRefSet) UpstreamMirrorLocalBranchPattern() string

UpstreamMirrorLocalBranchPattern is the name of the local ref (or pattern matching multiple local refs) after it has been fetched from the upstream.

func (MirrorRefSet) UpstreamMirrorRefspec

func (b MirrorRefSet) UpstreamMirrorRefspec() string

UpstreamMirrorRefspec pushes the local mirroring branches to back to branches with the same name as the branches they were fetched from.

type PRRefSet

type PRRefSet struct {
	// Name of the base branch to update. Do not include "refs/heads/".
	Name string
	// Purpose of the PR. This is used to generate the PR branch name, "dev/{Purpose}/{Name}".
	Purpose string
}

PRRefSet contains information about an automatic PR branch and calculates the set of refs that would correspond to that PR.

func (PRRefSet) BaseBranchFetchRefspec

func (b PRRefSet) BaseBranchFetchRefspec() string

BaseBranchFetchRefspec is the refspec with src: PR base branch src, dst: PR head branch dst. This can be used with "fetch" to create a fresh dev branch.

func (PRRefSet) CreateGitHubPR

func (b PRRefSet) CreateGitHubPR(headOwner, title, body string) *GitHubRequest

CreateGitHubPR creates the data model that can be sent to GitHub to create a PR for this branch.

func (PRRefSet) PRBranch

func (b PRRefSet) PRBranch() string

PRBranch is the name of the "head" branch name for this PR, under "dev/{Purpose}/{Name}" convention, without the "refs/heads/" prefix.

func (PRRefSet) PRBranchRefspec

func (b PRRefSet) PRBranchRefspec() string

PRBranchRefspec is the refspec that syncs the dev branch between two repos.

type Remote

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

Remote is a parsed version of a Git Remote. It helps determine how to send a GitHub PR.

func ParseRemoteURL

func ParseRemoteURL(url string) (*Remote, error)

ParseRemoteURL takes the URL ("https://github.com/microsoft/go", "git@github.com:microsoft/go") and grabs the owner ("microsoft") and repository name ("go"). This assumes the URL follows one of these two patterns, or something that's compatible. Returns an initialized 'Remote'.

func (Remote) GetOwner

func (r Remote) GetOwner() string

func (Remote) GetOwnerRepo

func (r Remote) GetOwnerRepo() []string

func (Remote) GetOwnerSlashRepo

func (r Remote) GetOwnerSlashRepo() string

func (Remote) GetRepo added in v0.0.6

func (r Remote) GetRepo() string

type SyncPRRefSet

type SyncPRRefSet struct {
	// UpstreamName is the name of the upstream branch being synced from.
	UpstreamName string
	// Commit is either the specific commit hash to sync to, or empty string to sync from the latest
	// commit in the branch. Commit is expected to already be contained in the upstream branch.
	Commit string
	PRRefSet
}

SyncPRRefSet calculates the set of refs that correspond to a PR branch that is performing a Git sync from an upstream repository.

func (SyncPRRefSet) ForkFromMainRefspec

func (b SyncPRRefSet) ForkFromMainRefspec(mainBranch string) string

ForkFromMainRefspec fetches the specified main branch on the target repo into the local branch.

func (SyncPRRefSet) UpstreamFetchRefspec

func (b SyncPRRefSet) UpstreamFetchRefspec() string

UpstreamFetchRefspec fetches the current upstream ref into the local branch.

func (SyncPRRefSet) UpstreamLocalBranch

func (b SyncPRRefSet) UpstreamLocalBranch() string

UpstreamLocalBranch is the name of the upstream ref after it has been fetched locally.

func (SyncPRRefSet) UpstreamLocalSyncTarget

func (b SyncPRRefSet) UpstreamLocalSyncTarget() string

UpstreamLocalSyncTarget is the commit (or branch) that should be synced to. Normally, it is the tip of the upstream ref, but it may be a specific commit if the config struct specified one.

func (SyncPRRefSet) UpstreamMirrorFetchRefspec

func (b SyncPRRefSet) UpstreamMirrorFetchRefspec() string

UpstreamMirrorFetchRefspec fetches the current upstream ref as it is in an upstream mirror into a local branch.

func (SyncPRRefSet) UpstreamMirrorLocalBranch

func (b SyncPRRefSet) UpstreamMirrorLocalBranch() string

UpstreamMirrorLocalBranch is the name of the upstream ref after it has been fetched locally from the mirror of the upstream.

func (SyncPRRefSet) UpstreamMirrorRefspec

func (b SyncPRRefSet) UpstreamMirrorRefspec() string

UpstreamMirrorRefspec is the refspec that mirrors the original branch name to the same name in another repo. This can be used with "push" for a mirror operation.

Jump to

Keyboard shortcuts

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