gitpr

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApprovePR

func ApprovePR(nodeID string, pat string) 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, pat string) error

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

func GetUsername

func GetUsername(pat string) string

GetUsername queries GitHub for the username associated with a PAT.

func MutateGraphQL

func MutateGraphQL(pat string, query string, variables map[string]interface{}) error

func QueryGraphQL

func QueryGraphQL(pat string, query string, variables map[string]interface{}, result interface{}) error

Types

type ExistingPR

type ExistingPR struct {
	Title  string
	ID     string
	Number int
}

func FindExistingPR

func FindExistingPR(r *GitHubRequest, head, target *Remote, headBranch, submitterUser, githubPAT string) (*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"`

	// GitHub failure response:
	Message string               `json:"message"`
	Errors  []GitHubRequestError `json:"errors"`

	// AlreadyExists is set to true if the error message says the PR exists. Otherwise, false. For
	// our purposes, a GitHub failure response that indicates a PR already exists is not an error.
	AlreadyExists bool
}

GitHubResponse is a PR creation response from GitHub. It may represent success or failure.

func PostGitHub

func PostGitHub(ownerRepo string, request *GitHubRequest, pat string) (response *GitHubResponse, err error)

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

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