pull

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsClosed              = errors.New("pull is closed")
	ErrUserNotAllowedToMerge = models.ErrDisallowedToMerge{}
	ErrHasMerged             = errors.New("has already been merged")
	ErrIsWorkInProgress      = errors.New("work in progress PRs cannot be merged")
	ErrIsChecking            = errors.New("cannot merge while conflict checking is in progress")
	ErrNotMergableState      = errors.New("not in mergeable state")
	ErrDependenciesLeft      = errors.New("is blocked by an open dependency")
)
View Source
var ErrUserHasNoPermissionForAction = errors.New("user not allowed to do this action")

Functions

func AddTestPullRequestTask

func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, isSync bool, oldCommitID, newCommitID string)

AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch, and generate new patch for testing as needed.

func AddToTaskQueue

func AddToTaskQueue(pr *issues_model.PullRequest)

AddToTaskQueue adds itself to pull request test task queue.

func AttemptThreeWayMerge

func AttemptThreeWayMerge(ctx context.Context, gitPath string, gitRepo *git.Repository, base, ours, theirs, description string) (bool, []string, error)

AttemptThreeWayMerge will attempt to three way merge using git read-tree and then follow the git merge-one-file algorithm to attempt to resolve basic conflicts

func ChangeTargetBranch

func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, targetBranch string) (err error)

ChangeTargetBranch changes the target branch of this pull request, as the given user.

func CheckFileProtection

func CheckFileProtection(repo *git.Repository, oldCommitID, newCommitID string, patterns []glob.Glob, limit int, env []string) ([]string, error)

CheckFileProtection check file Protection

func CheckPRsForBaseBranch

func CheckPRsForBaseBranch(baseRepo *repo_model.Repository, baseBranchName string) error

CheckPRsForBaseBranch check all pulls with baseBrannch

func CheckPullBranchProtections

func CheckPullBranchProtections(ctx context.Context, pr *issues_model.PullRequest, skipProtectedFilesCheck bool) (err error)

CheckPullBranchProtections checks whether the PR is ready to be merged (reviews and status checks)

func CheckPullMergable

func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *issues_model.PullRequest, mergeCheckType MergeCheckType, adminSkipProtectionCheck bool) error

CheckPullMergable check if the pull mergable based on all conditions (branch protection, merge options, ...)

func CheckUnprotectedFiles

func CheckUnprotectedFiles(repo *git.Repository, oldCommitID, newCommitID string, patterns []glob.Glob, env []string) (bool, error)

CheckUnprotectedFiles check if the commit only touches unprotected files

func CloseBranchPulls

func CloseBranchPulls(doer *user_model.User, repoID int64, branch string) error

CloseBranchPulls close all the pull requests who's head branch is the branch

func CloseRepoBranchesPulls

func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) error

CloseRepoBranchesPulls close all pull requests which head branches are in the given repository, but only whose base repo is not in the given repository

func CreateCodeComment

func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue, line int64, content, treePath string, pendingReview bool, replyReviewID int64, latestCommitID string) (*issues_model.Comment, error)

CreateCodeComment creates a comment on the code line

func CreatePushPullComment

func CreatePushPullComment(ctx context.Context, pusher *user_model.User, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (comment *issues_model.Comment, err error)

CreatePushPullComment create push code to pull base comment

func DismissReview

func DismissReview(ctx context.Context, reviewID, repoID int64, message string, doer *user_model.User, isDismiss, dismissPriors bool) (comment *issues_model.Comment, err error)

DismissReview dismissing stale review by repo admin

func DownloadDiffOrPatch

func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io.Writer, patch, binary bool) error

DownloadDiffOrPatch will write the patch for the pr to the writer

func GetDefaultMergeMessage

func GetDefaultMergeMessage(ctx context.Context, baseGitRepo *git.Repository, pr *issues_model.PullRequest, mergeStyle repo_model.MergeStyle) (message, body string, err error)

GetDefaultMergeMessage returns default message used when merging pull request

func GetDiverging

func GetDiverging(ctx context.Context, pr *issues_model.PullRequest) (*git.DivergeObject, error)

GetDiverging determines how many commits a PR is ahead or behind the PR base branch

func GetIssuesAllCommitStatus

func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList) (map[int64][]*git_model.CommitStatus, map[int64]*git_model.CommitStatus, error)

