summaryrefslogtreecommitdiffstats
path: root/services/pull
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-24 17:49:20 +0800
committerGitHub <noreply@github.com>2021-11-24 17:49:20 +0800
commita666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch)
tree9ab1434b759a8a2cb275a83149903a823851e309 /services/pull
parent4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff)
downloadgitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz
gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip
Move user related model into models/user (#17781)
* Move user related model into models/user * Fix lint for windows * Fix windows lint * Fix windows lint * Move some tests in models * Merge
Diffstat (limited to 'services/pull')
-rw-r--r--services/pull/check.go3
-rw-r--r--services/pull/merge.go15
-rw-r--r--services/pull/pull.go11
-rw-r--r--services/pull/review.go9
-rw-r--r--services/pull/update.go5
5 files changed, 24 insertions, 19 deletions
diff --git a/services/pull/check.go b/services/pull/check.go
index 1fb167ac21..03d4a39919 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
@@ -159,7 +160,7 @@ func manuallyMerged(pr *models.PullRequest) bool {
pr.MergedCommitID = commit.ID.String()
pr.MergedUnix = timeutil.TimeStamp(commit.Author.When.Unix())
pr.Status = models.PullRequestStatusManuallyMerged
- merger, _ := models.GetUserByEmail(commit.Author.Email)
+ merger, _ := user_model.GetUserByEmail(commit.Author.Email)
// When the commit author is unknown set the BaseRepo owner as merger
if merger == nil {
diff --git a/services/pull/merge.go b/services/pull/merge.go
index e4ed4e38bd..f94aa36128 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -30,7 +31,7 @@ import (
// Merge merges pull request to base repository.
// Caller should check PR is ready to be merged (review and status checks)
// FIXME: add repoWorkingPull make sure two merges does not happen at same time.
-func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository, mergeStyle models.MergeStyle, message string) (err error) {
+func Merge(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle models.MergeStyle, message string) (err error) {
if err = pr.LoadHeadRepo(); err != nil {
log.Error("LoadHeadRepo: %v", err)
return fmt.Errorf("LoadHeadRepo: %v", err)
@@ -110,7 +111,7 @@ func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repositor
}
// rawMerge perform the merge operation without changing any pull information in database
-func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.MergeStyle, message string) (string, error) {
+func rawMerge(pr *models.PullRequest, doer *user_model.User, mergeStyle models.MergeStyle, message string) (string, error) {
err := git.LoadGitVersion()
if err != nil {
log.Error("git.LoadGitVersion: %v", err)
@@ -396,10 +397,10 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge
}
}
- var headUser *models.User
+ var headUser *user_model.User
err = pr.HeadRepo.GetOwner()
if err != nil {
- if !models.IsErrUserNotExist(err) {
+ if !user_model.IsErrUserNotExist(err) {
log.Error("Can't find user: %d for head repository - %v", pr.HeadRepo.OwnerID, err)
return "", err
}
@@ -541,7 +542,7 @@ func getDiffTree(repoPath, baseBranch, headBranch string) (string, error) {
}
// IsSignedIfRequired check if merge will be signed if required
-func IsSignedIfRequired(pr *models.PullRequest, doer *models.User) (bool, error) {
+func IsSignedIfRequired(pr *models.PullRequest, doer *user_model.User) (bool, error) {
if err := pr.LoadProtectedBranch(); err != nil {
return false, err
}
@@ -556,7 +557,7 @@ func IsSignedIfRequired(pr *models.PullRequest, doer *models.User) (bool, error)
}
// IsUserAllowedToMerge check if user is allowed to merge PR with given permissions and branch protections
-func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *models.User) (bool, error) {
+func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *user_model.User) (bool, error) {
if user == nil {
return false, nil
}
@@ -632,7 +633,7 @@ func CheckPRReadyToMerge(pr *models.PullRequest, skipProtectedFilesCheck bool) (
}
// MergedManually mark pr as merged manually
-func MergedManually(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository, commitID string) (err error) {
+func MergedManually(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, commitID string) (err error) {
prUnit, err := pr.BaseRepo.GetUnit(unit.TypePullRequests)
if err != nil {
return
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 5f6198a393..339fb1e22d 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
@@ -113,7 +114,7 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6
}
// ChangeTargetBranch changes the target branch of this pull request, as the given user.
-func ChangeTargetBranch(pr *models.PullRequest, doer *models.User, targetBranch string) (err error) {
+func ChangeTargetBranch(pr *models.PullRequest, doer *user_model.User, targetBranch string) (err error) {
// Current target branch is already the same
if pr.BaseBranch == targetBranch {
return nil
@@ -209,7 +210,7 @@ func ChangeTargetBranch(pr *models.PullRequest, doer *models.User, targetBranch
return nil
}
-func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *models.User, branch string) error {
+func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *user_model.User, branch string) error {
repo, err := models.GetRepositoryByID(repoID)
if err != nil {
return fmt.Errorf("GetRepositoryByID: %v", err)
@@ -231,7 +232,7 @@ func checkForInvalidation(requests models.PullRequestList, repoID int64, doer *m
// AddTestPullRequestTask adds new test tasks by given head/base repository and head/base branch,
// and generate new patch for testing as needed.
-func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSync bool, oldCommitID, newCommitID string) {
+func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string, isSync bool, oldCommitID, newCommitID string) {
log.Trace("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", repoID, branch)
graceful.GetManager().RunWithShutdownContext(func(ctx context.Context) {
// There is no sensible way to shut this down ":-("
@@ -494,7 +495,7 @@ func (errs errlist) Error() string {
}
// CloseBranchPulls close all the pull requests who's head branch is the branch
-func CloseBranchPulls(doer *models.User, repoID int64, branch string) error {
+func CloseBranchPulls(doer *user_model.User, repoID int64, branch string) error {
prs, err := models.GetUnmergedPullRequestsByHeadInfo(repoID, branch)
if err != nil {
return err
@@ -523,7 +524,7 @@ func CloseBranchPulls(doer *models.User, repoID int64, branch string) 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 CloseRepoBranchesPulls(doer *models.User, repo *models.Repository) error {
+func CloseRepoBranchesPulls(doer *user_model.User, repo *models.Repository) error {
branches, _, err := git.GetBranchesByPath(repo.RepoPath(), 0, 0)
if err != nil {
return err
diff --git a/services/pull/review.go b/services/pull/review.go
index 081b17cd83..31c2e99782 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
@@ -20,7 +21,7 @@ import (
)
// CreateCodeComment creates a comment on the code line
-func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models.Issue, line int64, content string, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*models.Comment, error) {
+func CreateCodeComment(doer *user_model.User, gitRepo *git.Repository, issue *models.Issue, line int64, content string, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*models.Comment, error) {
var (
existsReview bool
@@ -114,7 +115,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
var notEnoughLines = regexp.MustCompile(`exit status 128 - fatal: file .* has only \d+ lines?`)
// createCodeComment creates a plain code comment at the specified line / path
-func createCodeComment(doer *models.User, repo *models.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) {
+func createCodeComment(doer *user_model.User, repo *models.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) {
var commitID, patch string
if err := issue.LoadPullRequest(); err != nil {
return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err)
@@ -216,7 +217,7 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
}
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
-func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string, attachmentUUIDs []string) (*models.Review, *models.Comment, error) {
+func SubmitReview(doer *user_model.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string, attachmentUUIDs []string) (*models.Review, *models.Comment, error) {
pr, err := issue.GetPullRequest()
if err != nil {
return nil, nil, err
@@ -270,7 +271,7 @@ func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issu
}
// DismissReview dismissing stale review by repo admin
-func DismissReview(reviewID int64, message string, doer *models.User, isDismiss bool) (comment *models.Comment, err error) {
+func DismissReview(reviewID int64, message string, doer *user_model.User, isDismiss bool) (comment *models.Comment, err error) {
review, err := models.GetReviewByID(reviewID)
if err != nil {
return
diff --git a/services/pull/update.go b/services/pull/update.go
index 4b4e67797e..ef6e84598e 100644
--- a/services/pull/update.go
+++ b/services/pull/update.go
@@ -8,12 +8,13 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
)
// Update updates pull request with base branch.
-func Update(pull *models.PullRequest, doer *models.User, message string, rebase bool) error {
+func Update(pull *models.PullRequest, doer *user_model.User, message string, rebase bool) error {
var (
pr *models.PullRequest
style models.MergeStyle
@@ -67,7 +68,7 @@ func Update(pull *models.PullRequest, doer *models.User, message string, rebase
}
// IsUserAllowedToUpdate check if user is allowed to update PR with given permissions and branch protections
-func IsUserAllowedToUpdate(pull *models.PullRequest, user *models.User) (mergeAllowed, rebaseAllowed bool, err error) {
+func IsUserAllowedToUpdate(pull *models.PullRequest, user *user_model.User) (mergeAllowed, rebaseAllowed bool, err error) {
if pull.Flow == models.PullRequestFlowAGit {
return false, false, nil
}