aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-06-13 17:37:59 +0800
committerGitHub <noreply@github.com>2022-06-13 17:37:59 +0800
commit1a9821f57a0293db3adc0eab8aff08ca5fa1026c (patch)
tree3c3d02813eb63c0d0827ef6d9745f6dcdd2636cb /services
parent3708ca8e2849ca7e36e6bd15ec6935a2a2d81e55 (diff)
downloadgitea-1a9821f57a0293db3adc0eab8aff08ca5fa1026c.tar.gz
gitea-1a9821f57a0293db3adc0eab8aff08ca5fa1026c.zip
Move issues related files into models/issues (#19931)
* Move access and repo permission to models/perm/access * fix test * fix git test * Move functions sequence * Some improvements per @KN4CK3R and @delvh * Move issues related code to models/issues * Move some issues related sub package * Merge * Fix test * Fix test * Fix test * Fix test * Rename some files
Diffstat (limited to 'services')
-rw-r--r--services/agit/agit.go21
-rw-r--r--services/asymkey/sign.go6
-rw-r--r--services/automerge/automerge.go24
-rw-r--r--services/comments/comments.go36
-rw-r--r--services/forms/repo_form.go15
-rw-r--r--services/forms/user_form_hidden_comments.go58
-rw-r--r--services/gitdiff/gitdiff.go14
-rw-r--r--services/gitdiff/gitdiff_test.go10
-rw-r--r--services/gitdiff/main_test.go1
-rw-r--r--services/issue/assignee.go56
-rw-r--r--services/issue/assignee_test.go6
-rw-r--r--services/issue/commit.go15
-rw-r--r--services/issue/commit_test.go57
-rw-r--r--services/issue/content.go6
-rw-r--r--services/issue/issue.go108
-rw-r--r--services/issue/issue_test.go61
-rw-r--r--services/issue/label.go32
-rw-r--r--services/issue/label_test.go16
-rw-r--r--services/issue/milestone.go13
-rw-r--r--services/issue/milestone_test.go9
-rw-r--r--services/issue/status.go14
-rw-r--r--services/mailer/mail.go29
-rw-r--r--services/mailer/mail_comment.go7
-rw-r--r--services/mailer/mail_issue.go17
-rw-r--r--services/mailer/mail_test.go17
-rw-r--r--services/migrations/gitea_uploader.go82
-rw-r--r--services/migrations/gitea_uploader_test.go6
-rw-r--r--services/pull/check.go31
-rw-r--r--services/pull/check_test.go12
-rw-r--r--services/pull/commit_status.go12
-rw-r--r--services/pull/edits.go6
-rw-r--r--services/pull/lfs.go6
-rw-r--r--services/pull/merge.go29
-rw-r--r--services/pull/patch.go21
-rw-r--r--services/pull/pull.go89
-rw-r--r--services/pull/pull_test.go6
-rw-r--r--services/pull/review.go60
-rw-r--r--services/pull/temp_repo.go5
-rw-r--r--services/pull/update.go17
-rw-r--r--services/repository/repository.go3
-rw-r--r--services/repository/template.go7
41 files changed, 599 insertions, 441 deletions
diff --git a/services/agit/agit.go b/services/agit/agit.go
index cc520dbc76..7666093c51 100644
--- a/services/agit/agit.go
+++ b/services/agit/agit.go
@@ -10,7 +10,8 @@ import (
"os"
"strings"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
+ repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
@@ -97,9 +98,9 @@ func ProcReceive(ctx *context.PrivateContext, opts *private.HookOptions) []priva
headBranch = curentTopicBranch
}
- pr, err := models.GetUnmergedPullRequest(repo.ID, repo.ID, headBranch, baseBranchName, models.PullRequestFlowAGit)
+ pr, err := issues_model.GetUnmergedPullRequest(repo.ID, repo.ID, headBranch, baseBranchName, issues_model.PullRequestFlowAGit)
if err != nil {
- if !models.IsErrPullRequestNotExist(err) {
+ if !issues_model.IsErrPullRequestNotExist(err) {
log.Error("Failed to get unmerged agit flow pull request in repository: %s/%s Error: %v", ownerName, repoName, err)
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
"Err": fmt.Sprintf("Failed to get unmerged agit flow pull request in repository: %s/%s Error: %v", ownerName, repoName, err),
@@ -134,7 +135,7 @@ func ProcReceive(ctx *context.PrivateContext, opts *private.HookOptions) []priva
return nil
}
- prIssue := &models.Issue{
+ prIssue := &issues_model.Issue{
RepoID: repo.ID,
Title: title,
PosterID: pusher.ID,
@@ -143,7 +144,7 @@ func ProcReceive(ctx *context.PrivateContext, opts *private.HookOptions) []priva
Content: description,
}
- pr := &models.PullRequest{
+ pr := &issues_model.PullRequest{
HeadRepoID: repo.ID,
BaseRepoID: repo.ID,
HeadBranch: headBranch,
@@ -152,12 +153,12 @@ func ProcReceive(ctx *context.PrivateContext, opts *private.HookOptions) []priva
HeadRepo: repo,
BaseRepo: repo,
MergeBase: "",
- Type: models.PullRequestGitea,
- Flow: models.PullRequestFlowAGit,
+ Type: issues_model.PullRequestGitea,
+ Flow: issues_model.PullRequestFlowAGit,
}
if err := pull_service.NewPullRequest(ctx, repo, prIssue, []int64{}, []string{}, pr, []int64{}); err != nil {
- if models.IsErrUserDoesNotHaveAccessToRepo(err) {
+ if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
return nil
}
@@ -249,7 +250,7 @@ func ProcReceive(ctx *context.PrivateContext, opts *private.HookOptions) []priva
})
return nil
}
- comment, err := models.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
+ comment, err := issues_model.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
if err == nil && comment != nil {
notification.NotifyPullRequestPushCommits(pusher, pr, comment)
}
@@ -270,7 +271,7 @@ func ProcReceive(ctx *context.PrivateContext, opts *private.HookOptions) []priva
// UserNameChanged handle user name change for agit flow pull
func UserNameChanged(user *user_model.User, newName string) error {
- pulls, err := models.GetAllUnmergedAgitPullRequestByPoster(user.ID)
+ pulls, err := issues_model.GetAllUnmergedAgitPullRequestByPoster(user.ID)
if err != nil {
return err
}
diff --git a/services/asymkey/sign.go b/services/asymkey/sign.go
index 0f74cd4b2a..edfd0f6cad 100644
--- a/services/asymkey/sign.go
+++ b/services/asymkey/sign.go
@@ -9,11 +9,11 @@ import (
"fmt"
"strings"
- "code.gitea.io/gitea/models"
asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
+ issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -271,7 +271,7 @@ Loop:
}
// SignMerge determines if we should sign a PR merge commit to the base repository
-func SignMerge(ctx context.Context, pr *models.PullRequest, u *user_model.User, tmpBasePath, baseCommit, headCommit string) (bool, string, *git.Signature, error) {
+func SignMerge(ctx context.Context, pr *issues_model.PullRequest, u *user_model.User, tmpBasePath, baseCommit, headCommit string) (bool, string, *git.Signature, error) {
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
log.Error("Unable to get Base Repo for pull request")
return false, "", nil, err
@@ -318,7 +318,7 @@ Loop:
if protectedBranch == nil {
return false, "", nil, &ErrWontSign{approved}
}
- if models.GetGrantedApprovalsCount(ctx, protectedBranch, pr) < 1 {
+ if issues_model.GetGrantedApprovalsCount(ctx, protectedBranch, pr) < 1 {
return false, "", nil, &ErrWontSign{approved}
}
case baseSigned:
diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go
index 3c7346ab58..d0f83f4a93 100644
--- a/services/automerge/automerge.go
+++ b/services/automerge/automerge.go
@@ -11,8 +11,8 @@ import (
"strconv"
"strings"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
pull_model "code.gitea.io/gitea/models/pull"
repo_model "code.gitea.io/gitea/models/repo"
@@ -52,7 +52,7 @@ func handle(data ...queue.Data) []queue.Data {
return nil
}
-func addToQueue(pr *models.PullRequest, sha string) {
+func addToQueue(pr *issues_model.PullRequest, sha string) {
if err := prAutoMergeQueue.PushFunc(fmt.Sprintf("%d_%s", pr.ID, sha), func() error {
log.Trace("Adding pullID: %d to the pull requests patch checking queue with sha %s", pr.ID, sha)
return nil
@@ -62,7 +62,7 @@ func addToQueue(pr *models.PullRequest, sha string) {
}
// ScheduleAutoMerge if schedule is false and no error, pull can be merged directly
-func ScheduleAutoMerge(ctx context.Context, doer *user_model.User, pull *models.PullRequest, style repo_model.MergeStyle, message string) (scheduled bool, err error) {
+func ScheduleAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_model.PullRequest, style repo_model.MergeStyle, message string) (scheduled bool, err error) {
err = db.WithTx(func(ctx context.Context) error {
lastCommitStatus, err := pull_service.GetPullRequestCommitStatusState(ctx, pull)
if err != nil {
@@ -79,27 +79,27 @@ func ScheduleAutoMerge(ctx context.Context, doer *user_model.User, pull *models.
}
scheduled = true
- _, err = models.CreateAutoMergeComment(ctx, models.CommentTypePRScheduledToAutoMerge, pull, doer)
+ _, err = issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRScheduledToAutoMerge, pull, doer)
return err
}, ctx)
return
}
// RemoveScheduledAutoMerge cancels a previously scheduled pull request
-func RemoveScheduledAutoMerge(ctx context.Context, doer *user_model.User, pull *models.PullRequest) error {
+func RemoveScheduledAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_model.PullRequest) error {
return db.WithTx(func(ctx context.Context) error {
if err := pull_model.DeleteScheduledAutoMerge(ctx, pull.ID); err != nil {
return err
}
- _, err := models.CreateAutoMergeComment(ctx, models.CommentTypePRUnScheduledToAutoMerge, pull, doer)
+ _, err := issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRUnScheduledToAutoMerge, pull, doer)
return err
}, ctx)
}
// MergeScheduledPullRequest merges a previously scheduled pull request when all checks succeeded
func MergeScheduledPullRequest(ctx context.Context, sha string, repo *repo_model.Repository) error {
- pulls, err := getPullRequestsByHeadSHA(ctx, sha, repo, func(pr *models.PullRequest) bool {
+ pulls, err := getPullRequestsByHeadSHA(ctx, sha, repo, func(pr *issues_model.PullRequest) bool {
return !pr.HasMerged && pr.CanAutoMerge()
})
if err != nil {
@@ -113,7 +113,7 @@ func MergeScheduledPullRequest(ctx context.Context, sha string, repo *repo_model
return nil
}
-func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.Repository, filter func(*models.PullRequest) bool) (map[int64]*models.PullRequest, error) {
+func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.Repository, filter func(*issues_model.PullRequest) bool) (map[int64]*issues_model.PullRequest, error) {
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
if err != nil {
return nil, err
@@ -125,7 +125,7 @@ func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.
return nil, err
}
- pulls := make(map[int64]*models.PullRequest)
+ pulls := make(map[int64]*issues_model.PullRequest)
for _, ref := range refs {
// Each pull branch starts with refs/pull/ we then go from there to find the index of the pr and then
@@ -145,10 +145,10 @@ func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.
continue
}
- p, err := models.GetPullRequestByIndex(ctx, repo.ID, prIndex)
+ p, err := issues_model.GetPullRequestByIndex(ctx, repo.ID, prIndex)
if err != nil {
// If there is no pull request for this branch, we don't try to merge it.
- if models.IsErrPullRequestNotExist(err) {
+ if issues_model.IsErrPullRequestNotExist(err) {
continue
}
return nil, err
@@ -168,7 +168,7 @@ func handlePull(pullID int64, sha string) {
fmt.Sprintf("Handle AutoMerge of pull[%d] with sha[%s]", pullID, sha))
defer finished()
- pr, err := models.GetPullRequestByID(ctx, pullID)
+ pr, err := issues_model.GetPullRequestByID(ctx, pullID)
if err != nil {
log.Error("GetPullRequestByID[%d]: %v", pullID, err)
return
diff --git a/services/comments/comments.go b/services/comments/comments.go
index b80fddf93f..c40631359b 100644
--- a/services/comments/comments.go
+++ b/services/comments/comments.go
@@ -5,9 +5,8 @@
package comments
import (
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/models/issues"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
@@ -15,9 +14,9 @@ import (
)
// CreateIssueComment creates a plain issue comment.
-func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, content string, attachments []string) (*models.Comment, error) {
- comment, err := models.CreateComment(&models.CreateCommentOptions{
- Type: models.CommentTypeComment,
+func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content string, attachments []string) (*issues_model.Comment, error) {
+ comment, err := issues_model.CreateComment(&issues_model.CreateCommentOptions{
+ Type: issues_model.CommentTypeComment,
Doer: doer,
Repo: repo,
Issue: issue,
@@ -28,7 +27,7 @@ func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issu
return nil, err
}
- mentions, err := models.FindAndUpdateIssueMentions(db.DefaultContext, issue, doer, comment.Content)
+ mentions, err := issues_model.FindAndUpdateIssueMentions(db.DefaultContext, issue, doer, comment.Content)
if err != nil {
return nil, err
}
@@ -39,28 +38,28 @@ func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issu
}
// UpdateComment updates information of comment.
-func UpdateComment(c *models.Comment, doer *user_model.User, oldContent string) error {
+func UpdateComment(c *issues_model.Comment, doer *user_model.User, oldContent string) error {
needsContentHistory := c.Content != oldContent &&
- (c.Type == models.CommentTypeComment || c.Type == models.CommentTypeReview || c.Type == models.CommentTypeCode)
+ (c.Type == issues_model.CommentTypeComment || c.Type == issues_model.CommentTypeReview || c.Type == issues_model.CommentTypeCode)
if needsContentHistory {
- hasContentHistory, err := issues.HasIssueContentHistory(db.DefaultContext, c.IssueID, c.ID)
+ hasContentHistory, err := issues_model.HasIssueContentHistory(db.DefaultContext, c.IssueID, c.ID)
if err != nil {
return err
}
if !hasContentHistory {
- if err = issues.SaveIssueContentHistory(db.DefaultContext, c.PosterID, c.IssueID, c.ID,
+ if err = issues_model.SaveIssueContentHistory(db.DefaultContext, c.PosterID, c.IssueID, c.ID,
c.CreatedUnix, oldContent, true); err != nil {
return err
}
}
}
- if err := models.UpdateComment(c, doer); err != nil {
+ if err := issues_model.UpdateComment(c, doer); err != nil {
return err
}
if needsContentHistory {
- err := issues.SaveIssueContentHistory(db.DefaultContext, doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
+ err := issues_model.SaveIssueContentHistory(db.DefaultContext, doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
if err != nil {
return err
}
@@ -72,8 +71,17 @@ func UpdateComment(c *models.Comment, doer *user_model.User, oldContent string)
}
// DeleteComment deletes the comment
-func DeleteComment(doer *user_model.User, comment *models.Comment) error {
- if err := models.DeleteComment(comment); err != nil {
+func DeleteComment(doer *user_model.User, comment *issues_model.Comment) error {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
+ return err
+ }
+ defer committer.Close()
+
+ if err := issues_model.DeleteComment(ctx, comment); err != nil {
+ return err
+ }
+ if err := committer.Commit(); err != nil {
return err
}
diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go
index 23ac1abe3c..c9327bbd9b 100644
--- a/services/forms/repo_form.go
+++ b/services/forms/repo_form.go
@@ -11,6 +11,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
project_model "code.gitea.io/gitea/models/project"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -636,18 +637,18 @@ func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) bind
}
// ReviewType will return the corresponding ReviewType for type
-func (f SubmitReviewForm) ReviewType() models.ReviewType {
+func (f SubmitReviewForm) ReviewType() issues_model.ReviewType {
switch f.Type {
case "approve":
- return models.ReviewTypeApprove
+ return issues_model.ReviewTypeApprove
case "comment":
- return models.ReviewTypeComment
+ return issues_model.ReviewTypeComment
case "reject":
- return models.ReviewTypeReject
+ return issues_model.ReviewTypeReject
case "":
- return models.ReviewTypeComment // default to comment when doing quick-submit (Ctrl+Enter) on the review form
+ return issues_model.ReviewTypeComment // default to comment when doing quick-submit (Ctrl+Enter) on the review form
default:
- return models.ReviewTypeUnknown
+ return issues_model.ReviewTypeUnknown
}
}
@@ -655,7 +656,7 @@ func (f SubmitReviewForm) ReviewType() models.ReviewType {
func (f SubmitReviewForm) HasEmptyContent() bool {
reviewType := f.ReviewType()
- return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
+ return (reviewType == issues_model.ReviewTypeComment || reviewType == issues_model.ReviewTypeReject) &&
len(strings.TrimSpace(f.Content)) == 0
}
diff --git a/services/forms/user_form_hidden_comments.go b/services/forms/user_form_hidden_comments.go
index e0c26e8ddf..35c1a6dd2a 100644
--- a/services/forms/user_form_hidden_comments.go
+++ b/services/forms/user_form_hidden_comments.go
@@ -7,69 +7,69 @@ package forms
import (
"math/big"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
)
-type hiddenCommentTypeGroupsType map[string][]models.CommentType
+type hiddenCommentTypeGroupsType map[string][]issues_model.CommentType
// hiddenCommentTypeGroups maps the group names to comment types, these group names comes from the Web UI (appearance.tmpl)
var hiddenCommentTypeGroups = hiddenCommentTypeGroupsType{
"reference": {
- /*3*/ models.CommentTypeIssueRef,
- /*4*/ models.CommentTypeCommitRef,
- /*5*/ models.CommentTypeCommentRef,
- /*6*/ models.CommentTypePullRef,
+ /*3*/ issues_model.CommentTypeIssueRef,
+ /*4*/ issues_model.CommentTypeCommitRef,
+ /*5*/ issues_model.CommentTypeCommentRef,
+ /*6*/ issues_model.CommentTypePullRef,
},
"label": {
- /*7*/ models.CommentTypeLabel,
+ /*7*/ issues_model.CommentTypeLabel,
},
"milestone": {
- /*8*/ models.CommentTypeMilestone,
+ /*8*/ issues_model.CommentTypeMilestone,
},
"assignee": {
- /*9*/ models.CommentTypeAssignees,
+ /*9*/ issues_model.CommentTypeAssignees,
},
"title": {
- /*10*/ models.CommentTypeChangeTitle,
+ /*10*/ issues_model.CommentTypeChangeTitle,
},
"branch": {
- /*11*/ models.CommentTypeDeleteBranch,
- /*25*/ models.CommentTypeChangeTargetBranch,
+ /*11*/ issues_model.CommentTypeDeleteBranch,
+ /*25*/ issues_model.CommentTypeChangeTargetBranch,
},
"time_tracking": {
- /*12*/ models.CommentTypeStartTracking,
- /*13*/ models.CommentTypeStopTracking,
- /*14*/ models.CommentTypeAddTimeManual,
- /*15*/ models.CommentTypeCancelTracking,
- /*26*/ models.CommentTypeDeleteTimeManual,
+ /*12*/ issues_model.CommentTypeStartTracking,
+ /*13*/ issues_model.CommentTypeStopTracking,
+ /*14*/ issues_model.CommentTypeAddTimeManual,
+ /*15*/ issues_model.CommentTypeCancelTracking,
+ /*26*/ issues_model.CommentTypeDeleteTimeManual,
},
"deadline": {
- /*16*/ models.CommentTypeAddedDeadline,
- /*17*/ models.CommentTypeModifiedDeadline,
- /*18*/ models.CommentTypeRemovedDeadline,
+ /*16*/ issues_model.CommentTypeAddedDeadline,
+ /*17*/ issues_model.CommentTypeModifiedDeadline,
+ /*18*/ issues_model.CommentTypeRemovedDeadline,
},
"dependency": {
- /*19*/ models.CommentTypeAddDependency,
- /*20*/ models.CommentTypeRemoveDependency,
+ /*19*/ issues_model.CommentTypeAddDependency,
+ /*20*/ issues_model.CommentTypeRemoveDependency,
},
"lock": {
- /*23*/ models.CommentTypeLock,
- /*24*/ models.CommentTypeUnlock,
+ /*23*/ issues_model.CommentTypeLock,
+ /*24*/ issues_model.CommentTypeUnlock,
},
"review_request": {
- /*27*/ models.CommentTypeReviewRequest,
+ /*27*/ issues_model.CommentTypeReviewRequest,
},
"pull_request_push": {
- /*29*/ models.CommentTypePullRequestPush,
+ /*29*/ issues_model.CommentTypePullRequestPush,
},
"project": {
- /*30*/ models.CommentTypeProject,
- /*31*/ models.CommentTypeProjectBoard,
+ /*30*/ issues_model.CommentTypeProject,
+ /*31*/ issues_model.CommentTypeProjectBoard,
},
"issue_ref": {
- /*33*/ models.CommentTypeChangeIssueRef,
+ /*33*/ issues_model.CommentTypeChangeIssueRef,
},
}
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index e56c2de8fa..97daadbc67 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -20,9 +20,9 @@ import (
"strings"
"time"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
+ issues_model "code.gitea.io/gitea/models/issues"
pull_model "code.gitea.io/gitea/models/pull"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/analyze"
@@ -82,7 +82,7 @@ type DiffLine struct {
Match int
Type DiffLineType
Content string
- Comments []*models.Comment
+ Comments []*issues_model.Comment
SectionInfo *DiffLineSectionInfo
}
@@ -704,8 +704,8 @@ type Diff struct {
}
// LoadComments loads comments into each line
-func (diff *Diff) LoadComments(ctx context.Context, issue *models.Issue, currentUser *user_model.User) error {
- allComments, err := models.FetchCodeComments(ctx, issue, currentUser)
+func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User) error {
+ allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser)
if err != nil {
return err
}
@@ -1520,7 +1520,7 @@ func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff
// SyncAndGetUserSpecificDiff is like GetDiff, except that user specific data such as which files the given user has already viewed on the given PR will also be set
// Additionally, the database asynchronously is updated if files have changed since the last review
-func SyncAndGetUserSpecificDiff(ctx context.Context, userID int64, pull *models.PullRequest, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error) {
+func SyncAndGetUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.PullRequest, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error) {
diff, err := GetDiff(gitRepo, opts, files...)
if err != nil {
return nil, err
@@ -1583,7 +1583,7 @@ outer:
}
// CommentAsDiff returns c.Patch as *Diff
-func CommentAsDiff(c *models.Comment) (*Diff, error) {
+func CommentAsDiff(c *issues_model.Comment) (*Diff, error) {
diff, err := ParsePatch(setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(c.Patch), "")
if err != nil {
@@ -1601,7 +1601,7 @@ func CommentAsDiff(c *models.Comment) (*Diff, error) {
}
// CommentMustAsDiff executes AsDiff and logs the error instead of returning
-func CommentMustAsDiff(c *models.Comment) *Diff {
+func CommentMustAsDiff(c *issues_model.Comment) *Diff {
if c == nil {
return nil
}
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go
index 3457785e5d..caca0e91d8 100644
--- a/services/gitdiff/gitdiff_test.go
+++ b/services/gitdiff/gitdiff_test.go
@@ -12,8 +12,8 @@ import (
"strings"
"testing"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
@@ -669,7 +669,7 @@ func setupDefaultDiff() *Diff {
func TestDiff_LoadComments(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}).(*issues_model.Issue)
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User)
diff := setupDefaultDiff()
assert.NoError(t, diff.LoadComments(db.DefaultContext, issue, user))
@@ -678,15 +678,15 @@ func TestDiff_LoadComments(t *testing.T) {
func TestDiffLine_CanComment(t *testing.T) {
assert.False(t, (&DiffLine{Type: DiffLineSection}).CanComment())
- assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*models.Comment{{Content: "bla"}}}).CanComment())
+ assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment())
assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment())
assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())
assert.True(t, (&DiffLine{Type: DiffLinePlain}).CanComment())
}
func TestDiffLine_GetCommentSide(t *testing.T) {
- assert.Equal(t, "previous", (&DiffLine{Comments: []*models.Comment{{Line: -3}}}).GetCommentSide())
- assert.Equal(t, "proposed", (&DiffLine{Comments: []*models.Comment{{Line: 3}}}).GetCommentSide())
+ assert.Equal(t, "previous", (&DiffLine{Comments: []*issues_model.Comment{{Line: -3}}}).GetCommentSide())
+ assert.Equal(t, "proposed", (&DiffLine{Comments: []*issues_model.Comment{{Line: 3}}}).GetCommentSide())
}
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
diff --git a/services/gitdiff/main_test.go b/services/gitdiff/main_test.go
index d4d9364ebf..17d0da6276 100644
--- a/services/gitdiff/main_test.go
+++ b/services/gitdiff/main_test.go
@@ -8,6 +8,7 @@ import (
"path/filepath"
"testing"
+ _ "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/unittest"
)
diff --git a/services/issue/assignee.go b/services/issue/assignee.go
index 8cad03351c..7c00f472dd 100644
--- a/services/issue/assignee.go
+++ b/services/issue/assignee.go
@@ -7,8 +7,8 @@ package issue
import (
"context"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
access_model "code.gitea.io/gitea/models/perm/access"
@@ -19,7 +19,7 @@ import (
)
// DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
-func DeleteNotPassedAssignee(issue *models.Issue, doer *user_model.User, assignees []*user_model.User) (err error) {
+func DeleteNotPassedAssignee(issue *issues_model.Issue, doer *user_model.User, assignees []*user_model.User) (err error) {
var found bool
oriAssignes := make([]*user_model.User, len(issue.Assignees))
_ = copy(oriAssignes, issue.Assignees)
@@ -45,8 +45,8 @@ func DeleteNotPassedAssignee(issue *models.Issue, doer *user_model.User, assigne
}
// ToggleAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
-func ToggleAssignee(issue *models.Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *models.Comment, err error) {
- removed, comment, err = models.ToggleIssueAssignee(issue, doer, assigneeID)
+func ToggleAssignee(issue *issues_model.Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *issues_model.Comment, err error) {
+ removed, comment, err = issues_model.ToggleIssueAssignee(issue, doer, assigneeID)
if err != nil {
return
}
@@ -63,11 +63,11 @@ func ToggleAssignee(issue *models.Issue, doer *user_model.User, assigneeID int64
}
// ReviewRequest add or remove a review request from a user for this PR, and make comment for it.
-func ReviewRequest(issue *models.Issue, doer, reviewer *user_model.User, isAdd bool) (comment *models.Comment, err error) {
+func ReviewRequest(issue *issues_model.Issue, doer, reviewer *user_model.User, isAdd bool) (comment *issues_model.Comment, err error) {
if isAdd {
- comment, err = models.AddReviewRequest(issue, reviewer, doer)
+ comment, err = issues_model.AddReviewRequest(issue, reviewer, doer)
} else {
- comment, err = models.RemoveReviewRequest(issue, reviewer, doer)
+ comment, err = issues_model.RemoveReviewRequest(issue, reviewer, doer)
}
if err != nil {
@@ -82,16 +82,16 @@ func ReviewRequest(issue *models.Issue, doer, reviewer *user_model.User, isAdd b
}
// IsValidReviewRequest Check permission for ReviewRequest
-func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User, isAdd bool, issue *models.Issue, permDoer *access_model.Permission) error {
+func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User, isAdd bool, issue *issues_model.Issue, permDoer *access_model.Permission) error {
if reviewer.IsOrganization() {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Organization can't be added as reviewer",
UserID: doer.ID,
RepoID: issue.Repo.ID,
}
}
if doer.IsOrganization() {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Organization can't be doer to add reviewer",
UserID: doer.ID,
RepoID: issue.Repo.ID,
@@ -111,8 +111,8 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User,
}
}
- lastreview, err := models.GetReviewByIssueIDAndUserID(ctx, issue.ID, reviewer.ID)
- if err != nil && !models.IsErrReviewNotExist(err) {
+ lastreview, err := issues_model.GetReviewByIssueIDAndUserID(ctx, issue.ID, reviewer.ID)
+ if err != nil && !issues_model.IsErrReviewNotExist(err) {
return err
}
@@ -120,25 +120,25 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User,
if isAdd {
pemResult = permReviewer.CanAccessAny(perm.AccessModeRead, unit.TypePullRequests)
if !pemResult {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Reviewer can't read",
UserID: doer.ID,
RepoID: issue.Repo.ID,
}
}
- if doer.ID == issue.PosterID && issue.OriginalAuthorID == 0 && lastreview != nil && lastreview.Type != models.ReviewTypeRequest {
+ if doer.ID == issue.PosterID && issue.OriginalAuthorID == 0 && lastreview != nil && lastreview.Type != issues_model.ReviewTypeRequest {
return nil
}
pemResult = permDoer.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests)
if !pemResult {
- pemResult, err = models.IsOfficialReviewer(ctx, issue, doer)
+ pemResult, err = issues_model.IsOfficialReviewer(ctx, issue, doer)
if err != nil {
return err
}
if !pemResult {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Doer can't choose reviewer",
UserID: doer.ID,
RepoID: issue.Repo.ID,
@@ -147,20 +147,20 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User,
}
if reviewer.ID == issue.PosterID && issue.OriginalAuthorID == 0 {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "poster of pr can't be reviewer",
UserID: doer.ID,
RepoID: issue.Repo.ID,
}
}
} else {
- if lastreview != nil && lastreview.Type == models.ReviewTypeRequest && lastreview.ReviewerID == doer.ID {
+ if lastreview != nil && lastreview.Type == issues_model.ReviewTypeRequest && lastreview.ReviewerID == doer.ID {
return nil
}
pemResult = permDoer.IsAdmin()
if !pemResult {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Doer is not admin",
UserID: doer.ID,
RepoID: issue.Repo.ID,
@@ -172,9 +172,9 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User,
}
// IsValidTeamReviewRequest Check permission for ReviewRequest Team
-func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team, doer *user_model.User, isAdd bool, issue *models.Issue) error {
+func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team, doer *user_model.User, isAdd bool, issue *issues_model.Issue) error {
if doer.IsOrganization() {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Organization can't be doer to add reviewer",
UserID: doer.ID,
RepoID: issue.Repo.ID,
@@ -192,7 +192,7 @@ func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team,
hasTeam := organization.HasTeamRepo(ctx, reviewer.OrgID, reviewer.ID, issue.RepoID)
if !hasTeam {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Reviewing team can't read repo",
UserID: doer.ID,
RepoID: issue.Repo.ID,
@@ -202,13 +202,13 @@ func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team,
doerCanWrite := permission.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests)
if !doerCanWrite {
- official, err := models.IsOfficialReviewer(ctx, issue, doer)
+ official, err := issues_model.IsOfficialReviewer(ctx, issue, doer)
if err != nil {
log.Error("Unable to Check if IsOfficialReviewer for %-v in %-v#%d", doer, issue.Repo, issue.Index)
return err
}
if !official {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Doer can't choose reviewer",
UserID: doer.ID,
RepoID: issue.Repo.ID,
@@ -216,7 +216,7 @@ func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team,
}
}
} else if !permission.IsAdmin() {
- return models.ErrNotValidReviewRequest{
+ return issues_model.ErrNotValidReviewRequest{
Reason: "Only admin users can remove team requests. Doer is not admin",
UserID: doer.ID,
RepoID: issue.Repo.ID,
@@ -227,11 +227,11 @@ func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team,
}
// TeamReviewRequest add or remove a review request from a team for this PR, and make comment for it.
-func TeamReviewRequest(issue *models.Issue, doer *user_model.User, reviewer *organization.Team, isAdd bool) (comment *models.Comment, err error) {
+func TeamReviewRequest(issue *issues_model.Issue, doer *user_model.User, reviewer *organization.Team, isAdd bool) (comment *issues_model.Comment, err error) {
if isAdd {
- comment, err = models.AddTeamReviewRequest(issue, reviewer, doer)
+ comment, err = issues_model.AddTeamReviewRequest(issue, reviewer, doer)
} else {
- comment, err = models.RemoveTeamReviewRequest(issue, reviewer, doer)
+ comment, err = issues_model.RemoveTeamReviewRequest(issue, reviewer, doer)
}
if err != nil {
diff --git a/services/issue/assignee_test.go b/services/issue/assignee_test.go
index ff4d7029eb..5c8b822499 100644
--- a/services/issue/assignee_test.go
+++ b/services/issue/assignee_test.go
@@ -7,8 +7,8 @@ package issue
import (
"testing"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -19,7 +19,7 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
// Fake issue with assignees
- issue, err := models.GetIssueWithAttrsByID(1)
+ issue, err := issues_model.GetIssueWithAttrsByID(1)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(issue.Assignees))
@@ -27,7 +27,7 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
assert.NoError(t, err)
// Check if he got removed
- isAssigned, err := models.IsUserAssignedToIssue(db.DefaultContext, issue, user1)
+ isAssigned, err := issues_model.IsUserAssignedToIssue(db.DefaultContext, issue, user1)
assert.NoError(t, err)
assert.True(t, isAssigned)
diff --git a/services/issue/commit.go b/services/issue/commit.go
index 5140eebed1..1053a81162 100644
--- a/services/issue/commit.go
+++ b/services/issue/commit.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -76,22 +77,22 @@ func timeLogToAmount(str string) int64 {
return a
}
-func issueAddTime(issue *models.Issue, doer *user_model.User, time time.Time, timeLog string) error {
+func issueAddTime(issue *issues_model.Issue, doer *user_model.User, time time.Time, timeLog string) error {
amount := timeLogToAmount(timeLog)
if amount == 0 {
return nil
}
- _, err := models.AddTime(doer, issue, amount, time)
+ _, err := issues_model.AddTime(doer, issue, amount, time)
return err
}
// getIssueFromRef returns the issue referenced by a ref. Returns a nil *Issue
// if the provided ref references a non-existent issue.
-func getIssueFromRef(repo *repo_model.Repository, index int64) (*models.Issue, error) {
- issue, err := models.GetIssueByIndex(repo.ID, index)
+func getIssueFromRef(repo *repo_model.Repository, index int64) (*issues_model.Issue, error) {
+ issue, err := issues_model.GetIssueByIndex(repo.ID, index)
if err != nil {
- if models.IsErrIssueNotExist(err) {
+ if issues_model.IsErrIssueNotExist(err) {
return nil, nil
}
return nil, err
@@ -112,7 +113,7 @@ func UpdateIssuesCommit(doer *user_model.User, repo *repo_model.Repository, comm
refMarked := make(map[markKey]bool)
var refRepo *repo_model.Repository
- var refIssue *models.Issue
+ var refIssue *issues_model.Issue
var err error
for _, ref := range references.FindAllIssueReferences(c.Message) {
@@ -153,7 +154,7 @@ func UpdateIssuesCommit(doer *user_model.User, repo *repo_model.Repository, comm
}
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, html.EscapeString(repo.Link()), html.EscapeString(url.PathEscape(c.Sha1)), html.EscapeString(strings.SplitN(c.Message, "\n", 2)[0]))
- if err = models.CreateRefComment(doer, refRepo, refIssue, message, c.Sha1); err != nil {
+ if err = issues_model.CreateRefComment(doer, refRepo, refIssue, message, c.Sha1); err != nil {
return err
}
diff --git a/services/issue/commit_test.go b/services/issue/commit_test.go
index 37283a7890..ce3f913627 100644
--- a/services/issue/commit_test.go
+++ b/services/issue/commit_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -50,16 +51,16 @@ func TestUpdateIssuesCommit(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
repo.Owner = user
- commentBean := &models.Comment{
- Type: models.CommentTypeCommitRef,
+ commentBean := &issues_model.Comment{
+ Type: issues_model.CommentTypeCommitRef,
CommitSHA: "abcdef1",
PosterID: user.ID,
IssueID: 1,
}
- issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
+ issueBean := &issues_model.Issue{RepoID: repo.ID, Index: 4}
unittest.AssertNotExistsBean(t, commentBean)
- unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
@@ -77,16 +78,16 @@ func TestUpdateIssuesCommit(t *testing.T) {
},
}
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository)
- commentBean = &models.Comment{
- Type: models.CommentTypeCommitRef,
+ commentBean = &issues_model.Comment{
+ Type: issues_model.CommentTypeCommitRef,
CommitSHA: "abcdef1",
PosterID: user.ID,
IssueID: 6,
}
- issueBean = &models.Issue{RepoID: repo.ID, Index: 1}
+ issueBean = &issues_model.Issue{RepoID: repo.ID, Index: 1}
unittest.AssertNotExistsBean(t, commentBean)
- unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
@@ -103,16 +104,16 @@ func TestUpdateIssuesCommit(t *testing.T) {
},
}
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository)
- commentBean = &models.Comment{
- Type: models.CommentTypeCommitRef,
+ commentBean = &issues_model.Comment{
+ Type: issues_model.CommentTypeCommitRef,
CommitSHA: "abcdef3",
PosterID: user.ID,
IssueID: 6,
}
- issueBean = &models.Issue{RepoID: repo.ID, Index: 1}
+ issueBean = &issues_model.Issue{RepoID: repo.ID, Index: 1}
unittest.AssertNotExistsBean(t, commentBean)
- unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
@@ -136,9 +137,9 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
repo.Owner = user
- issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
+ issueBean := &issues_model.Issue{RepoID: repo.ID, Index: 4}
- unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
unittest.CheckConsistencyFor(t, &models.Action{})
@@ -161,14 +162,14 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
}
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
- commentBean := &models.Comment{
- Type: models.CommentTypeCommitRef,
+ commentBean := &issues_model.Comment{
+ Type: issues_model.CommentTypeCommitRef,
CommitSHA: "abcdef1",
PosterID: user.ID,
IssueID: 7,
}
- issueBean := &models.Issue{RepoID: repo.ID, Index: 2, ID: 7}
+ issueBean := &issues_model.Issue{RepoID: repo.ID, Index: 2, ID: 7}
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
@@ -196,14 +197,14 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
}
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
- commentBean := &models.Comment{
- Type: models.CommentTypeCommitRef,
+ commentBean := &issues_model.Comment{
+ Type: issues_model.CommentTypeCommitRef,
CommitSHA: "abcdef1",
PosterID: user.ID,
IssueID: 1,
}
- issueBean := &models.Issue{RepoID: 1, Index: 1, ID: 1}
+ issueBean := &issues_model.Issue{RepoID: 1, Index: 1, ID: 1}
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
@@ -231,14 +232,14 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
}
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
- commentBean := &models.Comment{
- Type: models.CommentTypeCommitRef,
+ commentBean := &issues_model.Comment{
+ Type: issues_model.CommentTypeCommitRef,
CommitSHA: "abcdef1",
PosterID: user.ID,
IssueID: 1,
}
- issueBean := &models.Issue{RepoID: 1, Index: 1, ID: 1}
+ issueBean := &issues_model.Issue{RepoID: 1, Index: 1, ID: 1}
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
@@ -274,20 +275,20 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
}
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 6}).(*repo_model.Repository)
- commentBean := &models.Comment{
- Type: models.CommentTypeCommitRef,
+ commentBean := &issues_model.Comment{
+ Type: issues_model.CommentTypeCommitRef,
CommitSHA: "abcdef3",
PosterID: user.ID,
IssueID: 6,
}
- commentBean2 := &models.Comment{
- Type: models.CommentTypeCommitRef,
+ commentBean2 := &issues_model.Comment{
+ Type: issues_model.CommentTypeCommitRef,
CommitSHA: "abcdef4",
PosterID: user.ID,
IssueID: 6,
}
- issueBean := &models.Issue{RepoID: 3, Index: 1, ID: 6}
+ issueBean := &issues_model.Issue{RepoID: 3, Index: 1, ID: 6}
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, commentBean2)
diff --git a/services/issue/content.go b/services/issue/content.go
index a60878479b..6f493892f4 100644
--- a/services/issue/content.go
+++ b/services/issue/content.go
@@ -5,16 +5,16 @@
package issue
import (
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
)
// ChangeContent changes issue content, as the given user.
-func ChangeContent(issue *models.Issue, doer *user_model.User, content string) (err error) {
+func ChangeContent(issue *issues_model.Issue, doer *user_model.User, content string) (err error) {
oldContent := issue.Content
- if err := models.ChangeIssueContent(issue, doer, content); err != nil {
+ if err := issues_model.ChangeIssueContent(issue, doer, content); err != nil {
return err
}
diff --git a/services/issue/issue.go b/services/issue/issue.go
index 78a486727a..ded281e209 100644
--- a/services/issue/issue.go
+++ b/services/issue/issue.go
@@ -8,18 +8,22 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ admin_model "code.gitea.io/gitea/models/admin"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
+ project_model "code.gitea.io/gitea/models/project"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/notification"
+ "code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util"
)
// NewIssue creates new issue with labels for repository.
-func NewIssue(repo *repo_model.Repository, issue *models.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error {
- if err := models.NewIssue(repo, issue, labelIDs, uuids); err != nil {
+func NewIssue(repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, assigneeIDs []int64) error {
+ if err := issues_model.NewIssue(repo, issue, labelIDs, uuids); err != nil {
return err
}
@@ -29,7 +33,7 @@ func NewIssue(repo *repo_model.Repository, issue *models.Issue, labelIDs []int64
}
}
- mentions, err := models.FindAndUpdateIssueMentions(db.DefaultContext, issue, issue.Poster, issue.Content)
+ mentions, err := issues_model.FindAndUpdateIssueMentions(db.DefaultContext, issue, issue.Poster, issue.Content)
if err != nil {
return err
}
@@ -46,11 +50,11 @@ func NewIssue(repo *repo_model.Repository, issue *models.Issue, labelIDs []int64
}
// ChangeTitle changes the title of this issue, as the given user.
-func ChangeTitle(issue *models.Issue, doer *user_model.User, title string) (err error) {
+func ChangeTitle(issue *issues_model.Issue, doer *user_model.User, title string) (err error) {
oldTitle := issue.Title
issue.Title = title
- if err = models.ChangeIssueTitle(issue, doer, oldTitle); err != nil {
+ if err = issues_model.ChangeIssueTitle(issue, doer, oldTitle); err != nil {
return
}
@@ -60,11 +64,11 @@ func ChangeTitle(issue *models.Issue, doer *user_model.User, title string) (err
}
// ChangeIssueRef changes the branch of this issue, as the given user.
-func ChangeIssueRef(issue *models.Issue, doer *user_model.User, ref string) error {
+func ChangeIssueRef(issue *issues_model.Issue, doer *user_model.User, ref string) error {
oldRef := issue.Ref
issue.Ref = ref
- if err := models.ChangeIssueRef(issue, doer, oldRef); err != nil {
+ if err := issues_model.ChangeIssueRef(issue, doer, oldRef); err != nil {
return err
}
@@ -79,7 +83,7 @@ func ChangeIssueRef(issue *models.Issue, doer *user_model.User, ref string) erro
// "assignees" (array): Logins for Users to assign to this issue.
// Pass one or more user logins to replace the set of assignees on this Issue.
// Send an empty array ([]) to clear all assignees from the Issue.
-func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees []string, doer *user_model.User) (err error) {
+func UpdateAssignees(issue *issues_model.Issue, oneAssignee string, multipleAssignees []string, doer *user_model.User) (err error) {
var allNewAssignees []*user_model.User
// Keep the old assignee thingy for compatibility reasons
@@ -129,9 +133,9 @@ func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees
}
// DeleteIssue deletes an issue
-func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *models.Issue) error {
+func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue) error {
// load issue before deleting it
- if err := issue.LoadAttributes(); err != nil {
+ if err := issue.LoadAttributes(db.DefaultContext); err != nil {
return err
}
if err := issue.LoadPullRequest(); err != nil {
@@ -139,7 +143,7 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *models.I
}
// delete entries in database
- if err := models.DeleteIssue(issue); err != nil {
+ if err := deleteIssue(issue); err != nil {
return err
}
@@ -157,14 +161,14 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *models.I
// AddAssigneeIfNotAssigned adds an assignee only if he isn't already assigned to the issue.
// Also checks for access of assigned user
-func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assigneeID int64) (err error) {
+func AddAssigneeIfNotAssigned(issue *issues_model.Issue, doer *user_model.User, assigneeID int64) (err error) {
assignee, err := user_model.GetUserByID(assigneeID)
if err != nil {
return err
}
// Check if the user is already assigned
- isAssigned, err := models.IsUserAssignedToIssue(db.DefaultContext, issue, assignee)
+ isAssigned, err := issues_model.IsUserAssignedToIssue(db.DefaultContext, issue, assignee)
if err != nil {
return err
}
@@ -178,7 +182,7 @@ func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assign
return err
}
if !valid {
- return models.ErrUserDoesNotHaveAccessToRepo{UserID: assigneeID, RepoName: issue.Repo.Name}
+ return repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: assigneeID, RepoName: issue.Repo.Name}
}
_, _, err = ToggleAssignee(issue, doer, assigneeID)
@@ -191,7 +195,7 @@ func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assign
// GetRefEndNamesAndURLs retrieves the ref end names (e.g. refs/heads/branch-name -> branch-name)
// and their respective URLs.
-func GetRefEndNamesAndURLs(issues []*models.Issue, repoLink string) (map[int64]string, map[int64]string) {
+func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[int64]string, map[int64]string) {
issueRefEndNames := make(map[int64]string, len(issues))
issueRefURLs := make(map[int64]string, len(issues))
for _, issue := range issues {
@@ -202,3 +206,77 @@ func GetRefEndNamesAndURLs(issues []*models.Issue, repoLink string) (map[int64]s
}
return issueRefEndNames, issueRefURLs
}
+
+// deleteIssue deletes the issue
+func deleteIssue(issue *issues_model.Issue) error {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
+ return err
+ }
+ defer committer.Close()
+
+ e := db.GetEngine(ctx)
+ if _, err := e.ID(issue.ID).NoAutoCondition().Delete(issue); err != nil {
+ return err
+ }
+
+ if err := repo_model.UpdateRepoIssueNumbers(ctx, issue.RepoID, issue.IsPull, issue.IsClosed); err != nil {
+ return err
+ }
+
+ if err := models.DeleteIssueActions(ctx, issue.RepoID, issue.ID); err != nil {
+ return err
+ }
+
+ // find attachments related to this issue and remove them
+ if err := issue.LoadAttributes(ctx); err != nil {
+ return err
+ }
+
+ for i := range issue.Attachments {
+ admin_model.RemoveStorageWithNotice(ctx, storage.Attachments, "Delete issue attachment", issue.Attachments[i].RelativePath())
+ }
+
+ // delete all database data still assigned to this issue
+ if err := issues_model.DeleteInIssue(ctx, issue.ID,
+ &issues_model.ContentHistory{},
+ &issues_model.Comment{},
+ &issues_model.IssueLabel{},
+ &issues_model.IssueDependency{},
+ &issues_model.IssueAssignees{},
+ &issues_model.IssueUser{},
+ &models.Notification{},
+ &issues_model.Reaction{},
+ &issues_model.IssueWatch{},
+ &issues_model.Stopwatch{},
+ &issues_model.TrackedTime{},
+ &project_model.ProjectIssue{},
+ &repo_model.Attachment{},
+ &issues_model.PullRequest{},
+ ); err != nil {
+ return err
+ }
+
+ // References to this issue in other issues
+ if _, err := db.DeleteByBean(ctx, &issues_model.Comment{
+ RefIssueID: issue.ID,
+ }); err != nil {
+ return err
+ }
+
+ // Delete dependencies for issues in other repositories
+ if _, err := db.DeleteByBean(ctx, &issues_model.IssueDependency{
+ DependencyID: issue.ID,
+ }); err != nil {
+ return err
+ }
+
+ // delete from dependent issues
+ if _, err := db.DeleteByBean(ctx, &issues_model.Comment{
+ DependentIssueID: issue.ID,
+ }); err != nil {
+ return err
+ }
+
+ return committer.Commit()
+}
diff --git a/services/issue/issue_test.go b/services/issue/issue_test.go
index caae773616..20f3a3296c 100644
--- a/services/issue/issue_test.go
+++ b/services/issue/issue_test.go
@@ -7,13 +7,17 @@ package issue
import (
"testing"
- "code.gitea.io/gitea/models"
+ "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/unittest"
+ user_model "code.gitea.io/gitea/models/user"
"github.com/stretchr/testify/assert"
)
func TestGetRefEndNamesAndURLs(t *testing.T) {
- issues := []*models.Issue{
+ issues := []*issues_model.Issue{
{ID: 1, Ref: "refs/heads/branch1"},
{ID: 2, Ref: "refs/tags/tag1"},
{ID: 3, Ref: "c0ffee"},
@@ -28,3 +32,56 @@ func TestGetRefEndNamesAndURLs(t *testing.T) {
3: repoLink + "/src/commit/c0ffee",
}, urls)
}
+
+func TestIssue_DeleteIssue(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 5, len(issueIDs))
+
+ issue := &issues_model.Issue{
+ RepoID: 1,
+ ID: issueIDs[2],
+ }
+
+ err = deleteIssue(issue)
+ assert.NoError(t, err)
+ issueIDs, err = issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 4, len(issueIDs))
+
+ // check attachment removal
+ attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 4)
+ assert.NoError(t, err)
+ issue, err = issues_model.GetIssueByID(db.DefaultContext, 4)
+ assert.NoError(t, err)
+ err = deleteIssue(issue)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 2, len(attachments))
+ for i := range attachments {
+ attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attachments[i].UUID)
+ assert.Error(t, err)
+ assert.True(t, repo_model.IsErrAttachmentNotExist(err))
+ assert.Nil(t, attachment)
+ }
+
+ // check issue dependencies
+ user, err := user_model.GetUserByID(1)
+ assert.NoError(t, err)
+ issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
+ assert.NoError(t, err)
+ issue2, err := issues_model.GetIssueByID(db.DefaultContext, 2)
+ assert.NoError(t, err)
+ err = issues_model.CreateIssueDependency(user, issue1, issue2)
+ assert.NoError(t, err)
+ left, err := issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
+ assert.NoError(t, err)
+ assert.False(t, left)
+
+ err = deleteIssue(issue2)
+ assert.NoError(t, err)
+ left, err = issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
+ assert.NoError(t, err)
+ assert.True(t, left)
+}
diff --git a/services/issue/label.go b/services/issue/label.go
index 289466f604..bc5f9b910e 100644
--- a/services/issue/label.go
+++ b/services/issue/label.go
@@ -5,16 +5,16 @@
package issue
import (
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
)
// ClearLabels clears all of an issue's labels
-func ClearLabels(issue *models.Issue, doer *user_model.User) (err error) {
- if err = models.ClearIssueLabels(issue, doer); err != nil {
+func ClearLabels(issue *issues_model.Issue, doer *user_model.User) (err error) {
+ if err = issues_model.ClearIssueLabels(issue, doer); err != nil {
return
}
@@ -24,18 +24,18 @@ func ClearLabels(issue *models.Issue, doer *user_model.User) (err error) {
}
// AddLabel adds a new label to the issue.
-func AddLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error {
- if err := models.NewIssueLabel(issue, label, doer); err != nil {
+func AddLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error {
+ if err := issues_model.NewIssueLabel(issue, label, doer); err != nil {
return err
}
- notification.NotifyIssueChangeLabels(doer, issue, []*models.Label{label}, nil)
+ notification.NotifyIssueChangeLabels(doer, issue, []*issues_model.Label{label}, nil)
return nil
}
// AddLabels adds a list of new labels to the issue.
-func AddLabels(issue *models.Issue, doer *user_model.User, labels []*models.Label) error {
- if err := models.NewIssueLabels(issue, labels, doer); err != nil {
+func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error {
+ if err := issues_model.NewIssueLabels(issue, labels, doer); err != nil {
return err
}
@@ -44,7 +44,7 @@ func AddLabels(issue *models.Issue, doer *user_model.User, labels []*models.Labe
}
// RemoveLabel removes a label from issue by given ID.
-func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error {
+func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error {
ctx, committer, err := db.TxContext()
if err != nil {
return err
@@ -61,12 +61,12 @@ func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label
}
if !perm.CanWriteIssuesOrPulls(issue.IsPull) {
if label.OrgID > 0 {
- return models.ErrOrgLabelNotExist{}
+ return issues_model.ErrOrgLabelNotExist{}
}
- return models.ErrRepoLabelNotExist{}
+ return issues_model.ErrRepoLabelNotExist{}
}
- if err := models.DeleteIssueLabel(ctx, issue, label, doer); err != nil {
+ if err := issues_model.DeleteIssueLabel(ctx, issue, label, doer); err != nil {
return err
}
@@ -74,18 +74,18 @@ func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label
return err
}
- notification.NotifyIssueChangeLabels(doer, issue, nil, []*models.Label{label})
+ notification.NotifyIssueChangeLabels(doer, issue, nil, []*issues_model.Label{label})
return nil
}
// ReplaceLabels removes all current labels and add new labels to the issue.
-func ReplaceLabels(issue *models.Issue, doer *user_model.User, labels []*models.Label) error {
- old, err := models.GetLabelsByIssueID(db.DefaultContext, issue.ID)
+func ReplaceLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error {
+ old, err := issues_model.GetLabelsByIssueID(db.DefaultContext, issue.ID)
if err != nil {
return err
}
- if err := models.ReplaceIssueLabels(issue, labels, doer); err != nil {
+ if err := issues_model.ReplaceIssueLabels(issue, labels, doer); err != nil {
return err
}
diff --git a/services/issue/label_test.go b/services/issue/label_test.go
index 73e30e894f..120c9ea4f1 100644
--- a/services/issue/label_test.go
+++ b/services/issue/label_test.go
@@ -7,7 +7,7 @@ package issue
import (
"testing"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -27,15 +27,15 @@ func TestIssue_AddLabels(t *testing.T) {
}
for _, test := range tests {
assert.NoError(t, unittest.PrepareTestDatabase())
- issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
- labels := make([]*models.Label, len(test.labelIDs))
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID}).(*issues_model.Issue)
+ labels := make([]*issues_model.Label, len(test.labelIDs))
for i, labelID := range test.labelIDs {
- labels[i] = unittest.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
+ labels[i] = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID}).(*issues_model.Label)
}
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User)
assert.NoError(t, AddLabels(issue, doer, labels))
for _, labelID := range test.labelIDs {
- unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
+ unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: labelID})
}
}
}
@@ -53,10 +53,10 @@ func TestIssue_AddLabel(t *testing.T) {
}
for _, test := range tests {
assert.NoError(t, unittest.PrepareTestDatabase())
- issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
- label := unittest.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID}).(*issues_model.Issue)
+ label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: test.labelID}).(*issues_model.Label)
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID}).(*user_model.User)
assert.NoError(t, AddLabel(issue, doer, label))
- unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
+ unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
}
}
diff --git a/services/issue/milestone.go b/services/issue/milestone.go
index 287f8ae285..af337c3f14 100644
--- a/services/issue/milestone.go
+++ b/services/issue/milestone.go
@@ -8,15 +8,14 @@ import (
"context"
"fmt"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/notification"
)
-func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *models.Issue, oldMilestoneID int64) error {
- if err := models.UpdateIssueCols(ctx, issue, "milestone_id"); err != nil {
+func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error {
+ if err := issues_model.UpdateIssueCols(ctx, issue, "milestone_id"); err != nil {
return err
}
@@ -37,15 +36,15 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *mo
return err
}
- opts := &models.CreateCommentOptions{
- Type: models.CommentTypeMilestone,
+ opts := &issues_model.CreateCommentOptions{
+ Type: issues_model.CommentTypeMilestone,
Doer: doer,
Repo: issue.Repo,
Issue: issue,
OldMilestoneID: oldMilestoneID,
MilestoneID: issue.MilestoneID,
}
- if _, err := models.CreateCommentCtx(ctx, opts); err != nil {
+ if _, err := issues_model.CreateCommentCtx(ctx, opts); err != nil {
return err
}
}
@@ -54,7 +53,7 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *mo
}
// ChangeMilestoneAssign changes assignment of milestone for issue.
-func ChangeMilestoneAssign(issue *models.Issue, doer *user_model.User, oldMilestoneID int64) (err error) {
+func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, oldMilestoneID int64) (err error) {
ctx, committer, err := db.TxContext()
if err != nil {
return err
diff --git a/services/issue/milestone_test.go b/services/issue/milestone_test.go
index 80e37a8acd..d08b1ae8c7 100644
--- a/services/issue/milestone_test.go
+++ b/services/issue/milestone_test.go
@@ -7,7 +7,6 @@ package issue
import (
"testing"
- "code.gitea.io/gitea/models"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -17,7 +16,7 @@ import (
func TestChangeMilestoneAssign(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{RepoID: 1}).(*models.Issue)
+ issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: 1}).(*issues_model.Issue)
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
assert.NotNil(t, issue)
assert.NotNil(t, doer)
@@ -25,11 +24,11 @@ func TestChangeMilestoneAssign(t *testing.T) {
oldMilestoneID := issue.MilestoneID
issue.MilestoneID = 2
assert.NoError(t, ChangeMilestoneAssign(issue, doer, oldMilestoneID))
- unittest.AssertExistsAndLoadBean(t, &models.Comment{
+ unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{
IssueID: issue.ID,
- Type: models.CommentTypeMilestone,
+ Type: issues_model.CommentTypeMilestone,
MilestoneID: issue.MilestoneID,
OldMilestoneID: oldMilestoneID,
})
- unittest.CheckConsistencyFor(t, &issues_model.Milestone{}, &models.Issue{})
+ unittest.CheckConsistencyFor(t, &issues_model.Milestone{}, &issues_model.Issue{})
}
diff --git a/services/issue/status.go b/services/issue/status.go
index d2b4fc303e..0da5c88762 100644
--- a/services/issue/status.go
+++ b/services/issue/status.go
@@ -7,25 +7,25 @@ package issue
import (
"context"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
)
// ChangeStatus changes issue status to open or closed.
-func ChangeStatus(issue *models.Issue, doer *user_model.User, closed bool) error {
+func ChangeStatus(issue *issues_model.Issue, doer *user_model.User, closed bool) error {
return changeStatusCtx(db.DefaultContext, issue, doer, closed)
}
// changeStatusCtx changes issue status to open or closed.
// TODO: if context is not db.DefaultContext we get a deadlock!!!
-func changeStatusCtx(ctx context.Context, issue *models.Issue, doer *user_model.User, closed bool) error {
- comment, err := models.ChangeIssueStatus(ctx, issue, doer, closed)
+func changeStatusCtx(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, closed bool) error {
+ comment, err := issues_model.ChangeIssueStatus(ctx, issue, doer, closed)
if err != nil {
- if models.IsErrDependenciesLeft(err) && closed {
- if err := models.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil {
+ if issues_model.IsErrDependenciesLeft(err) && closed {
+ if err := issues_model.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil {
log.Error("Unable to stop stopwatch for issue[%d]#%d: %v", issue.ID, issue.Index, err)
}
}
@@ -33,7 +33,7 @@ func changeStatusCtx(ctx context.Context, issue *models.Issue, doer *user_model.
}
if closed {
- if err := models.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil {
+ if err := issues_model.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil {
return err
}
}
diff --git a/services/mailer/mail.go b/services/mailer/mail.go
index bdd7e25cab..81cfb2e31a 100644
--- a/services/mailer/mail.go
+++ b/services/mailer/mail.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
@@ -220,10 +221,10 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
prefix string
// Fall back subject for bad templates, make sure subject is never empty
fallback string
- reviewComments []*models.Comment
+ reviewComments []*issues_model.Comment
)
- commentType := models.CommentTypeComment
+ commentType := issues_model.CommentTypeComment
if ctx.Comment != nil {
commentType = ctx.Comment.Type
link = ctx.Issue.HTMLURL() + "#" + ctx.Comment.HashTag()
@@ -231,7 +232,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
link = ctx.Issue.HTMLURL()
}
- reviewType := models.ReviewTypeComment
+ reviewType := issues_model.ReviewTypeComment
if ctx.Comment != nil && ctx.Comment.Review != nil {
reviewType = ctx.Comment.Review.Type
}
@@ -254,7 +255,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
fallback = prefix + fallbackMailSubject(ctx.Issue)
if ctx.Comment != nil && ctx.Comment.Review != nil {
- reviewComments = make([]*models.Comment, 0, 10)
+ reviewComments = make([]*issues_model.Comment, 0, 10)
for _, lines := range ctx.Comment.Review.CodeComments {
for _, comments := range lines {
reviewComments = append(reviewComments, comments...)
@@ -328,7 +329,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
return msgs, nil
}
-func createReference(issue *models.Issue, comment *models.Comment, actionType models.ActionType) string {
+func createReference(issue *issues_model.Issue, comment *issues_model.Comment, actionType models.ActionType) string {
var path string
if issue.IsPull {
path = "pulls"
@@ -400,7 +401,7 @@ func sanitizeSubject(subject string) string {
}
// SendIssueAssignedMail composes and sends issue assigned email
-func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content string, comment *models.Comment, recipients []*user_model.User) error {
+func SendIssueAssignedMail(issue *issues_model.Issue, doer *user_model.User, content string, comment *issues_model.Comment, recipients []*user_model.User) error {
if setting.MailService == nil {
// No mail service configured
return nil
@@ -439,8 +440,8 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
// actionToTemplate returns the type and name of the action facing the user
// (slightly different from models.ActionType) and the name of the template to use (based on availability)
-func actionToTemplate(issue *models.Issue, actionType models.ActionType,
- commentType models.CommentType, reviewType models.ReviewType,
+func actionToTemplate(issue *issues_model.Issue, actionType models.ActionType,
+ commentType issues_model.CommentType, reviewType issues_model.ReviewType,
) (typeName, name, template string) {
if issue.IsPull {
typeName = "pull"
@@ -464,20 +465,20 @@ func actionToTemplate(issue *models.Issue, actionType models.ActionType,
name = "ready_for_review"
default:
switch commentType {
- case models.CommentTypeReview:
+ case issues_model.CommentTypeReview:
switch reviewType {
- case models.ReviewTypeApprove:
+ case issues_model.ReviewTypeApprove:
name = "approve"
- case models.ReviewTypeReject:
+ case issues_model.ReviewTypeReject:
name = "reject"
default:
name = "review"
}
- case models.CommentTypeCode:
+ case issues_model.CommentTypeCode:
name = "code"
- case models.CommentTypeAssignees:
+ case issues_model.CommentTypeAssignees:
name = "assigned"
- case models.CommentTypePullRequestPush:
+ case issues_model.CommentTypePullRequestPush:
name = "push"
default:
name = "default"
diff --git a/services/mailer/mail_comment.go b/services/mailer/mail_comment.go
index baecd2a101..95d11ae8a1 100644
--- a/services/mailer/mail_comment.go
+++ b/services/mailer/mail_comment.go
@@ -8,20 +8,21 @@ import (
"context"
"code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
// MailParticipantsComment sends new comment emails to repository watchers and mentioned people.
-func MailParticipantsComment(ctx context.Context, c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*user_model.User) error {
+func MailParticipantsComment(ctx context.Context, c *issues_model.Comment, opType models.ActionType, issue *issues_model.Issue, mentions []*user_model.User) error {
if setting.MailService == nil {
// No mail service configured
return nil
}
content := c.Content
- if c.Type == models.CommentTypePullRequestPush {
+ if c.Type == issues_model.CommentTypePullRequestPush {
content = ""
}
if err := mailIssueCommentToParticipants(
@@ -39,7 +40,7 @@ func MailParticipantsComment(ctx context.Context, c *models.Comment, opType mode
}
// MailMentionsComment sends email to users mentioned in a code comment
-func MailMentionsComment(ctx context.Context, pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) (err error) {
+func MailMentionsComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) (err error) {
if setting.MailService == nil {
// No mail service configured
return nil
diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go
index d479dd0d44..5c330f6e00 100644
--- a/services/mailer/mail_issue.go
+++ b/services/mailer/mail_issue.go
@@ -9,6 +9,7 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -16,17 +17,17 @@ import (
"code.gitea.io/gitea/modules/setting"
)
-func fallbackMailSubject(issue *models.Issue) string {
+func fallbackMailSubject(issue *issues_model.Issue) string {
return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.FullName(), issue.Title, issue.Index)
}
type mailCommentContext struct {
context.Context
- Issue *models.Issue
+ Issue *issues_model.Issue
Doer *user_model.User
ActionType models.ActionType
Content string
- Comment *models.Comment
+ Comment *issues_model.Comment
}
const (
@@ -57,21 +58,21 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
unfiltered[0] = ctx.Issue.PosterID
// =========== Assignees ===========
- ids, err := models.GetAssigneeIDsByIssue(ctx.Issue.ID)
+ ids, err := issues_model.GetAssigneeIDsByIssue(ctx.Issue.ID)
if err != nil {
return fmt.Errorf("GetAssigneeIDsByIssue(%d): %v", ctx.Issue.ID, err)
}
unfiltered = append(unfiltered, ids...)
// =========== Participants (i.e. commenters, reviewers) ===========
- ids, err = models.GetParticipantsIDsByIssueID(ctx.Issue.ID)
+ ids, err = issues_model.GetParticipantsIDsByIssueID(ctx.Issue.ID)
if err != nil {
return fmt.Errorf("GetParticipantsIDsByIssueID(%d): %v", ctx.Issue.ID, err)
}
unfiltered = append(unfiltered, ids...)
// =========== Issue watchers ===========
- ids, err = models.GetIssueWatchersIDs(ctx, ctx.Issue.ID, true)
+ ids, err = issues_model.GetIssueWatchersIDs(ctx, ctx.Issue.ID, true)
if err != nil {
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
}
@@ -98,7 +99,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
}
// Avoid mailing explicit unwatched
- ids, err = models.GetIssueWatchersIDs(ctx, ctx.Issue.ID, false)
+ ids, err = issues_model.GetIssueWatchersIDs(ctx, ctx.Issue.ID, false)
if err != nil {
return fmt.Errorf("GetIssueWatchersIDs(%d): %v", ctx.Issue.ID, err)
}
@@ -171,7 +172,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi
// MailParticipants sends new issue thread created emails to repository watchers
// and mentioned people.
-func MailParticipants(issue *models.Issue, doer *user_model.User, opType models.ActionType, mentions []*user_model.User) error {
+func MailParticipants(issue *issues_model.Issue, doer *user_model.User, opType models.ActionType, mentions []*user_model.User) error {
if setting.MailService == nil {
// No mail service configured
return nil
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index baf426146a..83955a5896 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"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/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -46,7 +47,7 @@ const bodyTpl = `
</html>
`
-func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, comment *models.Comment) {
+func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment) {
assert.NoError(t, unittest.PrepareTestDatabase())
mailService := setting.Mailer{
From: "test@gitea.com",
@@ -57,9 +58,9 @@ func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *repo_model.Re
doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1, Owner: doer}).(*repo_model.Repository)
- issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
+ issue = unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1, Repo: repo, Poster: doer}).(*issues_model.Issue)
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
- comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2, Issue: issue}).(*models.Comment)
+ comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2, Issue: issue}).(*issues_model.Comment)
return
}
@@ -162,8 +163,8 @@ func TestTemplateSelection(t *testing.T) {
}, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/default/subject", "issue/default/body")
- pull := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue)
- comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment)
+ pull := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2, Repo: repo, Poster: doer}).(*issues_model.Issue)
+ comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull}).(*issues_model.Comment)
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
Context: context.TODO(), // TODO: use a correct context
Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
@@ -183,7 +184,7 @@ func TestTemplateServices(t *testing.T) {
doer, _, issue, comment := prepareMailerTest(t)
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
- expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
+ expect := func(t *testing.T, issue *issues_model.Issue, comment *issues_model.Comment, doer *user_model.User,
actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
) {
stpl := texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject))
@@ -268,8 +269,8 @@ func Test_createReference(t *testing.T) {
pullIssue.IsPull = true
type args struct {
- issue *models.Issue
- comment *models.Comment
+ issue *issues_model.Issue
+ comment *issues_model.Comment
actionType models.ActionType
}
tests := []struct {
diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go
index 408704adef..e71b2ca17a 100644
--- a/services/migrations/gitea_uploader.go
+++ b/services/migrations/gitea_uploader.go
@@ -45,14 +45,14 @@ type GiteaLocalUploader struct {
repoOwner string
repoName string
repo *repo_model.Repository
- labels map[string]*models.Label
+ labels map[string]*issues_model.Label
milestones map[string]int64
- issues map[int64]*models.Issue
+ issues map[int64]*issues_model.Issue
gitRepo *git.Repository
prHeadCache map[string]struct{}
sameApp bool
userMap map[int64]int64 // external user id mapping to user id
- prCache map[int64]*models.PullRequest
+ prCache map[int64]*issues_model.PullRequest
gitServiceType structs.GitServiceType
}
@@ -63,12 +63,12 @@ func NewGiteaLocalUploader(ctx context.Context, doer *user_model.User, repoOwner
doer: doer,
repoOwner: repoOwner,
repoName: repoName,
- labels: make(map[string]*models.Label),
+ labels: make(map[string]*issues_model.Label),
milestones: make(map[string]int64),
- issues: make(map[int64]*models.Issue),
+ issues: make(map[int64]*issues_model.Issue),
prHeadCache: make(map[string]struct{}),
userMap: make(map[int64]int64),
- prCache: make(map[int64]*models.PullRequest),
+ prCache: make(map[int64]*issues_model.PullRequest),
}
}
@@ -76,17 +76,17 @@ func NewGiteaLocalUploader(ctx context.Context, doer *user_model.User, repoOwner
func (g *GiteaLocalUploader) MaxBatchInsertSize(tp string) int {
switch tp {
case "issue":
- return db.MaxBatchInsertSize(new(models.Issue))
+ return db.MaxBatchInsertSize(new(issues_model.Issue))
case "comment":
- return db.MaxBatchInsertSize(new(models.Comment))
+ return db.MaxBatchInsertSize(new(issues_model.Comment))
case "milestone":
return db.MaxBatchInsertSize(new(issues_model.Milestone))
case "label":
- return db.MaxBatchInsertSize(new(models.Label))
+ return db.MaxBatchInsertSize(new(issues_model.Label))
case "release":
return db.MaxBatchInsertSize(new(models.Release))
case "pullrequest":
- return db.MaxBatchInsertSize(new(models.PullRequest))
+ return db.MaxBatchInsertSize(new(issues_model.PullRequest))
}
return 10
}
@@ -216,9 +216,9 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err
// CreateLabels creates labels
func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error {
- lbs := make([]*models.Label, 0, len(labels))
+ lbs := make([]*issues_model.Label, 0, len(labels))
for _, label := range labels {
- lbs = append(lbs, &models.Label{
+ lbs = append(lbs, &issues_model.Label{
RepoID: g.repo.ID,
Name: label.Name,
Description: label.Description,
@@ -226,7 +226,7 @@ func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error {
})
}
- err := models.NewLabels(lbs...)
+ err := issues_model.NewLabels(lbs...)
if err != nil {
return err
}
@@ -339,9 +339,9 @@ func (g *GiteaLocalUploader) SyncTags() error {
// CreateIssues creates issues
func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
- iss := make([]*models.Issue, 0, len(issues))
+ iss := make([]*issues_model.Issue, 0, len(issues))
for _, issue := range issues {
- var labels []*models.Label
+ var labels []*issues_model.Label
for _, label := range issue.Labels {
lb, ok := g.labels[label.Name]
if ok {
@@ -366,7 +366,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
}
}
- is := models.Issue{
+ is := issues_model.Issue{
RepoID: g.repo.ID,
Repo: g.repo,
Index: issue.Number,
@@ -423,9 +423,9 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
// CreateComments creates comments of issues
func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
- cms := make([]*models.Comment, 0, len(comments))
+ cms := make([]*issues_model.Comment, 0, len(comments))
for _, comment := range comments {
- var issue *models.Issue
+ var issue *issues_model.Issue
issue, ok := g.issues[comment.IssueIndex]
if !ok {
return fmt.Errorf("comment references non existent IssueIndex %d", comment.IssueIndex)
@@ -438,9 +438,9 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
comment.Updated = comment.Created
}
- cm := models.Comment{
+ cm := issues_model.Comment{
IssueID: issue.ID,
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
Content: comment.Content,
CreatedUnix: timeutil.TimeStamp(comment.Created.Unix()),
UpdatedUnix: timeutil.TimeStamp(comment.Updated.Unix()),
@@ -473,7 +473,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
// CreatePullRequests creates pull requests
func (g *GiteaLocalUploader) CreatePullRequests(prs ...*base.PullRequest) error {
- gprs := make([]*models.PullRequest, 0, len(prs))
+ gprs := make([]*issues_model.PullRequest, 0, len(prs))
for _, pr := range prs {
gpr, err := g.newPullRequest(pr)
if err != nil {
@@ -600,8 +600,8 @@ func (g *GiteaLocalUploader) updateGitForPullRequest(pr *base.PullRequest) (head
return head, nil
}
-func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullRequest, error) {
- var labels []*models.Label
+func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*issues_model.PullRequest, error) {
+ var labels []*issues_model.Label
for _, label := range pr.Labels {
lb, ok := g.labels[label.Name]
if ok {
@@ -629,7 +629,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
pr.Updated = pr.Created
}
- issue := models.Issue{
+ issue := issues_model.Issue{
RepoID: g.repo.ID,
Repo: g.repo,
Title: pr.Title,
@@ -660,7 +660,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
issue.Reactions = append(issue.Reactions, &res)
}
- pullRequest := models.PullRequest{
+ pullRequest := issues_model.PullRequest{
HeadRepoID: g.repo.ID,
HeadBranch: head,
BaseRepoID: g.repo.ID,
@@ -686,28 +686,28 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
return &pullRequest, nil
}
-func convertReviewState(state string) models.ReviewType {
+func convertReviewState(state string) issues_model.ReviewType {
switch state {
case base.ReviewStatePending:
- return models.ReviewTypePending
+ return issues_model.ReviewTypePending
case base.ReviewStateApproved:
- return models.ReviewTypeApprove
+ return issues_model.ReviewTypeApprove
case base.ReviewStateChangesRequested:
- return models.ReviewTypeReject
+ return issues_model.ReviewTypeReject
case base.ReviewStateCommented:
- return models.ReviewTypeComment
+ return issues_model.ReviewTypeComment
case base.ReviewStateRequestReview:
- return models.ReviewTypeRequest
+ return issues_model.ReviewTypeRequest
default:
- return models.ReviewTypePending
+ return issues_model.ReviewTypePending
}
}
// CreateReviews create pull request reviews of currently migrated issues
func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
- cms := make([]*models.Review, 0, len(reviews))
+ cms := make([]*issues_model.Review, 0, len(reviews))
for _, review := range reviews {
- var issue *models.Issue
+ var issue *issues_model.Issue
issue, ok := g.issues[review.IssueIndex]
if !ok {
return fmt.Errorf("review references non existent IssueIndex %d", review.IssueIndex)
@@ -716,7 +716,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
review.CreatedAt = time.Unix(int64(issue.CreatedUnix), 0)
}
- cm := models.Review{
+ cm := issues_model.Review{
Type: convertReviewState(review.State),
IssueID: issue.ID,
Content: review.Content,
@@ -733,7 +733,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
pr, ok := g.prCache[issue.ID]
if !ok {
var err error
- pr, err = models.GetPullRequestByIssueIDWithNoAttributes(issue.ID)
+ pr, err = issues_model.GetPullRequestByIssueIDWithNoAttributes(issue.ID)
if err != nil {
return err
}
@@ -767,7 +767,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
_ = writer.Close()
}(comment)
- patch, _ = git.CutDiffAroundLine(reader, int64((&models.Comment{Line: int64(line + comment.Position - 1)}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
+ patch, _ = git.CutDiffAroundLine(reader, int64((&issues_model.Comment{Line: int64(line + comment.Position - 1)}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
if comment.CreatedAt.IsZero() {
comment.CreatedAt = review.CreatedAt
@@ -776,8 +776,8 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
comment.UpdatedAt = comment.CreatedAt
}
- c := models.Comment{
- Type: models.CommentTypeCode,
+ c := issues_model.Comment{
+ Type: issues_model.CommentTypeCode,
IssueID: issue.ID,
Content: comment.Content,
Line: int64(line + comment.Position - 1),
@@ -798,7 +798,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
cms = append(cms, &cm)
}
- return models.InsertReviews(cms)
+ return issues_model.InsertReviews(cms)
}
// Rollback when migrating failed, this will rollback all the changes.
@@ -819,7 +819,7 @@ func (g *GiteaLocalUploader) Finish() error {
}
// update issue_index
- if err := models.RecalculateIssueIndexForRepo(g.repo.ID); err != nil {
+ if err := issues_model.RecalculateIssueIndexForRepo(g.repo.ID); err != nil {
return err
}
diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go
index bd7c6e0657..6ea1c20592 100644
--- a/services/migrations/gitea_uploader_test.go
+++ b/services/migrations/gitea_uploader_test.go
@@ -81,7 +81,7 @@ func TestGiteaUploadRepo(t *testing.T) {
assert.NoError(t, err)
assert.Empty(t, milestones)
- labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
+ labels, err := issues_model.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
assert.NoError(t, err)
assert.Len(t, labels, 12)
@@ -105,7 +105,7 @@ func TestGiteaUploadRepo(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, releases, 1)
- issues, err := models.Issues(&models.IssuesOptions{
+ issues, err := issues_model.Issues(&issues_model.IssuesOptions{
RepoID: repo.ID,
IsPull: util.OptionalBoolFalse,
SortType: "oldest",
@@ -115,7 +115,7 @@ func TestGiteaUploadRepo(t *testing.T) {
assert.NoError(t, issues[0].LoadDiscussComments())
assert.Empty(t, issues[0].Comments)
- pulls, _, err := models.PullRequests(repo.ID, &models.PullRequestsOptions{
+ pulls, _, err := issues_model.PullRequests(repo.ID, &issues_model.PullRequestsOptions{
SortType: "oldest",
})
assert.NoError(t, err)
diff --git a/services/pull/check.go b/services/pull/check.go
index 94e7ca7161..6621a281fa 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
@@ -44,9 +45,9 @@ var (
)
// AddToTaskQueue adds itself to pull request test task queue.
-func AddToTaskQueue(pr *models.PullRequest) {
+func AddToTaskQueue(pr *issues_model.PullRequest) {
err := prPatchCheckerQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error {
- pr.Status = models.PullRequestStatusChecking
+ pr.Status = issues_model.PullRequestStatusChecking
err := pr.UpdateColsIfNotMerged("status")
if err != nil {
log.Error("AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err)
@@ -61,7 +62,7 @@ func AddToTaskQueue(pr *models.PullRequest) {
}
// CheckPullMergable check if the pull mergable based on all conditions (branch protection, merge options, ...)
-func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *models.PullRequest, manuallMerge, force bool) error {
+func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *issues_model.PullRequest, manuallMerge, force bool) error {
return db.WithTx(func(ctx context.Context) error {
if pr.HasMerged {
return ErrHasMerged
@@ -114,7 +115,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce
return err
}
- if noDeps, err := models.IssueNoDependenciesLeft(ctx, pr.Issue); err != nil {
+ if noDeps, err := issues_model.IssueNoDependenciesLeft(ctx, pr.Issue); err != nil {
return err
} else if !noDeps {
return ErrDependenciesLeft
@@ -125,7 +126,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce
}
// isSignedIfRequired check if merge will be signed if required
-func isSignedIfRequired(ctx context.Context, pr *models.PullRequest, doer *user_model.User) (bool, error) {
+func isSignedIfRequired(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User) (bool, error) {
if err := pr.LoadProtectedBranchCtx(ctx); err != nil {
return false, err
}
@@ -141,10 +142,10 @@ func isSignedIfRequired(ctx context.Context, pr *models.PullRequest, doer *user_
// checkAndUpdateStatus checks if pull request is possible to leaving checking status,
// and set to be either conflict or mergeable.
-func checkAndUpdateStatus(pr *models.PullRequest) {
+func checkAndUpdateStatus(pr *issues_model.PullRequest) {
// Status is not changed to conflict means mergeable.
- if pr.Status == models.PullRequestStatusChecking {
- pr.Status = models.PullRequestStatusMergeable
+ if pr.Status == issues_model.PullRequestStatusChecking {
+ pr.Status = issues_model.PullRequestStatusMergeable
}
// Make sure there is no waiting test to process before leaving the checking status.
@@ -162,7 +163,7 @@ func checkAndUpdateStatus(pr *models.PullRequest) {
// getMergeCommit checks if a pull request got merged
// Returns the git.Commit of the pull request if merged
-func getMergeCommit(ctx context.Context, pr *models.PullRequest) (*git.Commit, error) {
+func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Commit, error) {
if pr.BaseRepo == nil {
var err error
pr.BaseRepo, err = repo_model.GetRepositoryByID(pr.BaseRepoID)
@@ -230,7 +231,7 @@ func getMergeCommit(ctx context.Context, pr *models.PullRequest) (*git.Commit, e
// 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 *models.PullRequest) bool {
+func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
log.Error("PullRequest[%d].LoadBaseRepo: %v", pr.ID, err)
return false
@@ -254,7 +255,7 @@ func manuallyMerged(ctx context.Context, pr *models.PullRequest) bool {
if commit != nil {
pr.MergedCommitID = commit.ID.String()
pr.MergedUnix = timeutil.TimeStamp(commit.Author.When.Unix())
- pr.Status = models.PullRequestStatusManuallyMerged
+ pr.Status = issues_model.PullRequestStatusManuallyMerged
merger, _ := user_model.GetUserByEmail(commit.Author.Email)
// When the commit author is unknown set the BaseRepo owner as merger
@@ -287,7 +288,7 @@ func manuallyMerged(ctx context.Context, pr *models.PullRequest) bool {
// InitializePullRequests checks and tests untested patches of pull requests.
func InitializePullRequests(ctx context.Context) {
- prs, err := models.GetPullRequestIDsByCheckStatus(models.PullRequestStatusChecking)
+ prs, err := issues_model.GetPullRequestIDsByCheckStatus(issues_model.PullRequestStatusChecking)
if err != nil {
log.Error("Find Checking PRs: %v", err)
return
@@ -323,7 +324,7 @@ func testPR(id int64) {
ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("Test PR[%d] from patch checking queue", id))
defer finished()
- pr, err := models.GetPullRequestByID(ctx, id)
+ pr, err := issues_model.GetPullRequestByID(ctx, id)
if err != nil {
log.Error("GetPullRequestByID[%d]: %v", id, err)
return
@@ -339,7 +340,7 @@ func testPR(id int64) {
if err := TestPatch(pr); err != nil {
log.Error("testPatch[%d]: %v", pr.ID, err)
- pr.Status = models.PullRequestStatusError
+ pr.Status = issues_model.PullRequestStatusError
if err := pr.UpdateCols("status"); err != nil {
log.Error("update pr [%d] status to PullRequestStatusError failed: %v", pr.ID, err)
}
@@ -350,7 +351,7 @@ func testPR(id int64) {
// CheckPrsForBaseBranch check all pulls with bseBrannch
func CheckPrsForBaseBranch(baseRepo *repo_model.Repository, baseBranchName string) error {
- prs, err := models.GetUnmergedPullRequestsByBaseInfo(baseRepo.ID, baseBranchName)
+ prs, err := issues_model.GetUnmergedPullRequestsByBaseInfo(baseRepo.ID, baseBranchName)
if err != nil {
return err
}
diff --git a/services/pull/check_test.go b/services/pull/check_test.go
index bc4c45ffad..21fe675bbc 100644
--- a/services/pull/check_test.go
+++ b/services/pull/check_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/queue"
@@ -43,12 +43,12 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
prPatchCheckerQueue = q.(queue.UniqueQueue)
- pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}).(*issues_model.PullRequest)
AddToTaskQueue(pr)
assert.Eventually(t, func() bool {
- pr = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
- return pr.Status == models.PullRequestStatusChecking
+ pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}).(*issues_model.PullRequest)
+ return pr.Status == issues_model.PullRequestStatusChecking
}, 1*time.Second, 100*time.Millisecond)
has, err := prPatchCheckerQueue.Has(strconv.FormatInt(pr.ID, 10))
@@ -72,8 +72,8 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
assert.False(t, has)
assert.NoError(t, err)
- pr = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
- assert.Equal(t, models.PullRequestStatusChecking, pr.Status)
+ pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}).(*issues_model.PullRequest)
+ assert.Equal(t, issues_model.PullRequestStatusChecking, pr.Status)
for _, callback := range queueShutdown {
callback()
diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go
index c0894c6c98..5d846129f6 100644
--- a/services/pull/commit_status.go
+++ b/services/pull/commit_status.go
@@ -8,9 +8,9 @@ package pull
import (
"context"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/structs"
@@ -83,7 +83,7 @@ func IsCommitStatusContextSuccess(commitStatuses []*git_model.CommitStatus, requ
}
// IsPullCommitStatusPass returns if all required status checks PASS
-func IsPullCommitStatusPass(ctx context.Context, pr *models.PullRequest) (bool, error) {
+func IsPullCommitStatusPass(ctx context.Context, pr *issues_model.PullRequest) (bool, error) {
if err := pr.LoadProtectedBranchCtx(ctx); err != nil {
return false, errors.Wrap(err, "GetLatestCommitStatus")
}
@@ -99,7 +99,7 @@ func IsPullCommitStatusPass(ctx context.Context, pr *models.PullRequest) (bool,
}
// GetPullRequestCommitStatusState returns pull request merged commit status state
-func GetPullRequestCommitStatusState(ctx context.Context, pr *models.PullRequest) (structs.CommitStatusState, error) {
+func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullRequest) (structs.CommitStatusState, error) {
// Ensure HeadRepo is loaded
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
return "", errors.Wrap(err, "LoadHeadRepo")
@@ -112,15 +112,15 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *models.PullRequest
}
defer closer.Close()
- if pr.Flow == models.PullRequestFlowGithub && !headGitRepo.IsBranchExist(pr.HeadBranch) {
+ if pr.Flow == issues_model.PullRequestFlowGithub && !headGitRepo.IsBranchExist(pr.HeadBranch) {
return "", errors.New("Head branch does not exist, can not merge")
}
- if pr.Flow == models.PullRequestFlowAGit && !git.IsReferenceExist(ctx, headGitRepo.Path, pr.GetGitRefName()) {
+ if pr.Flow == issues_model.PullRequestFlowAGit && !git.IsReferenceExist(ctx, headGitRepo.Path, pr.GetGitRefName()) {
return "", errors.New("Head branch does not exist, can not merge")
}
var sha string
- if pr.Flow == models.PullRequestFlowGithub {
+ if pr.Flow == issues_model.PullRequestFlowGithub {
sha, err = headGitRepo.GetBranchCommitID(pr.HeadBranch)
} else {
sha, err = headGitRepo.GetRefCommitID(pr.GetGitRefName())
diff --git a/services/pull/edits.go b/services/pull/edits.go
index 11932d9ab8..2938f2b108 100644
--- a/services/pull/edits.go
+++ b/services/pull/edits.go
@@ -9,7 +9,7 @@ import (
"context"
"errors"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
unit_model "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
@@ -18,7 +18,7 @@ import (
var ErrUserHasNoPermissionForAction = errors.New("user not allowed to do this action")
// SetAllowEdits allow edits from maintainers to PRs
-func SetAllowEdits(ctx context.Context, doer *user_model.User, pr *models.PullRequest, allow bool) error {
+func SetAllowEdits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, allow bool) error {
if doer == nil || !pr.Issue.IsPoster(doer.ID) {
return ErrUserHasNoPermissionForAction
}
@@ -37,5 +37,5 @@ func SetAllowEdits(ctx context.Context, doer *user_model.User, pr *models.PullRe
}
pr.AllowMaintainerEdit = allow
- return models.UpdateAllowEdits(ctx, pr)
+ return issues_model.UpdateAllowEdits(ctx, pr)
}
diff --git a/services/pull/lfs.go b/services/pull/lfs.go
index 490a904584..8cca0a91b7 100644
--- a/services/pull/lfs.go
+++ b/services/pull/lfs.go
@@ -12,15 +12,15 @@ import (
"strconv"
"sync"
- "code.gitea.io/gitea/models"
git_model "code.gitea.io/gitea/models/git"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/git/pipeline"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
)
// LFSPush pushes lfs objects referred to in new commits in the head repository from the base repository
-func LFSPush(ctx context.Context, tmpBasePath, mergeHeadSHA, mergeBaseSHA string, pr *models.PullRequest) error {
+func LFSPush(ctx context.Context, tmpBasePath, mergeHeadSHA, mergeBaseSHA string, pr *issues_model.PullRequest) error {
// Now we have to implement git lfs push
// git rev-list --objects --filter=blob:limit=1k HEAD --not base
// pass blob shas in to git cat-file --batch-check (possibly unnecessary)
@@ -68,7 +68,7 @@ func LFSPush(ctx context.Context, tmpBasePath, mergeHeadSHA, mergeBaseSHA string
return nil
}
-func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg *sync.WaitGroup, pr *models.PullRequest) {
+func createLFSMetaObjectsFromCatFileBatch(catFileBatchReader *io.PipeReader, wg *sync.WaitGroup, pr *issues_model.PullRequest) {
defer wg.Done()
defer catFileBatchReader.Close()
diff --git a/services/pull/merge.go b/services/pull/merge.go
index eef1d17b64..aff800a1b6 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
pull_model "code.gitea.io/gitea/models/pull"
repo_model "code.gitea.io/gitea/models/repo"
@@ -38,7 +39,7 @@ import (
)
// GetDefaultMergeMessage returns default message used when merging pull request
-func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *models.PullRequest, mergeStyle repo_model.MergeStyle) (string, error) {
+func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRequest, mergeStyle repo_model.MergeStyle) (string, error) {
if err := pr.LoadHeadRepo(); err != nil {
return "", err
}
@@ -131,7 +132,7 @@ func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *models.PullRequest,
// 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 *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string) error {
+func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string) error {
if err := pr.LoadHeadRepo(); err != nil {
log.Error("LoadHeadRepo: %v", err)
return fmt.Errorf("LoadHeadRepo: %v", err)
@@ -213,7 +214,7 @@ func Merge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, b
if close != ref.Issue.IsClosed {
if err = issue_service.ChangeStatus(ref.Issue, doer, close); err != nil {
// Allow ErrDependenciesLeft
- if !models.IsErrDependenciesLeft(err) {
+ if !issues_model.IsErrDependenciesLeft(err) {
return err
}
}
@@ -223,7 +224,7 @@ func Merge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, b
}
// rawMerge perform the merge operation without changing any pull information in database
-func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string) (string, error) {
+func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string) (string, error) {
// Clone base repo.
tmpBasePath, err := createTemporaryRepo(ctx, pr)
if err != nil {
@@ -635,7 +636,7 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
return mergeCommitID, nil
}
-func commitAndSignNoAuthor(ctx context.Context, pr *models.PullRequest, message, signArg, tmpBasePath string, env []string) error {
+func commitAndSignNoAuthor(ctx context.Context, pr *issues_model.PullRequest, message, signArg, tmpBasePath string, env []string) error {
var outbuf, errbuf strings.Builder
if signArg == "" {
if err := git.NewCommand(ctx, "commit", "-m", message).
@@ -663,7 +664,7 @@ func commitAndSignNoAuthor(ctx context.Context, pr *models.PullRequest, message,
return nil
}
-func runMergeCommand(pr *models.PullRequest, mergeStyle repo_model.MergeStyle, cmd *git.Command, tmpBasePath string) error {
+func runMergeCommand(pr *issues_model.PullRequest, mergeStyle repo_model.MergeStyle, cmd *git.Command, tmpBasePath string) error {
var outbuf, errbuf strings.Builder
if err := cmd.Run(&git.RunOpts{
Dir: tmpBasePath,
@@ -747,7 +748,7 @@ func getDiffTree(ctx context.Context, repoPath, baseBranch, headBranch string) (
}
// IsUserAllowedToMerge check if user is allowed to merge PR with given permissions and branch protections
-func IsUserAllowedToMerge(ctx context.Context, pr *models.PullRequest, p access_model.Permission, user *user_model.User) (bool, error) {
+func IsUserAllowedToMerge(ctx context.Context, pr *issues_model.PullRequest, p access_model.Permission, user *user_model.User) (bool, error) {
if user == nil {
return false, nil
}
@@ -765,7 +766,7 @@ func IsUserAllowedToMerge(ctx context.Context, pr *models.PullRequest, p access_
}
// CheckPullBranchProtections checks whether the PR is ready to be merged (reviews and status checks)
-func CheckPullBranchProtections(ctx context.Context, pr *models.PullRequest, skipProtectedFilesCheck bool) (err error) {
+func CheckPullBranchProtections(ctx context.Context, pr *issues_model.PullRequest, skipProtectedFilesCheck bool) (err error) {
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
return fmt.Errorf("LoadBaseRepo: %v", err)
}
@@ -787,23 +788,23 @@ func CheckPullBranchProtections(ctx context.Context, pr *models.PullRequest, ski
}
}
- if !models.HasEnoughApprovals(ctx, pr.ProtectedBranch, pr) {
+ if !issues_model.HasEnoughApprovals(ctx, pr.ProtectedBranch, pr) {
return models.ErrDisallowedToMerge{
Reason: "Does not have enough approvals",
}
}
- if models.MergeBlockedByRejectedReview(ctx, pr.ProtectedBranch, pr) {
+ if issues_model.MergeBlockedByRejectedReview(ctx, pr.ProtectedBranch, pr) {
return models.ErrDisallowedToMerge{
Reason: "There are requested changes",
}
}
- if models.MergeBlockedByOfficialReviewRequests(ctx, pr.ProtectedBranch, pr) {
+ if issues_model.MergeBlockedByOfficialReviewRequests(ctx, pr.ProtectedBranch, pr) {
return models.ErrDisallowedToMerge{
Reason: "There are official review requests",
}
}
- if models.MergeBlockedByOutdatedBranch(pr.ProtectedBranch, pr) {
+ if issues_model.MergeBlockedByOutdatedBranch(pr.ProtectedBranch, pr) {
return models.ErrDisallowedToMerge{
Reason: "The head branch is behind the base branch",
}
@@ -823,7 +824,7 @@ func CheckPullBranchProtections(ctx context.Context, pr *models.PullRequest, ski
}
// MergedManually mark pr as merged manually
-func MergedManually(pr *models.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, commitID string) error {
+func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, commitID string) error {
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID))
@@ -862,7 +863,7 @@ func MergedManually(pr *models.PullRequest, doer *user_model.User, baseGitRepo *
pr.MergedCommitID = commitID
pr.MergedUnix = timeutil.TimeStamp(commit.Author.When.Unix())
- pr.Status = models.PullRequestStatusManuallyMerged
+ pr.Status = issues_model.PullRequestStatusManuallyMerged
pr.Merger = doer
pr.MergerID = doer.ID
diff --git a/services/pull/patch.go b/services/pull/patch.go
index 6e2889b060..c7a69501c3 100644
--- a/services/pull/patch.go
+++ b/services/pull/patch.go
@@ -15,6 +15,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
@@ -27,7 +28,7 @@ import (
)
// DownloadDiffOrPatch will write the patch for the pr to the writer
-func DownloadDiffOrPatch(ctx context.Context, pr *models.PullRequest, w io.Writer, patch, binary bool) error {
+func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io.Writer, patch, binary bool) error {
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
log.Error("Unable to load base repository ID %d for pr #%d [%d]", pr.BaseRepoID, pr.Index, pr.ID)
return err
@@ -54,7 +55,7 @@ var patchErrorSuffices = []string{
}
// TestPatch will test whether a simple patch will apply
-func TestPatch(pr *models.PullRequest) error {
+func TestPatch(pr *issues_model.PullRequest) error {
ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("TestPatch: Repo[%d]#%d", pr.BaseRepoID, pr.Index))
defer finished()
@@ -88,7 +89,7 @@ func TestPatch(pr *models.PullRequest) error {
pr.MergeBase = strings.TrimSpace(pr.MergeBase)
// 2. Check for conflicts
- if conflicts, err := checkConflicts(ctx, pr, gitRepo, tmpBasePath); err != nil || conflicts || pr.Status == models.PullRequestStatusEmpty {
+ if conflicts, err := checkConflicts(ctx, pr, gitRepo, tmpBasePath); err != nil || conflicts || pr.Status == issues_model.PullRequestStatusEmpty {
return err
}
@@ -101,7 +102,7 @@ func TestPatch(pr *models.PullRequest) error {
log.Trace("Found %d protected files changed", len(pr.ChangedProtectedFiles))
}
- pr.Status = models.PullRequestStatusMergeable
+ pr.Status = issues_model.PullRequestStatusMergeable
return nil
}
@@ -270,7 +271,7 @@ func AttemptThreeWayMerge(ctx context.Context, gitPath string, gitRepo *git.Repo
return conflict, conflictedFiles, nil
}
-func checkConflicts(ctx context.Context, pr *models.PullRequest, gitRepo *git.Repository, tmpBasePath string) (bool, error) {
+func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *git.Repository, tmpBasePath string) (bool, error) {
// 1. checkConflicts resets the conflict status - therefore - reset the conflict status
pr.ConflictedFiles = nil
@@ -295,7 +296,7 @@ func checkConflicts(ctx context.Context, pr *models.PullRequest, gitRepo *git.Re
}
if treeHash == baseTree.ID.String() {
log.Debug("PullRequest[%d]: Patch is empty - ignoring", pr.ID)
- pr.Status = models.PullRequestStatusEmpty
+ pr.Status = issues_model.PullRequestStatusEmpty
}
return false, nil
@@ -329,7 +330,7 @@ func checkConflicts(ctx context.Context, pr *models.PullRequest, gitRepo *git.Re
// 3b. if the size of that patch is 0 - there can be no conflicts!
if stat.Size() == 0 {
log.Debug("PullRequest[%d]: Patch is empty - ignoring", pr.ID)
- pr.Status = models.PullRequestStatusEmpty
+ pr.Status = issues_model.PullRequestStatusEmpty
return false, nil
}
@@ -449,7 +450,7 @@ func checkConflicts(ctx context.Context, pr *models.PullRequest, gitRepo *git.Re
// Note: `"err" could be non-nil` is due that if enable 3-way merge, it doesn't return any error on found conflicts.
if len(pr.ConflictedFiles) > 0 {
if conflict {
- pr.Status = models.PullRequestStatusConflict
+ pr.Status = issues_model.PullRequestStatusConflict
log.Trace("Found %d files conflicted: %v", len(pr.ConflictedFiles), pr.ConflictedFiles)
return true, nil
@@ -516,8 +517,8 @@ func CheckUnprotectedFiles(repo *git.Repository, oldCommitID, newCommitID string
}
// checkPullFilesProtection check if pr changed protected files and save results
-func checkPullFilesProtection(pr *models.PullRequest, gitRepo *git.Repository) error {
- if pr.Status == models.PullRequestStatusEmpty {
+func checkPullFilesProtection(pr *issues_model.PullRequest, gitRepo *git.Repository) error {
+ if pr.Status == issues_model.PullRequestStatusEmpty {
pr.ChangedProtectedFiles = nil
return nil
}
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 736520fda2..103fdc340d 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
@@ -35,7 +36,7 @@ import (
var pullWorkingPool = sync.NewExclusivePool()
// NewPullRequest creates new pull request with labels for repository.
-func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *models.Issue, labelIDs []int64, uuids []string, pr *models.PullRequest, assigneeIDs []int64) error {
+func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issues_model.Issue, labelIDs []int64, uuids []string, pr *issues_model.PullRequest, assigneeIDs []int64) error {
if err := TestPatch(pr); err != nil {
return err
}
@@ -47,7 +48,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
pr.CommitsAhead = divergence.Ahead
pr.CommitsBehind = divergence.Behind
- if err := models.NewPullRequest(ctx, repo, pull, labelIDs, uuids, pr); err != nil {
+ if err := issues_model.NewPullRequest(ctx, repo, pull, labelIDs, uuids, pr); err != nil {
return err
}
@@ -66,7 +67,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
prCtx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("NewPullRequest: %s:%d", repo.FullName(), pr.Index))
defer finished()
- if pr.Flow == models.PullRequestFlowGithub {
+ if pr.Flow == issues_model.PullRequestFlowGithub {
err = PushToBaseRepo(prCtx, pr)
} else {
err = UpdateRef(prCtx, pr)
@@ -75,7 +76,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
return err
}
- mentions, err := models.FindAndUpdateIssueMentions(ctx, pull, pull.Poster, pull.Content)
+ mentions, err := issues_model.FindAndUpdateIssueMentions(ctx, pull, pull.Poster, pull.Content)
if err != nil {
return err
}
@@ -102,7 +103,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
}
if len(compareInfo.Commits) > 0 {
- data := models.PushActionContent{IsForcePush: false}
+ data := issues_model.PushActionContent{IsForcePush: false}
data.CommitIDs = make([]string, 0, len(compareInfo.Commits))
for i := len(compareInfo.Commits) - 1; i >= 0; i-- {
data.CommitIDs = append(data.CommitIDs, compareInfo.Commits[i].ID.String())
@@ -113,8 +114,8 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
return err
}
- ops := &models.CreateCommentOptions{
- Type: models.CommentTypePullRequestPush,
+ ops := &issues_model.CreateCommentOptions{
+ Type: issues_model.CommentTypePullRequestPush,
Doer: pull.Poster,
Repo: repo,
Issue: pr.Issue,
@@ -122,14 +123,14 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *mode
Content: string(dataJSON),
}
- _, _ = models.CreateComment(ops)
+ _, _ = issues_model.CreateComment(ops)
}
return nil
}
// ChangeTargetBranch changes the target branch of this pull request, as the given user.
-func ChangeTargetBranch(ctx context.Context, pr *models.PullRequest, doer *user_model.User, targetBranch string) (err error) {
+func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, targetBranch string) (err error) {
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID))
@@ -139,7 +140,7 @@ func ChangeTargetBranch(ctx context.Context, pr *models.PullRequest, doer *user_
}
if pr.Issue.IsClosed {
- return models.ErrIssueIsClosed{
+ return issues_model.ErrIssueIsClosed{
ID: pr.Issue.ID,
RepoID: pr.Issue.RepoID,
Index: pr.Issue.Index,
@@ -170,9 +171,9 @@ func ChangeTargetBranch(ctx context.Context, pr *models.PullRequest, doer *user_
}
// Check if pull request for the new target branch already exists
- existingPr, err := models.GetUnmergedPullRequest(pr.HeadRepoID, pr.BaseRepoID, pr.HeadBranch, targetBranch, models.PullRequestFlowGithub)
+ existingPr, err := issues_model.GetUnmergedPullRequest(pr.HeadRepoID, pr.BaseRepoID, pr.HeadBranch, targetBranch, issues_model.PullRequestFlowGithub)
if existingPr != nil {
- return models.ErrPullRequestAlreadyExists{
+ return issues_model.ErrPullRequestAlreadyExists{
ID: existingPr.ID,
IssueID: existingPr.Index,
HeadRepoID: existingPr.HeadRepoID,
@@ -181,7 +182,7 @@ func ChangeTargetBranch(ctx context.Context, pr *models.PullRequest, doer *user_
BaseBranch: existingPr.BaseBranch,
}
}
- if err != nil && !models.IsErrPullRequestNotExist(err) {
+ if err != nil && !issues_model.IsErrPullRequestNotExist(err) {
return err
}
@@ -196,8 +197,8 @@ func ChangeTargetBranch(ctx context.Context, pr *models.PullRequest, doer *user_
// Update target branch, PR diff and status
// This is the same as checkAndUpdateStatus in check service, but also updates base_branch
- if pr.Status == models.PullRequestStatusChecking {
- pr.Status = models.PullRequestStatusMergeable
+ if pr.Status == issues_model.PullRequestStatusChecking {
+ pr.Status = issues_model.PullRequestStatusMergeable
}
// Update Commit Divergence
@@ -213,22 +214,22 @@ func ChangeTargetBranch(ctx context.Context, pr *models.PullRequest, doer *user_
}
// Create comment
- options := &models.CreateCommentOptions{
- Type: models.CommentTypeChangeTargetBranch,
+ options := &issues_model.CreateCommentOptions{
+ Type: issues_model.CommentTypeChangeTargetBranch,
Doer: doer,
Repo: pr.Issue.Repo,
Issue: pr.Issue,
OldRef: oldBranch,
NewRef: targetBranch,
}
- if _, err = models.CreateComment(options); err != nil {
+ if _, err = issues_model.CreateComment(options); err != nil {
return fmt.Errorf("CreateChangeTargetBranchComment: %v", err)
}
return nil
}
-func checkForInvalidation(ctx context.Context, requests models.PullRequestList, repoID int64, doer *user_model.User, branch string) error {
+func checkForInvalidation(ctx context.Context, requests issues_model.PullRequestList, repoID int64, doer *user_model.User, branch string) error {
repo, err := repo_model.GetRepositoryByID(repoID)
if err != nil {
return fmt.Errorf("GetRepositoryByID: %v", err)
@@ -257,14 +258,14 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
// If you don't let it run all the way then you will lose data
// TODO: graceful: AddTestPullRequestTask needs to become a queue!
- prs, err := models.GetUnmergedPullRequestsByHeadInfo(repoID, branch)
+ prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repoID, branch)
if err != nil {
log.Error("Find pull requests [head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err)
return
}
if isSync {
- requests := models.PullRequestList(prs)
+ requests := issues_model.PullRequestList(prs)
if err = requests.LoadAttributes(); err != nil {
log.Error("PullRequestList.LoadAttributes: %v", err)
}
@@ -280,11 +281,11 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
}
if changed {
// Mark old reviews as stale if diff to mergebase has changed
- if err := models.MarkReviewsAsStale(pr.IssueID); err != nil {
+ if err := issues_model.MarkReviewsAsStale(pr.IssueID); err != nil {
log.Error("MarkReviewsAsStale: %v", err)
}
}
- if err := models.MarkReviewsAsNotStale(pr.IssueID, newCommitID); err != nil {
+ if err := issues_model.MarkReviewsAsNotStale(pr.IssueID, newCommitID); err != nil {
log.Error("MarkReviewsAsNotStale: %v", err)
}
divergence, err := GetDiverging(ctx, pr)
@@ -306,7 +307,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
for _, pr := range prs {
log.Trace("Updating PR[%d]: composing new test task", pr.ID)
- if pr.Flow == models.PullRequestFlowGithub {
+ if pr.Flow == issues_model.PullRequestFlowGithub {
if err := PushToBaseRepo(ctx, pr); err != nil {
log.Error("PushToBaseRepo: %v", err)
continue
@@ -316,14 +317,14 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
}
AddToTaskQueue(pr)
- comment, err := models.CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
+ comment, err := issues_model.CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
if err == nil && comment != nil {
notification.NotifyPullRequestPushCommits(doer, pr, comment)
}
}
log.Trace("AddTestPullRequestTask [base_repo_id: %d, base_branch: %s]: finding pull requests", repoID, branch)
- prs, err = models.GetUnmergedPullRequestsByBaseInfo(repoID, branch)
+ prs, err = issues_model.GetUnmergedPullRequestsByBaseInfo(repoID, branch)
if err != nil {
log.Error("Find pull requests [base_repo_id: %d, base_branch: %s]: %v", repoID, branch, err)
return
@@ -349,7 +350,7 @@ 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 *models.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
+func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
return false, fmt.Errorf("LoadHeadRepo: %v", err)
} else if pr.HeadRepo == nil {
@@ -421,11 +422,11 @@ func checkIfPRContentChanged(ctx context.Context, pr *models.PullRequest, oldCom
// PushToBaseRepo pushes commits from branches of head repository to
// corresponding branches of base repository.
// FIXME: Only push branches that are actually updates?
-func PushToBaseRepo(ctx context.Context, pr *models.PullRequest) (err error) {
+func PushToBaseRepo(ctx context.Context, pr *issues_model.PullRequest) (err error) {
return pushToBaseRepoHelper(ctx, pr, "")
}
-func pushToBaseRepoHelper(ctx context.Context, pr *models.PullRequest, prefixHeadBranch string) (err error) {
+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 {
@@ -481,7 +482,7 @@ func pushToBaseRepoHelper(ctx context.Context, pr *models.PullRequest, prefixHea
}
// UpdateRef update refs/pull/id/head directly for agit flow pull request
-func UpdateRef(ctx context.Context, pr *models.PullRequest) (err error) {
+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 {
log.Error("Unable to load base repository for PR[%d] Error: %v", pr.ID, err)
@@ -514,24 +515,24 @@ func (errs errlist) Error() string {
// CloseBranchPulls close all the pull requests who's head branch is the branch
func CloseBranchPulls(doer *user_model.User, repoID int64, branch string) error {
- prs, err := models.GetUnmergedPullRequestsByHeadInfo(repoID, branch)
+ prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repoID, branch)
if err != nil {
return err
}
- prs2, err := models.GetUnmergedPullRequestsByBaseInfo(repoID, branch)
+ prs2, err := issues_model.GetUnmergedPullRequestsByBaseInfo(repoID, branch)
if err != nil {
return err
}
prs = append(prs, prs2...)
- if err := models.PullRequestList(prs).LoadAttributes(); err != nil {
+ if err := issues_model.PullRequestList(prs).LoadAttributes(); err != nil {
return err
}
var errs errlist
for _, pr := range prs {
- if err = issue_service.ChangeStatus(pr.Issue, doer, true); err != nil && !models.IsErrPullWasClosed(err) && !models.IsErrDependenciesLeft(err) {
+ if err = issue_service.ChangeStatus(pr.Issue, doer, true); err != nil && !issues_model.IsErrPullWasClosed(err) && !issues_model.IsErrDependenciesLeft(err) {
errs = append(errs, err)
}
}
@@ -550,12 +551,12 @@ func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *re
var errs errlist
for _, branch := range branches {
- prs, err := models.GetUnmergedPullRequestsByHeadInfo(repo.ID, branch.Name)
+ prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repo.ID, branch.Name)
if err != nil {
return err
}
- if err = models.PullRequestList(prs).LoadAttributes(); err != nil {
+ if err = issues_model.PullRequestList(prs).LoadAttributes(); err != nil {
return err
}
@@ -565,7 +566,7 @@ func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *re
if pr.BaseRepoID == repo.ID {
continue
}
- if err = issue_service.ChangeStatus(pr.Issue, doer, true); err != nil && !models.IsErrPullWasClosed(err) {
+ if err = issue_service.ChangeStatus(pr.Issue, doer, true); err != nil && !issues_model.IsErrPullWasClosed(err) {
errs = append(errs, err)
}
}
@@ -580,7 +581,7 @@ func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *re
var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[ \t]*:[^\n]+\n*(?:[ \t]+[^\n]+\n*)*)+$`)
// GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)
-func GetSquashMergeCommitMessages(ctx context.Context, pr *models.PullRequest) string {
+func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequest) string {
if err := pr.LoadIssue(); err != nil {
log.Error("Cannot load issue %d for PR id %d: Error: %v", pr.IssueID, pr.ID, err)
return ""
@@ -608,7 +609,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *models.PullRequest) s
defer closer.Close()
var headCommit *git.Commit
- if pr.Flow == models.PullRequestFlowGithub {
+ if pr.Flow == issues_model.PullRequestFlowGithub {
headCommit, err = gitRepo.GetBranchCommit(pr.HeadBranch)
} else {
pr.HeadCommitID, err = gitRepo.GetRefCommitID(pr.GetGitRefName())
@@ -736,13 +737,13 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *models.PullRequest) s
}
// GetIssuesLastCommitStatus returns a map of issue ID to the most recent commit's latest status
-func GetIssuesLastCommitStatus(ctx context.Context, issues models.IssueList) (map[int64]*git_model.CommitStatus, error) {
+func GetIssuesLastCommitStatus(ctx context.Context, issues issues_model.IssueList) (map[int64]*git_model.CommitStatus, error) {
_, lastStatus, err := GetIssuesAllCommitStatus(ctx, issues)
return lastStatus, err
}
// 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 models.IssueList) (map[int64][]*git_model.CommitStatus, map[int64]*git_model.CommitStatus, error) {
+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 {
return nil, nil, err
}
@@ -788,7 +789,7 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues models.IssueList) (map
}
// getAllCommitStatus get pr's commit statuses.
-func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (statuses []*git_model.CommitStatus, lastStatus *git_model.CommitStatus, err error) {
+func getAllCommitStatus(gitRepo *git.Repository, pr *issues_model.PullRequest) (statuses []*git_model.CommitStatus, lastStatus *git_model.CommitStatus, err error) {
sha, shaErr := gitRepo.GetRefCommitID(pr.GetGitRefName())
if shaErr != nil {
return nil, nil, shaErr
@@ -800,7 +801,7 @@ func getAllCommitStatus(gitRepo *git.Repository, pr *models.PullRequest) (status
}
// IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head
-func IsHeadEqualWithBranch(ctx context.Context, pr *models.PullRequest, branchName string) (bool, error) {
+func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, branchName string) (bool, error) {
var err error
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
return false, err
@@ -833,7 +834,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *models.PullRequest, branchNa
}
var headCommit *git.Commit
- if pr.Flow == models.PullRequestFlowGithub {
+ if pr.Flow == issues_model.PullRequestFlowGithub {
headCommit, err = headGitRepo.GetBranchCommit(pr.HeadBranch)
if err != nil {
return false, err
diff --git a/services/pull/pull_test.go b/services/pull/pull_test.go
index 09bae97780..9160c43460 100644
--- a/services/pull/pull_test.go
+++ b/services/pull/pull_test.go
@@ -8,7 +8,7 @@ package pull
import (
"testing"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
@@ -38,7 +38,7 @@ func TestPullRequest_CommitMessageTrailersPattern(t *testing.T) {
func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}).(*issues_model.PullRequest)
assert.NoError(t, pr.LoadBaseRepo())
gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
@@ -68,7 +68,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
baseRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
baseRepo.Units = []*repo_model.RepoUnit{&externalTracker}
- pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2, BaseRepo: baseRepo}).(*models.PullRequest)
+ pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2, BaseRepo: baseRepo}).(*issues_model.PullRequest)
assert.NoError(t, pr.LoadBaseRepo())
gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
diff --git a/services/pull/review.go b/services/pull/review.go
index eac7279f9b..9cb58fa3a1 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -12,8 +12,8 @@ import (
"regexp"
"strings"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
@@ -23,7 +23,7 @@ import (
)
// CreateCodeComment creates a comment on the code line
-func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *models.Issue, line int64, content, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*models.Comment, error) {
+func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue, line int64, content, treePath string, isReview bool, replyReviewID int64, latestCommitID string) (*issues_model.Comment, error) {
var (
existsReview bool
err error
@@ -37,7 +37,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
if !isReview && replyReviewID != 0 {
// It's not part of a review; maybe a reply to a review comment or a single comment.
// Check if there are reviews for that line already; if there are, this is a reply
- if existsReview, err = models.ReviewExists(issue, treePath, line); err != nil {
+ if existsReview, err = issues_model.ReviewExists(issue, treePath, line); err != nil {
return nil, err
}
}
@@ -61,7 +61,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
return nil, err
}
- mentions, err := models.FindAndUpdateIssueMentions(ctx, issue, doer, comment.Content)
+ mentions, err := issues_model.FindAndUpdateIssueMentions(ctx, issue, doer, comment.Content)
if err != nil {
return nil, err
}
@@ -71,14 +71,14 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
return comment, nil
}
- review, err := models.GetCurrentReview(ctx, doer, issue)
+ review, err := issues_model.GetCurrentReview(ctx, doer, issue)
if err != nil {
- if !models.IsErrReviewNotExist(err) {
+ if !issues_model.IsErrReviewNotExist(err) {
return nil, err
}
- if review, err = models.CreateReview(ctx, models.CreateReviewOptions{
- Type: models.ReviewTypePending,
+ if review, err = issues_model.CreateReview(ctx, issues_model.CreateReviewOptions{
+ Type: issues_model.ReviewTypePending,
Reviewer: doer,
Issue: issue,
Official: false,
@@ -103,7 +103,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
if !isReview && !existsReview {
// Submit the review we've just created so the comment shows up in the issue view
- if _, _, err = SubmitReview(ctx, doer, gitRepo, issue, models.ReviewTypeComment, "", latestCommitID, nil); err != nil {
+ if _, _, err = SubmitReview(ctx, doer, gitRepo, issue, issues_model.ReviewTypeComment, "", latestCommitID, nil); err != nil {
return nil, err
}
}
@@ -116,7 +116,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
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(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *models.Issue, content, treePath string, line, reviewID int64) (*models.Comment, error) {
+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: %v", err)
@@ -135,11 +135,11 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
head := pr.GetGitRefName()
if line > 0 {
if reviewID != 0 {
- first, err := models.FindComments(ctx, &models.FindCommentsOptions{
+ first, err := issues_model.FindComments(ctx, &issues_model.FindCommentsOptions{
ReviewID: reviewID,
Line: line,
TreePath: treePath,
- Type: models.CommentTypeCode,
+ Type: issues_model.CommentTypeCode,
ListOptions: db.ListOptions{
PageSize: 1,
Page: 1,
@@ -149,13 +149,13 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
commitID = first[0].CommitSHA
invalidated = first[0].Invalidated
patch = first[0].Patch
- } else if err != nil && !models.IsErrCommentNotExist(err) {
+ } else if err != nil && !issues_model.IsErrCommentNotExist(err) {
return nil, fmt.Errorf("Find first comment for %d line %d path %s. Error: %v", reviewID, line, treePath, err)
} else {
- review, err := models.GetReviewByID(ctx, reviewID)
+ review, err := issues_model.GetReviewByID(ctx, reviewID)
if err == nil && len(review.CommitID) > 0 {
head = review.CommitID
- } else if err != nil && !models.IsErrReviewNotExist(err) {
+ } else if err != nil && !issues_model.IsErrReviewNotExist(err) {
return nil, fmt.Errorf("GetReviewByID %d. Error: %v", reviewID, err)
}
}
@@ -196,14 +196,14 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
_ = writer.Close()
}()
- patch, err = git.CutDiffAroundLine(reader, int64((&models.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
+ patch, err = git.CutDiffAroundLine(reader, int64((&issues_model.Comment{Line: line}).UnsignedLine()), line < 0, setting.UI.CodeCommentLines)
if err != nil {
log.Error("Error whilst generating patch: %v", err)
return nil, err
}
}
- return models.CreateComment(&models.CreateCommentOptions{
- Type: models.CommentTypeCode,
+ return issues_model.CreateComment(&issues_model.CreateCommentOptions{
+ Type: issues_model.CommentTypeCode,
Doer: doer,
Repo: repo,
Issue: issue,
@@ -218,14 +218,14 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
}
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
-func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *models.Issue, reviewType models.ReviewType, content, commitID string, attachmentUUIDs []string) (*models.Review, *models.Comment, error) {
+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) {
pr, err := issue.GetPullRequest()
if err != nil {
return nil, nil, err
}
var stale bool
- if reviewType != models.ReviewTypeApprove && reviewType != models.ReviewTypeReject {
+ if reviewType != issues_model.ReviewTypeApprove && reviewType != issues_model.ReviewTypeReject {
stale = false
} else {
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
@@ -243,12 +243,12 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
}
}
- review, comm, err := models.SubmitReview(doer, issue, reviewType, content, commitID, stale, attachmentUUIDs)
+ review, comm, err := issues_model.SubmitReview(doer, issue, reviewType, content, commitID, stale, attachmentUUIDs)
if err != nil {
return nil, nil, err
}
- mentions, err := models.FindAndUpdateIssueMentions(ctx, issue, doer, comm.Content)
+ mentions, err := issues_model.FindAndUpdateIssueMentions(ctx, issue, doer, comm.Content)
if err != nil {
return nil, nil, err
}
@@ -258,7 +258,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
for _, lines := range review.CodeComments {
for _, comments := range lines {
for _, codeComment := range comments {
- mentions, err := models.FindAndUpdateIssueMentions(ctx, issue, doer, codeComment.Content)
+ mentions, err := issues_model.FindAndUpdateIssueMentions(ctx, issue, doer, codeComment.Content)
if err != nil {
return nil, nil, err
}
@@ -271,17 +271,17 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
}
// DismissReview dismissing stale review by repo admin
-func DismissReview(ctx context.Context, reviewID int64, message string, doer *user_model.User, isDismiss bool) (comment *models.Comment, err error) {
- review, err := models.GetReviewByID(ctx, reviewID)
+func DismissReview(ctx context.Context, reviewID int64, message string, doer *user_model.User, isDismiss bool) (comment *issues_model.Comment, err error) {
+ review, err := issues_model.GetReviewByID(ctx, reviewID)
if err != nil {
return
}
- if review.Type != models.ReviewTypeApprove && review.Type != models.ReviewTypeReject {
+ if review.Type != issues_model.ReviewTypeApprove && review.Type != issues_model.ReviewTypeReject {
return nil, fmt.Errorf("not need to dismiss this review because it's type is not Approve or change request")
}
- if err = models.DismissReview(review, isDismiss); err != nil {
+ if err = issues_model.DismissReview(review, isDismiss); err != nil {
return
}
@@ -296,14 +296,14 @@ func DismissReview(ctx context.Context, reviewID int64, message string, doer *us
if err = review.Issue.LoadPullRequest(); err != nil {
return
}
- if err = review.Issue.LoadAttributes(); err != nil {
+ if err = review.Issue.LoadAttributes(ctx); err != nil {
return
}
- comment, err = models.CreateComment(&models.CreateCommentOptions{
+ comment, err = issues_model.CreateComment(&issues_model.CreateCommentOptions{
Doer: doer,
Content: message,
- Type: models.CommentTypeDismissReview,
+ Type: issues_model.CommentTypeDismissReview,
ReviewID: review.ID,
Issue: review.Issue,
Repo: review.Issue.Repo,
diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go
index 6b01809d49..c1456ef0a9 100644
--- a/services/pull/temp_repo.go
+++ b/services/pull/temp_repo.go
@@ -13,6 +13,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -21,7 +22,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 *models.PullRequest) (string, error) {
+func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (string, error) {
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
log.Error("LoadHeadRepo: %v", err)
return "", fmt.Errorf("LoadHeadRepo: %v", err)
@@ -164,7 +165,7 @@ func createTemporaryRepo(ctx context.Context, pr *models.PullRequest) (string, e
trackingBranch := "tracking"
// Fetch head branch
var headBranch string
- if pr.Flow == models.PullRequestFlowGithub {
+ if pr.Flow == issues_model.PullRequestFlowGithub {
headBranch = git.BranchPrefix + pr.HeadBranch
} else if len(pr.HeadCommitID) == 40 { // for not created pull request
headBranch = pr.HeadCommitID
diff --git a/services/pull/update.go b/services/pull/update.go
index 0ab8ffcd7d..e5e26462e5 100644
--- a/services/pull/update.go
+++ b/services/pull/update.go
@@ -9,6 +9,7 @@ import (
"fmt"
"code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
@@ -19,9 +20,9 @@ import (
)
// Update updates pull request with base branch.
-func Update(ctx context.Context, pull *models.PullRequest, doer *user_model.User, message string, rebase bool) error {
+func Update(ctx context.Context, pull *issues_model.PullRequest, doer *user_model.User, message string, rebase bool) error {
var (
- pr *models.PullRequest
+ pr *issues_model.PullRequest
style repo_model.MergeStyle
)
@@ -33,7 +34,7 @@ func Update(ctx context.Context, pull *models.PullRequest, doer *user_model.User
style = repo_model.MergeStyleRebaseUpdate
} else {
// use merge functions but switch repo's and branch's
- pr = &models.PullRequest{
+ pr = &issues_model.PullRequest{
HeadRepoID: pull.BaseRepoID,
BaseRepoID: pull.HeadRepoID,
HeadBranch: pull.BaseBranch,
@@ -42,7 +43,7 @@ func Update(ctx context.Context, pull *models.PullRequest, doer *user_model.User
style = repo_model.MergeStyleMerge
}
- if pull.Flow == models.PullRequestFlowAGit {
+ if pull.Flow == issues_model.PullRequestFlowAGit {
// TODO: Not support update agit flow pull request's head branch
return fmt.Errorf("Not support update agit flow pull request's head branch")
}
@@ -76,8 +77,8 @@ func Update(ctx context.Context, pull *models.PullRequest, doer *user_model.User
}
// IsUserAllowedToUpdate check if user is allowed to update PR with given permissions and branch protections
-func IsUserAllowedToUpdate(ctx context.Context, pull *models.PullRequest, user *user_model.User) (mergeAllowed, rebaseAllowed bool, err error) {
- if pull.Flow == models.PullRequestFlowAGit {
+func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest, user *user_model.User) (mergeAllowed, rebaseAllowed bool, err error) {
+ if pull.Flow == issues_model.PullRequestFlowAGit {
return false, false, nil
}
@@ -89,7 +90,7 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *models.PullRequest, user *
return false, false, err
}
- pr := &models.PullRequest{
+ pr := &issues_model.PullRequest{
HeadRepoID: pull.BaseRepoID,
BaseRepoID: pull.HeadRepoID,
HeadBranch: pull.BaseBranch,
@@ -139,7 +140,7 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *models.PullRequest, user *
}
// GetDiverging determines how many commits a PR is ahead or behind the PR base branch
-func GetDiverging(ctx context.Context, pr *models.PullRequest) (*git.DivergeObject, error) {
+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 {
return nil, err
diff --git a/services/repository/repository.go b/services/repository/repository.go
index 6848eda101..4bde6879a6 100644
--- a/services/repository/repository.go
+++ b/services/repository/repository.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
admin_model "code.gitea.io/gitea/models/admin"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/organization"
packages_model "code.gitea.io/gitea/models/packages"
repo_model "code.gitea.io/gitea/models/repo"
@@ -105,7 +106,7 @@ func UpdateRepository(repo *repo_model.Repository, visibilityChanged bool) (err
// LinkedRepository returns the linked repo if any
func LinkedRepository(a *repo_model.Attachment) (*repo_model.Repository, unit.Type, error) {
if a.IssueID != 0 {
- iss, err := models.GetIssueByID(a.IssueID)
+ iss, err := issues_model.GetIssueByID(db.DefaultContext, a.IssueID)
if err != nil {
return nil, unit.TypeIssues, err
}
diff --git a/services/repository/template.go b/services/repository/template.go
index 6a1bfaff5b..d7e8145811 100644
--- a/services/repository/template.go
+++ b/services/repository/template.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
@@ -18,14 +19,14 @@ import (
// GenerateIssueLabels generates issue labels from a template repository
func GenerateIssueLabels(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
- templateLabels, err := models.GetLabelsByRepoID(ctx, templateRepo.ID, "", db.ListOptions{})
+ templateLabels, err := issues_model.GetLabelsByRepoID(ctx, templateRepo.ID, "", db.ListOptions{})
if err != nil {
return err
}
- newLabels := make([]*models.Label, 0, len(templateLabels))
+ newLabels := make([]*issues_model.Label, 0, len(templateLabels))
for _, templateLabel := range templateLabels {
- newLabels = append(newLabels, &models.Label{
+ newLabels = append(newLabels, &issues_model.Label{
RepoID: generateRepo.ID,
Name: templateLabel.Name,
Description: templateLabel.Description,