GetIssuesAllCommitStatus returns a map of issue ID to a list of all statuses for the most recent commit as well as a map of issue ID to only the commit's latest status

func GetIssuesLastCommitStatus

func GetIssuesLastCommitStatus(ctx context.Context, issues issues_model.IssueList) (map[int64]*git_model.CommitStatus, error)

GetIssuesLastCommitStatus returns a map of issue ID to the most recent commit's latest status

func GetPullRequestCommitStatusState

func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullRequest) (structs.CommitStatusState, error)

GetPullRequestCommitStatusState returns pull request merged commit status state

func GetSquashMergeCommitMessages

func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequest) string

GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)

func Init

func Init() error

Init runs the task queue to test all the checking status pull requests

func InitializePullRequests

func InitializePullRequests(ctx context.Context)

InitializePullRequests checks and tests untested patches of pull requests.

func InvalidateCodeComments

func InvalidateCodeComments(ctx context.Context, prs issues_model.PullRequestList, doer *user_model.User, repo *git.Repository, branch string) error

InvalidateCodeComments will lookup the prs for code comments which got invalidated by change

func IsCommitStatusContextSuccess

func IsCommitStatusContextSuccess(commitStatuses []*git_model.CommitStatus, requiredContexts []string) bool

IsCommitStatusContextSuccess returns true if all required status check contexts succeed.

func IsHeadEqualWithBranch

func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, branchName string) (bool, error)

IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head

func IsPullCommitStatusPass

func IsPullCommitStatusPass(ctx context.Context, pr *issues_model.PullRequest) (bool, error)

IsPullCommitStatusPass returns if all required status checks PASS

func IsUserAllowedToMerge

func IsUserAllowedToMerge(ctx context.Context, pr *issues_model.PullRequest, p access_model.Permission, user *user_model.User) (bool, error)

IsUserAllowedToMerge check if user is allowed to merge PR with given permissions and branch protections

func IsUserAllowedToUpdate

func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest, user *user_model.User) (mergeAllowed, rebaseAllowed bool, err error)

IsUserAllowedToUpdate check if user is allowed to update PR with given permissions and branch protections

func LFSPush

func LFSPush(ctx context.Context, tmpBasePath, mergeHeadSHA, mergeBaseSHA string, pr *issues_model.PullRequest) error

LFSPush pushes lfs objects referred to in new commits in the head repository from the base repository

func Merge

func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, wasAutoMerged bool) error

Merge merges pull request to base repository. Caller should check PR is ready to be merged (review and status checks)

func MergeRequiredContextsCommitStatus

func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus, requiredContexts []string) structs.CommitStatusState

MergeRequiredContextsCommitStatus returns a commit status state for given required contexts

func MergedManually

func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, commitID string) error

MergedManually mark pr as merged manually

func NewPullRequest

func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issues_model.Issue, labelIDs []int64, uuids []string, pr *issues_model.PullRequest, assigneeIDs []int64) error

NewPullRequest creates new pull request with labels for repository.

func PushToBaseRepo

func PushToBaseRepo(ctx context.Context, pr *issues_model.PullRequest) (err error)

PushToBaseRepo pushes commits from branches of head repository to corresponding branches of base repository. FIXME: Only push branches that are actually updates?

func SetAllowEdits

func SetAllowEdits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, allow bool) error

SetAllowEdits allow edits from maintainers to PRs

func SubmitReview

func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue, reviewType issues_model.ReviewType, content, commitID string, attachmentUUIDs []string) (*issues_model.Review, *issues_model.Comment, error)

SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist

func TestPatch

func TestPatch(pr *issues_model.PullRequest) error

TestPatch will test whether a simple patch will apply

func Update

func Update(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, message string, rebase bool) error

Update updates pull request with base branch.

func UpdateRef

func UpdateRef(ctx context.Context, pr *issues_model.PullRequest) (err error)

UpdateRef update refs/pull/id/head directly for agit flow pull request

Types

type MergeCheckType

type MergeCheckType int
const (
	MergeCheckTypeGeneral  MergeCheckType = iota // general merge checks for "merge", "rebase", "squash", etc
	MergeCheckTypeManually                       // Manually Merged button (mark a PR as merged manually)
	MergeCheckTypeAuto                           // Auto Merge (Scheduled Merge) After Checks Succeed
)

Jump to

Keyboard shortcuts

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