Add context.Context
to more methods (#21546)
This PR adds a context parameter to a bunch of methods. Some helper `xxxCtx()` methods got replaced with the normal name now. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
fefdb7ffd1
commit
044c754ea5
148 changed files with 1411 additions and 1564 deletions
|
@ -48,7 +48,7 @@ var (
|
|||
func AddToTaskQueue(pr *issues_model.PullRequest) {
|
||||
err := prPatchCheckerQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error {
|
||||
pr.Status = issues_model.PullRequestStatusChecking
|
||||
err := pr.UpdateColsIfNotMerged("status")
|
||||
err := pr.UpdateColsIfNotMerged(db.DefaultContext, "status")
|
||||
if err != nil {
|
||||
log.Error("AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err)
|
||||
} else {
|
||||
|
@ -68,7 +68,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce
|
|||
return ErrHasMerged
|
||||
}
|
||||
|
||||
if err := pr.LoadIssueCtx(ctx); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
return err
|
||||
} else if pr.Issue.IsClosed {
|
||||
return ErrIsClosed
|
||||
|
@ -142,7 +142,7 @@ func isSignedIfRequired(ctx context.Context, pr *issues_model.PullRequest, doer
|
|||
|
||||
// checkAndUpdateStatus checks if pull request is possible to leaving checking status,
|
||||
// and set to be either conflict or mergeable.
|
||||
func checkAndUpdateStatus(pr *issues_model.PullRequest) {
|
||||
func checkAndUpdateStatus(ctx context.Context, pr *issues_model.PullRequest) {
|
||||
// Status is not changed to conflict means mergeable.
|
||||
if pr.Status == issues_model.PullRequestStatusChecking {
|
||||
pr.Status = issues_model.PullRequestStatusMergeable
|
||||
|
@ -155,7 +155,7 @@ func checkAndUpdateStatus(pr *issues_model.PullRequest) {
|
|||
}
|
||||
|
||||
if !has {
|
||||
if err := pr.UpdateColsIfNotMerged("merge_base", "status", "conflicted_files", "changed_protected_files"); err != nil {
|
||||
if err := pr.UpdateColsIfNotMerged(ctx, "merge_base", "status", "conflicted_files", "changed_protected_files"); err != nil {
|
||||
log.Error("Update[%d]: %v", pr.ID, err)
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
|||
// manuallyMerged checks if a pull request got manually merged
|
||||
// When a pull request got manually merged mark the pull request as merged
|
||||
func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("PullRequest[%d].LoadBaseRepo: %v", pr.ID, err)
|
||||
return false
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
notification.NotifyMergePullRequest(pr, merger)
|
||||
notification.NotifyMergePullRequest(ctx, merger, pr)
|
||||
|
||||
log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commit.ID.String())
|
||||
return true
|
||||
|
@ -346,7 +346,7 @@ func testPR(id int64) {
|
|||
}
|
||||
return
|
||||
}
|
||||
checkAndUpdateStatus(pr)
|
||||
checkAndUpdateStatus(ctx, pr)
|
||||
}
|
||||
|
||||
// CheckPrsForBaseBranch check all pulls with bseBrannch
|
||||
|
|
|
@ -101,7 +101,7 @@ func IsPullCommitStatusPass(ctx context.Context, pr *issues_model.PullRequest) (
|
|||
// GetPullRequestCommitStatusState returns pull request merged commit status state
|
||||
func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullRequest) (structs.CommitStatusState, error) {
|
||||
// Ensure HeadRepo is loaded
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return "", errors.Wrap(err, "LoadHeadRepo")
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR
|
|||
return "", err
|
||||
}
|
||||
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return "", errors.Wrap(err, "LoadBaseRepo")
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ func SetAllowEdits(ctx context.Context, doer *user_model.User, pr *issues_model.
|
|||
return ErrUserHasNoPermissionForAction
|
||||
}
|
||||
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -40,18 +40,18 @@ import (
|
|||
)
|
||||
|
||||
// GetDefaultMergeMessage returns default message used when merging pull request
|
||||
func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRequest, mergeStyle repo_model.MergeStyle) (string, error) {
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
func GetDefaultMergeMessage(ctx context.Context, baseGitRepo *git.Repository, pr *issues_model.PullRequest, mergeStyle repo_model.MergeStyle) (string, error) {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := pr.LoadBaseRepo(); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if pr.BaseRepo == nil {
|
||||
return "", repo_model.ErrRepoNotExist{ID: pr.BaseRepoID}
|
||||
}
|
||||
|
||||
if err := pr.LoadIssue(); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRe
|
|||
vars["HeadRepoOwnerName"] = pr.HeadRepo.OwnerName
|
||||
vars["HeadRepoName"] = pr.HeadRepo.Name
|
||||
}
|
||||
refs, err := pr.ResolveCrossReferences(baseGitRepo.Ctx)
|
||||
refs, err := pr.ResolveCrossReferences(ctx)
|
||||
if err == nil {
|
||||
closeIssueIndexes := make([]string, 0, len(refs))
|
||||
closeWord := "close"
|
||||
|
@ -134,10 +134,10 @@ func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRe
|
|||
// Merge merges pull request to base repository.
|
||||
// Caller should check PR is ready to be merged (review and status checks)
|
||||
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 {
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if err := pr.LoadBaseRepo(); err != nil {
|
||||
} else if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
@ -179,24 +179,24 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
|
|||
pr.MergerID = doer.ID
|
||||
|
||||
if _, err := pr.SetMerged(hammerCtx); err != nil {
|
||||
log.Error("setMerged [%d]: %v", pr.ID, err)
|
||||
log.Error("SetMerged [%d]: %v", pr.ID, err)
|
||||
}
|
||||
|
||||
if err := pr.LoadIssueCtx(hammerCtx); err != nil {
|
||||
log.Error("loadIssue [%d]: %v", pr.ID, err)
|
||||
if err := pr.LoadIssue(hammerCtx); err != nil {
|
||||
log.Error("LoadIssue [%d]: %v", pr.ID, err)
|
||||
}
|
||||
|
||||
if err := pr.Issue.LoadRepo(hammerCtx); err != nil {
|
||||
log.Error("loadRepo for issue [%d]: %v", pr.ID, err)
|
||||
log.Error("LoadRepo for issue [%d]: %v", pr.ID, err)
|
||||
}
|
||||
if err := pr.Issue.Repo.GetOwner(hammerCtx); err != nil {
|
||||
log.Error("GetOwner for issue repo [%d]: %v", pr.ID, err)
|
||||
log.Error("GetOwner for PR [%d]: %v", pr.ID, err)
|
||||
}
|
||||
|
||||
if wasAutoMerged {
|
||||
notification.NotifyAutoMergePullRequest(pr, doer)
|
||||
notification.NotifyAutoMergePullRequest(hammerCtx, doer, pr)
|
||||
} else {
|
||||
notification.NotifyMergePullRequest(pr, doer)
|
||||
notification.NotifyMergePullRequest(hammerCtx, doer, pr)
|
||||
}
|
||||
|
||||
// Reset cached commit count
|
||||
|
@ -210,7 +210,7 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
|
|||
}
|
||||
|
||||
for _, ref := range refs {
|
||||
if err = ref.LoadIssueCtx(hammerCtx); err != nil {
|
||||
if err = ref.LoadIssue(hammerCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = ref.Issue.LoadRepo(hammerCtx); err != nil {
|
||||
|
@ -511,7 +511,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
|||
return "", err
|
||||
}
|
||||
|
||||
if err = pr.Issue.LoadPoster(); err != nil {
|
||||
if err = pr.Issue.LoadPoster(ctx); err != nil {
|
||||
log.Error("LoadPoster: %v", err)
|
||||
return "", fmt.Errorf("LoadPoster: %w", err)
|
||||
}
|
||||
|
@ -767,7 +767,7 @@ func IsUserAllowedToMerge(ctx context.Context, pr *issues_model.PullRequest, p a
|
|||
|
||||
// CheckPullBranchProtections checks whether the PR is ready to be merged (reviews and status checks)
|
||||
func CheckPullBranchProtections(ctx context.Context, pr *issues_model.PullRequest, skipProtectedFilesCheck bool) (err error) {
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
|
@ -878,7 +878,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit
|
|||
return err
|
||||
}
|
||||
|
||||
notification.NotifyMergePullRequest(pr, doer)
|
||||
notification.NotifyMergePullRequest(baseGitRepo.Ctx, doer, pr)
|
||||
log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commitID)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import (
|
|||
|
||||
// DownloadDiffOrPatch will write the patch for the pr to the writer
|
||||
func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io.Writer, patch, binary bool) error {
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("Unable to load base repository ID %d for pr #%d [%d]", pr.BaseRepoID, pr.Index, pr.ID)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -82,12 +82,12 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issu
|
|||
return err
|
||||
}
|
||||
|
||||
notification.NotifyNewPullRequest(pr, mentions)
|
||||
notification.NotifyNewPullRequest(prCtx, pr, mentions)
|
||||
if len(pull.Labels) > 0 {
|
||||
notification.NotifyIssueChangeLabels(pull.Poster, pull, pull.Labels, nil)
|
||||
notification.NotifyIssueChangeLabels(prCtx, pull.Poster, pull, pull.Labels, nil)
|
||||
}
|
||||
if pull.Milestone != nil {
|
||||
notification.NotifyIssueChangeMilestone(pull.Poster, pull, 0)
|
||||
notification.NotifyIssueChangeMilestone(prCtx, pull.Poster, pull, 0)
|
||||
}
|
||||
|
||||
// add first push codes comment
|
||||
|
@ -172,7 +172,7 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
|||
}
|
||||
|
||||
// Check if pull request for the new target branch already exists
|
||||
existingPr, err := issues_model.GetUnmergedPullRequest(pr.HeadRepoID, pr.BaseRepoID, pr.HeadBranch, targetBranch, issues_model.PullRequestFlowGithub)
|
||||
existingPr, err := issues_model.GetUnmergedPullRequest(ctx, pr.HeadRepoID, pr.BaseRepoID, pr.HeadBranch, targetBranch, issues_model.PullRequestFlowGithub)
|
||||
if existingPr != nil {
|
||||
return issues_model.ErrPullRequestAlreadyExists{
|
||||
ID: existingPr.ID,
|
||||
|
@ -210,7 +210,7 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
|||
pr.CommitsAhead = divergence.Ahead
|
||||
pr.CommitsBehind = divergence.Behind
|
||||
|
||||
if err := pr.UpdateColsIfNotMerged("merge_base", "status", "conflicted_files", "changed_protected_files", "base_branch", "commits_ahead", "commits_behind"); err != nil {
|
||||
if err := pr.UpdateColsIfNotMerged(ctx, "merge_base", "status", "conflicted_files", "changed_protected_files", "base_branch", "commits_ahead", "commits_behind"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -231,9 +231,9 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
|||
}
|
||||
|
||||
func checkForInvalidation(ctx context.Context, requests issues_model.PullRequestList, repoID int64, doer *user_model.User, branch string) error {
|
||||
repo, err := repo_model.GetRepositoryByID(repoID)
|
||||
repo, err := repo_model.GetRepositoryByIDCtx(ctx, repoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryByID: %w", err)
|
||||
return fmt.Errorf("GetRepositoryByIDCtx: %w", err)
|
||||
}
|
||||
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||
if err != nil {
|
||||
|
@ -301,7 +301,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
|||
}
|
||||
|
||||
pr.Issue.PullRequest = pr
|
||||
notification.NotifyPullRequestSynchronized(doer, pr)
|
||||
notification.NotifyPullRequestSynchronized(ctx, doer, pr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
|||
AddToTaskQueue(pr)
|
||||
comment, err := issues_model.CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
|
||||
if err == nil && comment != nil {
|
||||
notification.NotifyPullRequestPushCommits(doer, pr, comment)
|
||||
notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,14 +352,14 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
|||
// checkIfPRContentChanged checks if diff to target branch has changed by push
|
||||
// A commit can be considered to leave the PR untouched if the patch/diff with its merge base is unchanged
|
||||
func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
|
||||
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||
return false, fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if pr.HeadRepo == nil {
|
||||
// corrupt data assumed changed
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
return false, fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
|
@ -430,22 +430,22 @@ func PushToBaseRepo(ctx context.Context, pr *issues_model.PullRequest) (err erro
|
|||
func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, prefixHeadBranch string) (err error) {
|
||||
log.Trace("PushToBaseRepo[%d]: pushing commits to base repo '%s'", pr.BaseRepoID, pr.GetGitRefName())
|
||||
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("Unable to load head repository for PR[%d] Error: %v", pr.ID, err)
|
||||
return err
|
||||
}
|
||||
headRepoPath := pr.HeadRepo.RepoPath()
|
||||
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("Unable to load base repository for PR[%d] Error: %v", pr.ID, err)
|
||||
return err
|
||||
}
|
||||
baseRepoPath := pr.BaseRepo.RepoPath()
|
||||
|
||||
if err = pr.LoadIssue(); err != nil {
|
||||
if err = pr.LoadIssue(ctx); err != nil {
|
||||
return fmt.Errorf("unable to load issue %d for pr %d: %w", pr.IssueID, pr.ID, err)
|
||||
}
|
||||
if err = pr.Issue.LoadPoster(); err != nil {
|
||||
if err = pr.Issue.LoadPoster(ctx); err != nil {
|
||||
return fmt.Errorf("unable to load poster %d for pr %d: %w", pr.Issue.PosterID, pr.ID, err)
|
||||
}
|
||||
|
||||
|
@ -485,7 +485,7 @@ func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, pre
|
|||
// UpdateRef update refs/pull/id/head directly for agit flow pull request
|
||||
func UpdateRef(ctx context.Context, pr *issues_model.PullRequest) (err error) {
|
||||
log.Trace("UpdateRef[%d]: upgate pull request ref in base repo '%s'", pr.ID, pr.GetGitRefName())
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("Unable to load base repository for PR[%d] Error: %v", pr.ID, err)
|
||||
return err
|
||||
}
|
||||
|
@ -583,21 +583,21 @@ var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[ \t]*
|
|||
|
||||
// GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)
|
||||
func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequest) string {
|
||||
if err := pr.LoadIssue(); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("Cannot load issue %d for PR id %d: Error: %v", pr.IssueID, pr.ID, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err := pr.Issue.LoadPoster(); err != nil {
|
||||
if err := pr.Issue.LoadPoster(ctx); err != nil {
|
||||
log.Error("Cannot load poster %d for pr id %d, index %d Error: %v", pr.Issue.PosterID, pr.ID, pr.Index, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if pr.HeadRepo == nil {
|
||||
var err error
|
||||
pr.HeadRepo, err = repo_model.GetRepositoryByID(pr.HeadRepoID)
|
||||
pr.HeadRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.HeadRepoID)
|
||||
if err != nil {
|
||||
log.Error("GetRepositoryById[%d]: %v", pr.HeadRepoID, err)
|
||||
log.Error("GetRepositoryByIdCtx[%d]: %v", pr.HeadRepoID, err)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
@ -743,10 +743,10 @@ func GetIssuesLastCommitStatus(ctx context.Context, issues issues_model.IssueLis
|
|||
|
||||
// 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 GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList) (map[int64][]*git_model.CommitStatus, map[int64]*git_model.CommitStatus, error) {
|
||||
if err := issues.LoadPullRequests(); err != nil {
|
||||
if err := issues.LoadPullRequests(ctx); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if _, err := issues.LoadRepositories(); err != nil {
|
||||
if _, err := issues.LoadRepositories(ctx); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
|
@ -802,7 +802,7 @@ func getAllCommitStatus(gitRepo *git.Repository, pr *issues_model.PullRequest) (
|
|||
// IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head
|
||||
func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, branchName string) (bool, error) {
|
||||
var err error
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
|
||||
|
@ -816,7 +816,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
|
|||
return false, err
|
||||
}
|
||||
|
||||
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
var headGitRepo *git.Repository
|
||||
|
|
|
@ -8,6 +8,7 @@ package pull
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
|
@ -40,18 +41,18 @@ func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) {
|
|||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
|
||||
assert.NoError(t, pr.LoadBaseRepo())
|
||||
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
||||
gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
mergeMessage, err := GetDefaultMergeMessage(gitRepo, pr, "")
|
||||
mergeMessage, err := GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from branch2 into master", mergeMessage)
|
||||
|
||||
pr.BaseRepoID = 1
|
||||
pr.HeadRepoID = 2
|
||||
mergeMessage, err = GetDefaultMergeMessage(gitRepo, pr, "")
|
||||
mergeMessage, err = GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from user2/repo1:branch2 into master", mergeMessage)
|
||||
}
|
||||
|
@ -70,12 +71,12 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
|
|||
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2, BaseRepo: baseRepo})
|
||||
|
||||
assert.NoError(t, pr.LoadBaseRepo())
|
||||
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
||||
gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
mergeMessage, err := GetDefaultMergeMessage(gitRepo, pr, "")
|
||||
mergeMessage, err := GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Merge pull request 'issue3' (!3) from branch2 into master", mergeMessage)
|
||||
|
@ -84,7 +85,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
|
|||
pr.HeadRepoID = 2
|
||||
pr.BaseRepo = nil
|
||||
pr.HeadRepo = nil
|
||||
mergeMessage, err = GetDefaultMergeMessage(gitRepo, pr, "")
|
||||
mergeMessage, err = GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from user2/repo2:branch2 into master", mergeMessage)
|
||||
|
|
|
@ -67,7 +67,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
|
|||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateIssueComment(doer, issue.Repo, issue, comment, mentions)
|
||||
notification.NotifyCreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions)
|
||||
|
||||
return comment, nil
|
||||
}
|
||||
|
@ -119,12 +119,12 @@ var notEnoughLines = regexp.MustCompile(`exit status 128 - fatal: file .* has on
|
|||
// createCodeComment creates a plain code comment at the specified line / path
|
||||
func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content, treePath string, line, reviewID int64) (*issues_model.Comment, error) {
|
||||
var commitID, patch string
|
||||
if err := issue.LoadPullRequest(); err != nil {
|
||||
return nil, fmt.Errorf("GetPullRequestByIssueID: %w", err)
|
||||
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||
return nil, fmt.Errorf("LoadPullRequest: %w", err)
|
||||
}
|
||||
pr := issue.PullRequest
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
return nil, fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return nil, fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
|
||||
if err != nil {
|
||||
|
@ -254,7 +254,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
notification.NotifyPullRequestReview(pr, review, comm, mentions)
|
||||
notification.NotifyPullRequestReview(ctx, pr, review, comm, mentions)
|
||||
|
||||
for _, lines := range review.CodeComments {
|
||||
for _, comments := range lines {
|
||||
|
@ -263,7 +263,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
|||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
notification.NotifyPullRequestCodeComment(pr, codeComment, mentions)
|
||||
notification.NotifyPullRequestCodeComment(ctx, pr, codeComment, mentions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if err = review.Issue.LoadPullRequest(); err != nil {
|
||||
if err = review.Issue.LoadPullRequest(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if err = review.Issue.LoadAttributes(ctx); err != nil {
|
||||
|
@ -339,7 +339,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
|||
comment.Poster = doer
|
||||
comment.Issue = review.Issue
|
||||
|
||||
notification.NotifyPullRevieweDismiss(doer, review, comment)
|
||||
notification.NotifyPullReviewDismiss(ctx, doer, review, comment)
|
||||
|
||||
return comment, err
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
// createTemporaryRepo creates a temporary repo with "base" for pr.BaseBranch and "tracking" for pr.HeadBranch
|
||||
// it also create a second base branch called "original_base"
|
||||
func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (string, error) {
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return "", fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if pr.HeadRepo == nil {
|
||||
|
@ -31,7 +31,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
|||
return "", &repo_model.ErrRepoNotExist{
|
||||
ID: pr.HeadRepoID,
|
||||
}
|
||||
} else if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
} else if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return "", fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
} else if pr.BaseRepo == nil {
|
||||
|
|
|
@ -48,10 +48,10 @@ func Update(ctx context.Context, pull *issues_model.PullRequest, doer *user_mode
|
|||
return fmt.Errorf("Not support update agit flow pull request's head branch")
|
||||
}
|
||||
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
} else if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
@ -145,10 +145,10 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest,
|
|||
// GetDiverging determines how many commits a PR is ahead or behind the PR base branch
|
||||
func GetDiverging(ctx context.Context, pr *issues_model.PullRequest) (*git.DivergeObject, error) {
|
||||
log.Trace("GetDiverging[%d]: compare commits", pr.ID)
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue