aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web
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 /routers/web
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 'routers/web')
-rw-r--r--routers/web/org/org_labels.go16
-rw-r--r--routers/web/repo/branch.go5
-rw-r--r--routers/web/repo/compare.go5
-rw-r--r--routers/web/repo/issue.go276
-rw-r--r--routers/web/repo/issue_content_history.go27
-rw-r--r--routers/web/repo/issue_dependency.go26
-rw-r--r--routers/web/repo/issue_label.go24
-rw-r--r--routers/web/repo/issue_label_test.go24
-rw-r--r--routers/web/repo/issue_lock.go6
-rw-r--r--routers/web/repo/issue_stopwatch.go14
-rw-r--r--routers/web/repo/issue_test.go158
-rw-r--r--routers/web/repo/issue_timetrack.go8
-rw-r--r--routers/web/repo/issue_watch.go4
-rw-r--r--routers/web/repo/projects.go14
-rw-r--r--routers/web/repo/pull.go65
-rw-r--r--routers/web/repo/pull_review.go24
-rw-r--r--routers/web/user/home.go52
-rw-r--r--routers/web/user/stop_watch.go6
18 files changed, 378 insertions, 376 deletions
diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go
index bfa9f162c3..185e1eee31 100644
--- a/routers/web/org/org_labels.go
+++ b/routers/web/org/org_labels.go
@@ -7,8 +7,8 @@ package org
import (
"net/http"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/web"
@@ -17,7 +17,7 @@ import (
// RetrieveLabels find all the labels of an organization
func RetrieveLabels(ctx *context.Context) {
- labels, err := models.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), db.ListOptions{})
+ labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("RetrieveLabels.GetLabels", err)
return
@@ -43,13 +43,13 @@ func NewLabel(ctx *context.Context) {
return
}
- l := &models.Label{
+ l := &issues_model.Label{
OrgID: ctx.Org.Organization.ID,
Name: form.Title,
Description: form.Description,
Color: form.Color,
}
- if err := models.NewLabel(ctx, l); err != nil {
+ if err := issues_model.NewLabel(ctx, l); err != nil {
ctx.ServerError("NewLabel", err)
return
}
@@ -59,10 +59,10 @@ func NewLabel(ctx *context.Context) {
// UpdateLabel update a label's name and color
func UpdateLabel(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CreateLabelForm)
- l, err := models.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, form.ID)
+ l, err := issues_model.GetLabelInOrgByID(ctx, ctx.Org.Organization.ID, form.ID)
if err != nil {
switch {
- case models.IsErrOrgLabelNotExist(err):
+ case issues_model.IsErrOrgLabelNotExist(err):
ctx.Error(http.StatusNotFound)
default:
ctx.ServerError("UpdateLabel", err)
@@ -73,7 +73,7 @@ func UpdateLabel(ctx *context.Context) {
l.Name = form.Title
l.Description = form.Description
l.Color = form.Color
- if err := models.UpdateLabel(l); err != nil {
+ if err := issues_model.UpdateLabel(l); err != nil {
ctx.ServerError("UpdateLabel", err)
return
}
@@ -82,7 +82,7 @@ func UpdateLabel(ctx *context.Context) {
// DeleteLabel delete a label
func DeleteLabel(ctx *context.Context) {
- if err := models.DeleteLabel(ctx.Org.Organization.ID, ctx.FormInt64("id")); err != nil {
+ if err := issues_model.DeleteLabel(ctx.Org.Organization.ID, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeleteLabel: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go
index 84ad803ee5..4bd2af4e8e 100644
--- a/routers/web/repo/branch.go
+++ b/routers/web/repo/branch.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models"
git_model "code.gitea.io/gitea/models/git"
+ 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/modules/base"
@@ -44,7 +45,7 @@ type Branch struct {
DeletedBranch *git_model.DeletedBranch
CommitsAhead int
CommitsBehind int
- LatestPullRequest *models.PullRequest
+ LatestPullRequest *issues_model.PullRequest
MergeMovedOn bool
}
@@ -264,7 +265,7 @@ func loadOneBranch(ctx *context.Context, rawBranch, defaultBranch *git.Branch, p
}
}
- pr, err := models.GetLatestPullRequestByHeadInfo(ctx.Repo.Repository.ID, branchName)
+ pr, err := issues_model.GetLatestPullRequestByHeadInfo(ctx.Repo.Repository.ID, branchName)
if err != nil {
ctx.ServerError("GetLatestPullRequestByHeadInfo", err)
return nil
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 44e89062e8..605594d5a9 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/models"
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"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
@@ -747,9 +748,9 @@ func CompareDiff(ctx *context.Context) {
ctx.Data["HeadTags"] = headTags
if ctx.Data["PageIsComparePull"] == true {
- pr, err := models.GetUnmergedPullRequest(ci.HeadRepo.ID, ctx.Repo.Repository.ID, ci.HeadBranch, ci.BaseBranch, models.PullRequestFlowGithub)
+ pr, err := issues_model.GetUnmergedPullRequest(ci.HeadRepo.ID, ctx.Repo.Repository.ID, ci.HeadBranch, ci.BaseBranch, issues_model.PullRequestFlowGithub)
if err != nil {
- if !models.IsErrPullRequestNotExist(err) {
+ if !issues_model.IsErrPullRequestNotExist(err) {
ctx.ServerError("GetUnmergedPullRequest", err)
return
}
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 38ee933044..11d2daeeff 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -183,11 +183,11 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
}
}
- var issueStats *models.IssueStats
+ var issueStats *issues_model.IssueStats
if forceEmpty {
- issueStats = &models.IssueStats{}
+ issueStats = &issues_model.IssueStats{}
} else {
- issueStats, err = models.GetIssueStats(&models.IssueStatsOptions{
+ issueStats, err = issues_model.GetIssueStats(&issues_model.IssueStatsOptions{
RepoID: repo.ID,
Labels: selectLabels,
MilestoneID: milestoneID,
@@ -228,11 +228,11 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
mileIDs = []int64{milestoneID}
}
- var issues []*models.Issue
+ var issues []*issues_model.Issue
if forceEmpty {
- issues = []*models.Issue{}
+ issues = []*issues_model.Issue{}
} else {
- issues, err = models.Issues(&models.IssuesOptions{
+ issues, err = issues_model.Issues(&issues_model.IssuesOptions{
ListOptions: db.ListOptions{
Page: pager.Paginater.Current(),
PageSize: setting.UI.IssuePagingNum,
@@ -256,7 +256,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
}
}
- issueList := models.IssueList(issues)
+ issueList := issues_model.IssueList(issues)
approvalCounts, err := issueList.GetApprovalCounts(ctx)
if err != nil {
ctx.ServerError("ApprovalCounts", err)
@@ -296,14 +296,14 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
return
}
- labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
+ labels, err := issues_model.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return
}
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
+ orgLabels, err := issues_model.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
@@ -330,11 +330,11 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
if !ok || len(counts) == 0 {
return 0
}
- reviewTyp := models.ReviewTypeApprove
+ reviewTyp := issues_model.ReviewTypeApprove
if typ == "reject" {
- reviewTyp = models.ReviewTypeReject
+ reviewTyp = issues_model.ReviewTypeReject
} else if typ == "waiting" {
- reviewTyp = models.ReviewTypeRequest
+ reviewTyp = issues_model.ReviewTypeRequest
}
for _, count := range counts {
if count.Type == reviewTyp {
@@ -483,24 +483,24 @@ type repoReviewerSelection struct {
IsTeam bool
Team *organization.Team
User *user_model.User
- Review *models.Review
+ Review *issues_model.Review
CanChange bool
Checked bool
ItemID int64
}
// RetrieveRepoReviewers find all reviewers of a repository
-func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, issue *models.Issue, canChooseReviewer bool) {
+func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, issue *issues_model.Issue, canChooseReviewer bool) {
ctx.Data["CanChooseReviewer"] = canChooseReviewer
- originalAuthorReviews, err := models.GetReviewersFromOriginalAuthorsByIssueID(issue.ID)
+ originalAuthorReviews, err := issues_model.GetReviewersFromOriginalAuthorsByIssueID(issue.ID)
if err != nil {
ctx.ServerError("GetReviewersFromOriginalAuthorsByIssueID", err)
return
}
ctx.Data["OriginalReviews"] = originalAuthorReviews
- reviews, err := models.GetReviewersByIssueID(issue.ID)
+ reviews, err := issues_model.GetReviewersByIssueID(issue.ID)
if err != nil {
ctx.ServerError("GetReviewersByIssueID", err)
return
@@ -549,7 +549,7 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is
for _, review := range reviews {
tmp := &repoReviewerSelection{
- Checked: review.Type == models.ReviewTypeRequest,
+ Checked: review.Type == issues_model.ReviewTypeRequest,
Review: review,
ItemID: review.ReviewerID,
}
@@ -561,10 +561,10 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is
if ctx.Repo.IsAdmin() {
// Admin can dismiss or re-request any review requests
tmp.CanChange = true
- } else if ctx.Doer != nil && ctx.Doer.ID == review.ReviewerID && review.Type == models.ReviewTypeRequest {
+ } else if ctx.Doer != nil && ctx.Doer.ID == review.ReviewerID && review.Type == issues_model.ReviewTypeRequest {
// A user can refuse review requests
tmp.CanChange = true
- } else if (canChooseReviewer || (ctx.Doer != nil && ctx.Doer.ID == issue.PosterID)) && review.Type != models.ReviewTypeRequest &&
+ } else if (canChooseReviewer || (ctx.Doer != nil && ctx.Doer.ID == issue.PosterID)) && review.Type != issues_model.ReviewTypeRequest &&
ctx.Doer.ID != review.ReviewerID {
// The poster of the PR, a manager, or official reviewers can re-request review from other reviewers
tmp.CanChange = true
@@ -670,19 +670,19 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is
}
// RetrieveRepoMetas find all the meta information of a repository
-func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull bool) []*models.Label {
+func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull bool) []*issues_model.Label {
if !ctx.Repo.CanWriteIssuesOrPulls(isPull) {
return nil
}
- labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
+ labels, err := issues_model.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return nil
}
ctx.Data["Labels"] = labels
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
+ orgLabels, err := issues_model.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
return nil
}
@@ -763,10 +763,10 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleDirs,
ctx.Data[issueTemplateTitleKey] = meta.Title
ctx.Data[ctxDataKey] = templateBody
labelIDs := make([]string, 0, len(meta.Labels))
- if repoLabels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, "", db.ListOptions{}); err == nil {
+ if repoLabels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, "", db.ListOptions{}); err == nil {
ctx.Data["Labels"] = repoLabels
if ctx.Repo.Owner.IsOrganization() {
- if orgLabels, err := models.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}); err == nil {
+ if orgLabels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{}); err == nil {
ctx.Data["OrgLabels"] = orgLabels
repoLabels = append(repoLabels, orgLabels...)
}
@@ -969,7 +969,7 @@ func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull
}
if !valid {
- ctx.ServerError("canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name})
+ ctx.ServerError("canBeAssigned", repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name})
return nil, nil, 0, 0
}
}
@@ -1017,7 +1017,7 @@ func NewIssuePost(ctx *context.Context) {
return
}
- issue := &models.Issue{
+ issue := &issues_model.Issue{
RepoID: repo.ID,
Repo: repo,
Title: form.Title,
@@ -1029,7 +1029,7 @@ func NewIssuePost(ctx *context.Context) {
}
if err := issue_service.NewIssue(repo, issue, labelIDs, attachments, assigneeIDs); err != nil {
- if models.IsErrUserDoesNotHaveAccessToRepo(err) {
+ if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
return
}
@@ -1038,7 +1038,7 @@ func NewIssuePost(ctx *context.Context) {
}
if projectID > 0 {
- if err := models.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil {
+ if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil {
ctx.ServerError("ChangeProjectAssign", err)
return
}
@@ -1053,29 +1053,29 @@ func NewIssuePost(ctx *context.Context) {
}
// roleDescriptor returns the Role Descriptor for a comment in/with the given repo, poster and issue
-func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *models.Issue) (models.RoleDescriptor, error) {
+func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *user_model.User, issue *issues_model.Issue) (issues_model.RoleDescriptor, error) {
perm, err := access_model.GetUserRepoPermission(ctx, repo, poster)
if err != nil {
- return models.RoleDescriptorNone, err
+ return issues_model.RoleDescriptorNone, err
}
// By default the poster has no roles on the comment.
- roleDescriptor := models.RoleDescriptorNone
+ roleDescriptor := issues_model.RoleDescriptorNone
// Check if the poster is owner of the repo.
if perm.IsOwner() {
// If the poster isn't a admin, enable the owner role.
if !poster.IsAdmin {
- roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorOwner)
+ roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorOwner)
} else {
// Otherwise check if poster is the real repo admin.
ok, err := access_model.IsUserRealRepoAdmin(repo, poster)
if err != nil {
- return models.RoleDescriptorNone, err
+ return issues_model.RoleDescriptorNone, err
}
if ok {
- roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorOwner)
+ roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorOwner)
}
}
}
@@ -1083,18 +1083,18 @@ func roleDescriptor(ctx stdCtx.Context, repo *repo_model.Repository, poster *use
// Is the poster can write issues or pulls to the repo, enable the Writer role.
// Only enable this if the poster doesn't have the owner role already.
if !roleDescriptor.HasRole("Owner") && perm.CanWriteIssuesOrPulls(issue.IsPull) {
- roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorWriter)
+ roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorWriter)
}
// If the poster is the actual poster of the issue, enable Poster role.
if issue.IsPoster(poster.ID) {
- roleDescriptor = roleDescriptor.WithRole(models.RoleDescriptorPoster)
+ roleDescriptor = roleDescriptor.WithRole(issues_model.RoleDescriptorPoster)
}
return roleDescriptor, nil
}
-func getBranchData(ctx *context.Context, issue *models.Issue) {
+func getBranchData(ctx *context.Context, issue *issues_model.Issue) {
ctx.Data["BaseBranch"] = nil
ctx.Data["HeadBranch"] = nil
ctx.Data["HeadUserName"] = nil
@@ -1131,9 +1131,9 @@ func ViewIssue(ctx *context.Context) {
}
}
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
+ if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("GetIssueByIndex", err)
} else {
ctx.ServerError("GetIssueByIndex", err)
@@ -1182,7 +1182,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled
upload.AddUploadContext(ctx, "comment")
- if err = issue.LoadAttributes(); err != nil {
+ if err = issue.LoadAttributes(ctx); err != nil {
ctx.ServerError("LoadAttributes", err)
return
}
@@ -1194,11 +1194,11 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
- iw := new(models.IssueWatch)
+ iw := new(issues_model.IssueWatch)
if ctx.Doer != nil {
iw.UserID = ctx.Doer.ID
iw.IssueID = issue.ID
- iw.IsWatching, err = models.CheckIssueWatch(ctx.Doer, issue)
+ iw.IsWatching, err = issues_model.CheckIssueWatch(ctx.Doer, issue)
if err != nil {
ctx.ServerError("CheckIssueWatch", err)
return
@@ -1239,7 +1239,7 @@ func ViewIssue(ctx *context.Context) {
for i := range issue.Labels {
labelIDMark[issue.Labels[i].ID] = true
}
- labels, err := models.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
+ labels, err := issues_model.GetLabelsByRepoID(ctx, repo.ID, "", db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByRepoID", err)
return
@@ -1247,7 +1247,7 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["Labels"] = labels
if repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
+ orgLabels, err := issues_model.GetLabelsByOrgID(ctx, repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
@@ -1279,7 +1279,7 @@ func ViewIssue(ctx *context.Context) {
if issue.IsPull {
canChooseReviewer := ctx.Repo.CanWrite(unit.TypePullRequests)
if !canChooseReviewer && ctx.Doer != nil && ctx.IsSigned {
- canChooseReviewer, err = models.IsOfficialReviewer(ctx, issue, ctx.Doer)
+ canChooseReviewer, err = issues_model.IsOfficialReviewer(ctx, issue, ctx.Doer)
if err != nil {
ctx.ServerError("IsOfficialReviewer", err)
return
@@ -1294,35 +1294,35 @@ func ViewIssue(ctx *context.Context) {
if ctx.IsSigned {
// Update issue-user.
- if err = issue.ReadBy(ctx, ctx.Doer.ID); err != nil {
+ if err = models.SetIssueReadBy(ctx, issue.ID, ctx.Doer.ID); err != nil {
ctx.ServerError("ReadBy", err)
return
}
}
var (
- role models.RoleDescriptor
+ role issues_model.RoleDescriptor
ok bool
- marked = make(map[int64]models.RoleDescriptor)
- comment *models.Comment
+ marked = make(map[int64]issues_model.RoleDescriptor)
+ comment *issues_model.Comment
participants = make([]*user_model.User, 1, 10)
)
if ctx.Repo.Repository.IsTimetrackerEnabled() {
if ctx.IsSigned {
// Deal with the stopwatch
- ctx.Data["IsStopwatchRunning"] = models.StopwatchExists(ctx.Doer.ID, issue.ID)
+ ctx.Data["IsStopwatchRunning"] = issues_model.StopwatchExists(ctx.Doer.ID, issue.ID)
if !ctx.Data["IsStopwatchRunning"].(bool) {
var exists bool
- var sw *models.Stopwatch
- if exists, sw, err = models.HasUserStopwatch(ctx, ctx.Doer.ID); err != nil {
+ var sw *issues_model.Stopwatch
+ if exists, sw, err = issues_model.HasUserStopwatch(ctx, ctx.Doer.ID); err != nil {
ctx.ServerError("HasUserStopwatch", err)
return
}
ctx.Data["HasUserStopwatch"] = exists
if exists {
// Add warning if the user has already a stopwatch
- var otherIssue *models.Issue
- if otherIssue, err = models.GetIssueByID(sw.IssueID); err != nil {
+ var otherIssue *issues_model.Issue
+ if otherIssue, err = issues_model.GetIssueByID(ctx, sw.IssueID); err != nil {
ctx.ServerError("GetIssueByID", err)
return
}
@@ -1338,7 +1338,7 @@ func ViewIssue(ctx *context.Context) {
} else {
ctx.Data["CanUseTimetracker"] = false
}
- if ctx.Data["WorkingUsers"], err = models.TotalTimes(&models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
+ if ctx.Data["WorkingUsers"], err = issues_model.TotalTimes(&issues_model.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil {
ctx.ServerError("TotalTimes", err)
return
}
@@ -1366,7 +1366,7 @@ func ViewIssue(ctx *context.Context) {
return
}
- if comment.Type == models.CommentTypeComment || comment.Type == models.CommentTypeReview {
+ if comment.Type == issues_model.CommentTypeComment || comment.Type == issues_model.CommentTypeReview {
if err := comment.LoadAttachments(); err != nil {
ctx.ServerError("LoadAttachments", err)
return
@@ -1396,12 +1396,12 @@ func ViewIssue(ctx *context.Context) {
}
marked[comment.PosterID] = comment.ShowRole
participants = addParticipant(comment.Poster, participants)
- } else if comment.Type == models.CommentTypeLabel {
+ } else if comment.Type == issues_model.CommentTypeLabel {
if err = comment.LoadLabel(); err != nil {
ctx.ServerError("LoadLabel", err)
return
}
- } else if comment.Type == models.CommentTypeMilestone {
+ } else if comment.Type == issues_model.CommentTypeMilestone {
if err = comment.LoadMilestone(); err != nil {
ctx.ServerError("LoadMilestone", err)
return
@@ -1416,7 +1416,7 @@ func ViewIssue(ctx *context.Context) {
if comment.MilestoneID > 0 && comment.Milestone == nil {
comment.Milestone = ghostMilestone
}
- } else if comment.Type == models.CommentTypeProject {
+ } else if comment.Type == issues_model.CommentTypeProject {
if err = comment.LoadProject(); err != nil {
ctx.ServerError("LoadProject", err)
@@ -1436,19 +1436,19 @@ func ViewIssue(ctx *context.Context) {
comment.Project = ghostProject
}
- } else if comment.Type == models.CommentTypeAssignees || comment.Type == models.CommentTypeReviewRequest {
+ } else if comment.Type == issues_model.CommentTypeAssignees || comment.Type == issues_model.CommentTypeReviewRequest {
if err = comment.LoadAssigneeUserAndTeam(); err != nil {
ctx.ServerError("LoadAssigneeUserAndTeam", err)
return
}
- } else if comment.Type == models.CommentTypeRemoveDependency || comment.Type == models.CommentTypeAddDependency {
+ } else if comment.Type == issues_model.CommentTypeRemoveDependency || comment.Type == issues_model.CommentTypeAddDependency {
if err = comment.LoadDepIssueDetails(); err != nil {
- if !models.IsErrIssueNotExist(err) {
+ if !issues_model.IsErrIssueNotExist(err) {
ctx.ServerError("LoadDepIssueDetails", err)
return
}
}
- } else if comment.Type == models.CommentTypeCode || comment.Type == models.CommentTypeReview || comment.Type == models.CommentTypeDismissReview {
+ } else if comment.Type == issues_model.CommentTypeCode || comment.Type == issues_model.CommentTypeReview || comment.Type == issues_model.CommentTypeDismissReview {
comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{
URLPrefix: ctx.Repo.RepoLink,
Metas: ctx.Repo.Repository.ComposeMetas(),
@@ -1459,7 +1459,7 @@ func ViewIssue(ctx *context.Context) {
ctx.ServerError("RenderString", err)
return
}
- if err = comment.LoadReview(); err != nil && !models.IsErrReviewNotExist(err) {
+ if err = comment.LoadReview(); err != nil && !issues_model.IsErrReviewNotExist(err) {
ctx.ServerError("LoadReview", err)
return
}
@@ -1502,14 +1502,14 @@ func ViewIssue(ctx *context.Context) {
ctx.ServerError("LoadResolveDoer", err)
return
}
- } else if comment.Type == models.CommentTypePullRequestPush {
+ } else if comment.Type == issues_model.CommentTypePullRequestPush {
participants = addParticipant(comment.Poster, participants)
if err = comment.LoadPushCommits(ctx); err != nil {
ctx.ServerError("LoadPushCommits", err)
return
}
- } else if comment.Type == models.CommentTypeAddTimeManual ||
- comment.Type == models.CommentTypeStopTracking {
+ } else if comment.Type == issues_model.CommentTypeAddTimeManual ||
+ comment.Type == issues_model.CommentTypeStopTracking {
// drop error since times could be pruned from DB..
_ = comment.LoadTime()
}
@@ -1562,7 +1562,7 @@ func ViewIssue(ctx *context.Context) {
return
}
- if ctx.Data["CanMarkConversation"], err = models.CanMarkConversation(issue, ctx.Doer); err != nil {
+ if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(issue, ctx.Doer); err != nil {
ctx.ServerError("CanMarkConversation", err)
return
}
@@ -1621,11 +1621,11 @@ func ViewIssue(ctx *context.Context) {
if ctx.Doer != nil {
showMergeInstructions = pull.ProtectedBranch.CanUserPush(ctx.Doer.ID)
}
- ctx.Data["IsBlockedByApprovals"] = !models.HasEnoughApprovals(ctx, pull.ProtectedBranch, pull)
- ctx.Data["IsBlockedByRejection"] = models.MergeBlockedByRejectedReview(ctx, pull.ProtectedBranch, pull)
- ctx.Data["IsBlockedByOfficialReviewRequests"] = models.MergeBlockedByOfficialReviewRequests(ctx, pull.ProtectedBranch, pull)
- ctx.Data["IsBlockedByOutdatedBranch"] = models.MergeBlockedByOutdatedBranch(pull.ProtectedBranch, pull)
- ctx.Data["GrantedApprovals"] = models.GetGrantedApprovalsCount(ctx, pull.ProtectedBranch, pull)
+ ctx.Data["IsBlockedByApprovals"] = !issues_model.HasEnoughApprovals(ctx, pull.ProtectedBranch, pull)
+ ctx.Data["IsBlockedByRejection"] = issues_model.MergeBlockedByRejectedReview(ctx, pull.ProtectedBranch, pull)
+ ctx.Data["IsBlockedByOfficialReviewRequests"] = issues_model.MergeBlockedByOfficialReviewRequests(ctx, pull.ProtectedBranch, pull)
+ ctx.Data["IsBlockedByOutdatedBranch"] = issues_model.MergeBlockedByOutdatedBranch(pull.ProtectedBranch, pull)
+ ctx.Data["GrantedApprovals"] = issues_model.GetGrantedApprovalsCount(ctx, pull.ProtectedBranch, pull)
ctx.Data["RequireSigned"] = pull.ProtectedBranch.RequireSignedCommits
ctx.Data["ChangedProtectedFiles"] = pull.ChangedProtectedFiles
ctx.Data["IsBlockedByChangedProtectedFiles"] = len(pull.ChangedProtectedFiles) != 0
@@ -1655,7 +1655,7 @@ func ViewIssue(ctx *context.Context) {
(!pull.HasMerged || ctx.Data["HeadBranchCommitID"] == ctx.Data["PullHeadCommitID"])
if isPullBranchDeletable && pull.HasMerged {
- exist, err := models.HasUnmergedPullRequestsByHeadInfo(ctx, pull.HeadRepoID, pull.HeadBranch)
+ exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pull.HeadRepoID, pull.HeadBranch)
if err != nil {
ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
return
@@ -1722,7 +1722,7 @@ func ViewIssue(ctx *context.Context) {
}
hiddenCommentTypes, _ = new(big.Int).SetString(val, 10) // we can safely ignore the failed conversion here
}
- ctx.Data["ShouldShowCommentType"] = func(commentType models.CommentType) bool {
+ ctx.Data["ShouldShowCommentType"] = func(commentType issues_model.CommentType) bool {
return hiddenCommentTypes == nil || hiddenCommentTypes.Bit(int(commentType)) == 0
}
@@ -1730,10 +1730,10 @@ func ViewIssue(ctx *context.Context) {
}
// GetActionIssue will return the issue which is used in the context.
-func GetActionIssue(ctx *context.Context) *models.Issue {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func GetActionIssue(ctx *context.Context) *issues_model.Issue {
+ issue, err := issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err)
+ ctx.NotFoundOrServerError("GetIssueByIndex", issues_model.IsErrIssueNotExist, err)
return nil
}
issue.Repo = ctx.Repo.Repository
@@ -1741,21 +1741,21 @@ func GetActionIssue(ctx *context.Context) *models.Issue {
if ctx.Written() {
return nil
}
- if err = issue.LoadAttributes(); err != nil {
+ if err = issue.LoadAttributes(ctx); err != nil {
ctx.ServerError("LoadAttributes", nil)
return nil
}
return issue
}
-func checkIssueRights(ctx *context.Context, issue *models.Issue) {
+func checkIssueRights(ctx *context.Context, issue *issues_model.Issue) {
if issue.IsPull && !ctx.Repo.CanRead(unit.TypePullRequests) ||
!issue.IsPull && !ctx.Repo.CanRead(unit.TypeIssues) {
ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
}
}
-func getActionIssues(ctx *context.Context) []*models.Issue {
+func getActionIssues(ctx *context.Context) []*issues_model.Issue {
commaSeparatedIssueIDs := ctx.FormString("issue_ids")
if len(commaSeparatedIssueIDs) == 0 {
return nil
@@ -1769,7 +1769,7 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
}
issueIDs = append(issueIDs, issueID)
}
- issues, err := models.GetIssuesByIDs(ctx, issueIDs)
+ issues, err := issues_model.GetIssuesByIDs(ctx, issueIDs)
if err != nil {
ctx.ServerError("GetIssuesByIDs", err)
return nil
@@ -1782,7 +1782,7 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
return nil
}
- if err = issue.LoadAttributes(); err != nil {
+ if err = issue.LoadAttributes(ctx); err != nil {
ctx.ServerError("LoadAttributes", err)
return nil
}
@@ -1792,9 +1792,9 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
// GetIssueInfo get an issue of a repository
func GetIssueInfo(ctx *context.Context) {
- issue, err := models.GetIssueWithAttrsByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := issues_model.GetIssueWithAttrsByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
+ if issues_model.IsErrIssueNotExist(err) {
ctx.Error(http.StatusNotFound)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err.Error())
@@ -1916,9 +1916,9 @@ func UpdateIssueContent(ctx *context.Context) {
// UpdateIssueDeadline updates an issue deadline
func UpdateIssueDeadline(ctx *context.Context) {
form := web.GetForm(ctx).(*api.EditDeadlineOption)
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
+ if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("GetIssueByIndex", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err.Error())
@@ -1939,7 +1939,7 @@ func UpdateIssueDeadline(ctx *context.Context) {
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
}
- if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
+ if err := issues_model.UpdateIssueDeadline(issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err.Error())
return
}
@@ -2002,7 +2002,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
return
}
if !valid {
- ctx.ServerError("canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: assigneeID, RepoName: issue.Repo.Name})
+ ctx.ServerError("canBeAssigned", repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: assigneeID, RepoName: issue.Repo.Name})
return
}
@@ -2080,7 +2080,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
err = issue_service.IsValidTeamReviewRequest(ctx, team, ctx.Doer, action == "attach", issue)
if err != nil {
- if models.IsErrNotValidReviewRequest(err) {
+ if issues_model.IsErrNotValidReviewRequest(err) {
log.Warn(
"UpdatePullReviewRequest: refusing to add invalid team review request for UID[%d] team %s to %s#%d owned by UID[%d]: Error: %v",
team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID,
@@ -2118,7 +2118,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
err = issue_service.IsValidReviewRequest(ctx, reviewer, ctx.Doer, action == "attach", issue, nil)
if err != nil {
- if models.IsErrNotValidReviewRequest(err) {
+ if issues_model.IsErrNotValidReviewRequest(err) {
log.Warn(
"UpdatePullReviewRequest: refusing to add invalid review request for %-v to %-v#%d: Error: %v",
reviewer, issue.Repo, issue.Index,
@@ -2215,7 +2215,7 @@ func SearchIssues(ctx *context.Context) {
return
}
- var issues []*models.Issue
+ var issues []*issues_model.Issue
var filteredCount int64
keyword := ctx.FormTrim("q")
@@ -2264,7 +2264,7 @@ func SearchIssues(ctx *context.Context) {
// Only fetch the issues if we either don't have a keyword or the search returned issues
// This would otherwise return all issues if no issues were found by the search.
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 || len(includedMilestones) > 0 {
- issuesOpt := &models.IssuesOptions{
+ issuesOpt := &issues_model.IssuesOptions{
ListOptions: db.ListOptions{
Page: ctx.FormInt("page"),
PageSize: limit,
@@ -2300,7 +2300,7 @@ func SearchIssues(ctx *context.Context) {
issuesOpt.ReviewRequestedID = ctxUserID
}
- if issues, err = models.Issues(issuesOpt); err != nil {
+ if issues, err = issues_model.Issues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, "Issues", err.Error())
return
}
@@ -2308,7 +2308,7 @@ func SearchIssues(ctx *context.Context) {
issuesOpt.ListOptions = db.ListOptions{
Page: -1,
}
- if filteredCount, err = models.CountIssues(issuesOpt); err != nil {
+ if filteredCount, err = issues_model.CountIssues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, "CountIssues", err.Error())
return
}
@@ -2356,7 +2356,7 @@ func ListIssues(ctx *context.Context) {
isClosed = util.OptionalBoolFalse
}
- var issues []*models.Issue
+ var issues []*issues_model.Issue
var filteredCount int64
keyword := ctx.FormTrim("q")
@@ -2374,7 +2374,7 @@ func ListIssues(ctx *context.Context) {
}
if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 {
- labelIDs, err = models.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted)
+ labelIDs, err = issues_model.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
@@ -2443,7 +2443,7 @@ func ListIssues(ctx *context.Context) {
// Only fetch the issues if we either don't have a keyword or the search returned issues
// This would otherwise return all issues if no issues were found by the search.
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
- issuesOpt := &models.IssuesOptions{
+ issuesOpt := &issues_model.IssuesOptions{
ListOptions: listOptions,
RepoID: ctx.Repo.Repository.ID,
IsClosed: isClosed,
@@ -2458,7 +2458,7 @@ func ListIssues(ctx *context.Context) {
MentionedID: mentionedByID,
}
- if issues, err = models.Issues(issuesOpt); err != nil {
+ if issues, err = issues_model.Issues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
}
@@ -2466,7 +2466,7 @@ func ListIssues(ctx *context.Context) {
issuesOpt.ListOptions = db.ListOptions{
Page: -1,
}
- if filteredCount, err = models.CountIssues(issuesOpt); err != nil {
+ if filteredCount, err = issues_model.CountIssues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
}
@@ -2493,14 +2493,14 @@ func UpdateIssueStatus(ctx *context.Context) {
log.Warn("Unrecognized action: %s", action)
}
- if _, err := models.IssueList(issues).LoadRepositories(); err != nil {
+ if _, err := issues_model.IssueList(issues).LoadRepositories(); err != nil {
ctx.ServerError("LoadRepositories", err)
return
}
for _, issue := range issues {
if issue.IsClosed != isClosed {
if err := issue_service.ChangeStatus(issue, ctx.Doer, isClosed); err != nil {
- if models.IsErrDependenciesLeft(err) {
+ if issues_model.IsErrDependenciesLeft(err) {
ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{
"error": "cannot close this issue because it still has open dependencies",
})
@@ -2564,7 +2564,7 @@ func NewComment(ctx *context.Context) {
return
}
- var comment *models.Comment
+ var comment *issues_model.Comment
defer func() {
// Check if issue admin/poster changes the status of issue.
if (ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) || (ctx.IsSigned && issue.IsPoster(ctx.Doer.ID))) &&
@@ -2572,14 +2572,14 @@ func NewComment(ctx *context.Context) {
!(issue.IsPull && issue.PullRequest.HasMerged) {
// Duplication and conflict check should apply to reopen pull request.
- var pr *models.PullRequest
+ var pr *issues_model.PullRequest
if form.Status == "reopen" && issue.IsPull {
pull := issue.PullRequest
var err error
- pr, err = models.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch, pull.Flow)
+ pr, err = issues_model.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch, pull.Flow)
if err != nil {
- if !models.IsErrPullRequestNotExist(err) {
+ if !issues_model.IsErrPullRequestNotExist(err) {
ctx.ServerError("GetUnmergedPullRequest", err)
return
}
@@ -2599,7 +2599,7 @@ func NewComment(ctx *context.Context) {
if err := issue_service.ChangeStatus(issue, ctx.Doer, isClosed); err != nil {
log.Error("ChangeStatus: %v", err)
- if models.IsErrDependenciesLeft(err) {
+ if issues_model.IsErrDependenciesLeft(err) {
if issue.IsPull {
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index))
@@ -2648,14 +2648,14 @@ func NewComment(ctx *context.Context) {
// UpdateCommentContent change comment of issue's content
func UpdateCommentContent(ctx *context.Context) {
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
+ ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
return
}
if err := comment.LoadIssue(); err != nil {
- ctx.NotFoundOrServerError("LoadIssue", models.IsErrIssueNotExist, err)
+ ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
return
}
@@ -2664,7 +2664,7 @@ func UpdateCommentContent(ctx *context.Context) {
return
}
- if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeReview && comment.Type != models.CommentTypeCode {
+ if comment.Type != issues_model.CommentTypeComment && comment.Type != issues_model.CommentTypeReview && comment.Type != issues_model.CommentTypeCode {
ctx.Error(http.StatusNoContent)
return
}
@@ -2714,21 +2714,21 @@ func UpdateCommentContent(ctx *context.Context) {
// DeleteComment delete comment of issue
func DeleteComment(ctx *context.Context) {
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
+ ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
return
}
if err := comment.LoadIssue(); err != nil {
- ctx.NotFoundOrServerError("LoadIssue", models.IsErrIssueNotExist, err)
+ ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
return
}
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
ctx.Error(http.StatusForbidden)
return
- } else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
+ } else if comment.Type != issues_model.CommentTypeComment && comment.Type != issues_model.CommentTypeCode {
ctx.Error(http.StatusNoContent)
return
}
@@ -2790,7 +2790,7 @@ func ChangeIssueReaction(ctx *context.Context) {
}
// Reload new reactions
issue.Reactions = nil
- if err = issue.LoadAttributes(); err != nil {
+ if err = issue.LoadAttributes(ctx); err != nil {
log.Info("issue.LoadAttributes: %s", err)
break
}
@@ -2804,7 +2804,7 @@ func ChangeIssueReaction(ctx *context.Context) {
// Reload new reactions
issue.Reactions = nil
- if err := issue.LoadAttributes(); err != nil {
+ if err := issue.LoadAttributes(ctx); err != nil {
log.Info("issue.LoadAttributes: %s", err)
break
}
@@ -2840,14 +2840,14 @@ func ChangeIssueReaction(ctx *context.Context) {
// ChangeCommentReaction create a reaction for comment
func ChangeCommentReaction(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.ReactionForm)
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
+ ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
return
}
if err := comment.LoadIssue(); err != nil {
- ctx.NotFoundOrServerError("LoadIssue", models.IsErrIssueNotExist, err)
+ ctx.NotFoundOrServerError("LoadIssue", issues_model.IsErrIssueNotExist, err)
return
}
@@ -2874,7 +2874,7 @@ func ChangeCommentReaction(ctx *context.Context) {
return
}
- if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode && comment.Type != models.CommentTypeReview {
+ if comment.Type != issues_model.CommentTypeComment && comment.Type != issues_model.CommentTypeCode && comment.Type != issues_model.CommentTypeReview {
ctx.Error(http.StatusNoContent)
return
}
@@ -2948,11 +2948,11 @@ func addParticipant(poster *user_model.User, participants []*user_model.User) []
return append(participants, poster)
}
-func filterXRefComments(ctx *context.Context, issue *models.Issue) error {
+func filterXRefComments(ctx *context.Context, issue *issues_model.Issue) error {
// Remove comments that the user has no permissions to see
for i := 0; i < len(issue.Comments); {
c := issue.Comments[i]
- if models.CommentTypeIsRef(c.Type) && c.RefRepoID != issue.RepoID && c.RefRepoID != 0 {
+ if issues_model.CommentTypeIsRef(c.Type) && c.RefRepoID != issue.RepoID && c.RefRepoID != 0 {
var err error
// Set RefRepo for description in template
c.RefRepo, err = repo_model.GetRepositoryByID(c.RefRepoID)
@@ -2985,13 +2985,13 @@ func GetIssueAttachments(ctx *context.Context) {
// GetCommentAttachments returns attachments for the comment
func GetCommentAttachments(ctx *context.Context) {
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
+ ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err)
return
}
attachments := make([]*api.Attachment, 0)
- if comment.Type == models.CommentTypeComment {
+ if comment.Type == issues_model.CommentTypeComment {
if err := comment.LoadAttachments(); err != nil {
ctx.ServerError("LoadAttachments", err)
return
@@ -3006,9 +3006,9 @@ func GetCommentAttachments(ctx *context.Context) {
func updateAttachments(ctx *context.Context, item interface{}, files []string) error {
var attachments []*repo_model.Attachment
switch content := item.(type) {
- case *models.Issue:
+ case *issues_model.Issue:
attachments = content.Attachments
- case *models.Comment:
+ case *issues_model.Comment:
attachments = content.Attachments
default:
return fmt.Errorf("unknown Type: %T", content)
@@ -3024,9 +3024,9 @@ func updateAttachments(ctx *context.Context, item interface{}, files []string) e
var err error
if len(files) > 0 {
switch content := item.(type) {
- case *models.Issue:
- err = models.UpdateIssueAttachments(content.ID, files)
- case *models.Comment:
+ case *issues_model.Issue:
+ err = issues_model.UpdateIssueAttachments(content.ID, files)
+ case *issues_model.Comment:
err = content.UpdateAttachments(files)
default:
return fmt.Errorf("unknown Type: %T", content)
@@ -3036,9 +3036,9 @@ func updateAttachments(ctx *context.Context, item interface{}, files []string) e
}
}
switch content := item.(type) {
- case *models.Issue:
+ case *issues_model.Issue:
content.Attachments, err = repo_model.GetAttachmentsByIssueID(ctx, content.ID)
- case *models.Comment:
+ case *issues_model.Comment:
content.Attachments, err = repo_model.GetAttachmentsByCommentID(ctx, content.ID)
default:
return fmt.Errorf("unknown Type: %T", content)
@@ -3060,17 +3060,17 @@ func attachmentsHTML(ctx *context.Context, attachments []*repo_model.Attachment,
}
// combineLabelComments combine the nearby label comments as one.
-func combineLabelComments(issue *models.Issue) {
- var prev, cur *models.Comment
+func combineLabelComments(issue *issues_model.Issue) {
+ var prev, cur *issues_model.Comment
for i := 0; i < len(issue.Comments); i++ {
cur = issue.Comments[i]
if i > 0 {
prev = issue.Comments[i-1]
}
- if i == 0 || cur.Type != models.CommentTypeLabel ||
+ if i == 0 || cur.Type != issues_model.CommentTypeLabel ||
(prev != nil && prev.PosterID != cur.PosterID) ||
(prev != nil && cur.CreatedUnix-prev.CreatedUnix >= 60) {
- if cur.Type == models.CommentTypeLabel && cur.Label != nil {
+ if cur.Type == issues_model.CommentTypeLabel && cur.Label != nil {
if cur.Content != "1" {
cur.RemovedLabels = append(cur.RemovedLabels, cur.Label)
} else {
@@ -3081,7 +3081,7 @@ func combineLabelComments(issue *models.Issue) {
}
if cur.Label != nil { // now cur MUST be label comment
- if prev.Type == models.CommentTypeLabel { // we can combine them only prev is a label comment
+ if prev.Type == issues_model.CommentTypeLabel { // we can combine them only prev is a label comment
if cur.Content != "1" {
// remove labels from the AddedLabels list if the label that was removed is already
// in this list, and if it's not in this list, add the label to RemovedLabels
diff --git a/routers/web/repo/issue_content_history.go b/routers/web/repo/issue_content_history.go
index 407832dffe..d8a21c7fd7 100644
--- a/routers/web/repo/issue_content_history.go
+++ b/routers/web/repo/issue_content_history.go
@@ -11,8 +11,7 @@ import (
"net/http"
"strings"
- "code.gitea.io/gitea/models"
- issuesModel "code.gitea.io/gitea/models/issues"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -31,7 +30,7 @@ func GetContentHistoryOverview(ctx *context.Context) {
}
lang := ctx.Locale.Language()
- editedHistoryCountMap, _ := issuesModel.QueryIssueContentHistoryEditedCountMap(ctx, issue.ID)
+ editedHistoryCountMap, _ := issues_model.QueryIssueContentHistoryEditedCountMap(ctx, issue.ID)
ctx.JSON(http.StatusOK, map[string]interface{}{
"i18n": map[string]interface{}{
"textEdited": i18n.Tr(lang, "repo.issues.content_history.edited"),
@@ -51,7 +50,7 @@ func GetContentHistoryList(ctx *context.Context) {
return
}
- items, _ := issuesModel.FetchIssueContentHistoryList(ctx, issue.ID, commentID)
+ items, _ := issues_model.FetchIssueContentHistoryList(ctx, issue.ID, commentID)
// render history list to HTML for frontend dropdown items: (name, value)
// name is HTML of "avatar + userName + userAction + timeSince"
@@ -89,8 +88,8 @@ func GetContentHistoryList(ctx *context.Context) {
// canSoftDeleteContentHistory checks whether current user can soft-delete a history revision
// Admins or owners can always delete history revisions. Normal users can only delete own history revisions.
-func canSoftDeleteContentHistory(ctx *context.Context, issue *models.Issue, comment *models.Comment,
- history *issuesModel.ContentHistory,
+func canSoftDeleteContentHistory(ctx *context.Context, issue *issues_model.Issue, comment *issues_model.Comment,
+ history *issues_model.ContentHistory,
) bool {
canSoftDelete := false
if ctx.Repo.IsOwner() {
@@ -118,7 +117,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
}
historyID := ctx.FormInt64("history_id")
- history, prevHistory, err := issuesModel.GetIssueContentHistoryAndPrev(ctx, historyID)
+ history, prevHistory, err := issues_model.GetIssueContentHistoryAndPrev(ctx, historyID)
if err != nil {
ctx.JSON(http.StatusNotFound, map[string]interface{}{
"message": "Can not find the content history",
@@ -127,10 +126,10 @@ func GetContentHistoryDetail(ctx *context.Context) {
}
// get the related comment if this history revision is for a comment, otherwise the history revision is for an issue.
- var comment *models.Comment
+ var comment *issues_model.Comment
if history.CommentID != 0 {
var err error
- if comment, err = models.GetCommentByID(ctx, history.CommentID); err != nil {
+ if comment, err = issues_model.GetCommentByID(ctx, history.CommentID); err != nil {
log.Error("can not get comment for issue content history %v. err=%v", historyID, err)
return
}
@@ -186,16 +185,16 @@ func SoftDeleteContentHistory(ctx *context.Context) {
commentID := ctx.FormInt64("comment_id")
historyID := ctx.FormInt64("history_id")
- var comment *models.Comment
- var history *issuesModel.ContentHistory
+ var comment *issues_model.Comment
+ var history *issues_model.ContentHistory
var err error
if commentID != 0 {
- if comment, err = models.GetCommentByID(ctx, commentID); err != nil {
+ if comment, err = issues_model.GetCommentByID(ctx, commentID); err != nil {
log.Error("can not get comment for issue content history %v. err=%v", historyID, err)
return
}
}
- if history, err = issuesModel.GetIssueContentHistoryByID(ctx, historyID); err != nil {
+ if history, err = issues_model.GetIssueContentHistoryByID(ctx, historyID); err != nil {
log.Error("can not get issue content history %v. err=%v", historyID, err)
return
}
@@ -208,7 +207,7 @@ func SoftDeleteContentHistory(ctx *context.Context) {
return
}
- err = issuesModel.SoftDeleteIssueContentHistory(ctx, historyID)
+ err = issues_model.SoftDeleteIssueContentHistory(ctx, historyID)
log.Debug("soft delete issue content history. issue=%d, comment=%d, history=%d", issue.ID, commentID, historyID)
ctx.JSON(http.StatusOK, map[string]interface{}{
"ok": err == nil,
diff --git a/routers/web/repo/issue_dependency.go b/routers/web/repo/issue_dependency.go
index ec713238c6..d8d934ea1c 100644
--- a/routers/web/repo/issue_dependency.go
+++ b/routers/web/repo/issue_dependency.go
@@ -7,7 +7,7 @@ package repo
import (
"net/http"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
)
@@ -15,7 +15,7 @@ import (
// AddDependency adds new dependencies
func AddDependency(ctx *context.Context) {
issueIndex := ctx.ParamsInt64("index")
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
+ issue, err := issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
if err != nil {
ctx.ServerError("GetIssueByIndex", err)
return
@@ -38,7 +38,7 @@ func AddDependency(ctx *context.Context) {
defer ctx.Redirect(issue.HTMLURL())
// Dependency
- dep, err := models.GetIssueByID(depID)
+ dep, err := issues_model.GetIssueByID(ctx, depID)
if err != nil {
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_issue_not_exist"))
return
@@ -56,12 +56,12 @@ func AddDependency(ctx *context.Context) {
return
}
- err = models.CreateIssueDependency(ctx.Doer, issue, dep)
+ err = issues_model.CreateIssueDependency(ctx.Doer, issue, dep)
if err != nil {
- if models.IsErrDependencyExists(err) {
+ if issues_model.IsErrDependencyExists(err) {
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_exists"))
return
- } else if models.IsErrCircularDependency(err) {
+ } else if issues_model.IsErrCircularDependency(err) {
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_cannot_create_circular"))
return
} else {
@@ -74,7 +74,7 @@ func AddDependency(ctx *context.Context) {
// RemoveDependency removes the dependency
func RemoveDependency(ctx *context.Context) {
issueIndex := ctx.ParamsInt64("index")
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
+ issue, err := issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, issueIndex)
if err != nil {
ctx.ServerError("GetIssueByIndex", err)
return
@@ -96,27 +96,27 @@ func RemoveDependency(ctx *context.Context) {
// Dependency Type
depTypeStr := ctx.Req.PostForm.Get("dependencyType")
- var depType models.DependencyType
+ var depType issues_model.DependencyType
switch depTypeStr {
case "blockedBy":
- depType = models.DependencyTypeBlockedBy
+ depType = issues_model.DependencyTypeBlockedBy
case "blocking":
- depType = models.DependencyTypeBlocking
+ depType = issues_model.DependencyTypeBlocking
default:
ctx.Error(http.StatusBadRequest, "GetDependecyType")
return
}
// Dependency
- dep, err := models.GetIssueByID(depID)
+ dep, err := issues_model.GetIssueByID(ctx, depID)
if err != nil {
ctx.ServerError("GetIssueByID", err)
return
}
- if err = models.RemoveIssueDependency(ctx.Doer, issue, dep, depType); err != nil {
- if models.IsErrDependencyNotExists(err) {
+ if err = issues_model.RemoveIssueDependency(ctx.Doer, issue, dep, depType); err != nil {
+ if issues_model.IsErrDependencyNotExists(err) {
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.add_error_dep_not_exist"))
return
}
diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go
index 2e72d659be..7af415a8fa 100644
--- a/routers/web/repo/issue_label.go
+++ b/routers/web/repo/issue_label.go
@@ -7,8 +7,8 @@ package repo
import (
"net/http"
- "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/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -56,7 +56,7 @@ func InitializeLabels(ctx *context.Context) {
// RetrieveLabels find all the labels of a repository and organization
func RetrieveLabels(ctx *context.Context) {
- labels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), db.ListOptions{})
+ labels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("RetrieveLabels.GetLabels", err)
return
@@ -69,7 +69,7 @@ func RetrieveLabels(ctx *context.Context) {
ctx.Data["Labels"] = labels
if ctx.Repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
+ orgLabels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Repo.Owner.ID, ctx.FormString("sort"), db.ListOptions{})
if err != nil {
ctx.ServerError("GetLabelsByOrgID", err)
return
@@ -111,13 +111,13 @@ func NewLabel(ctx *context.Context) {
return
}
- l := &models.Label{
+ l := &issues_model.Label{
RepoID: ctx.Repo.Repository.ID,
Name: form.Title,
Description: form.Description,
Color: form.Color,
}
- if err := models.NewLabel(ctx, l); err != nil {
+ if err := issues_model.NewLabel(ctx, l); err != nil {
ctx.ServerError("NewLabel", err)
return
}
@@ -127,10 +127,10 @@ func NewLabel(ctx *context.Context) {
// UpdateLabel update a label's name and color
func UpdateLabel(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.CreateLabelForm)
- l, err := models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, form.ID)
+ l, err := issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, form.ID)
if err != nil {
switch {
- case models.IsErrRepoLabelNotExist(err):
+ case issues_model.IsErrRepoLabelNotExist(err):
ctx.Error(http.StatusNotFound)
default:
ctx.ServerError("UpdateLabel", err)
@@ -141,7 +141,7 @@ func UpdateLabel(ctx *context.Context) {
l.Name = form.Title
l.Description = form.Description
l.Color = form.Color
- if err := models.UpdateLabel(l); err != nil {
+ if err := issues_model.UpdateLabel(l); err != nil {
ctx.ServerError("UpdateLabel", err)
return
}
@@ -150,7 +150,7 @@ func UpdateLabel(ctx *context.Context) {
// DeleteLabel delete a label
func DeleteLabel(ctx *context.Context) {
- if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
+ if err := issues_model.DeleteLabel(ctx.Repo.Repository.ID, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeleteLabel: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("repo.issues.label_deletion_success"))
@@ -177,9 +177,9 @@ func UpdateIssueLabel(ctx *context.Context) {
}
}
case "attach", "detach", "toggle":
- label, err := models.GetLabelByID(ctx, ctx.FormInt64("id"))
+ label, err := issues_model.GetLabelByID(ctx, ctx.FormInt64("id"))
if err != nil {
- if models.IsErrRepoLabelNotExist(err) {
+ if issues_model.IsErrRepoLabelNotExist(err) {
ctx.Error(http.StatusNotFound, "GetLabelByID")
} else {
ctx.ServerError("GetLabelByID", err)
@@ -191,7 +191,7 @@ func UpdateIssueLabel(ctx *context.Context) {
// detach if any issues already have label, otherwise attach
action = "attach"
for _, issue := range issues {
- if models.HasIssueLabel(ctx, issue.ID, label.ID) {
+ if issues_model.HasIssueLabel(ctx, issue.ID, label.ID) {
action = "detach"
break
}
diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go
index 5d7a29ee93..ea078e215c 100644
--- a/routers/web/repo/issue_label_test.go
+++ b/routers/web/repo/issue_label_test.go
@@ -9,7 +9,7 @@ import (
"strconv"
"testing"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
@@ -37,7 +37,7 @@ func TestInitializeLabels(t *testing.T) {
web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"})
InitializeLabels(ctx)
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
- unittest.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &issues_model.Label{
RepoID: 2,
Name: "enhancement",
Color: "#84b6eb",
@@ -62,7 +62,7 @@ func TestRetrieveLabels(t *testing.T) {
ctx.Req.Form.Set("sort", testCase.Sort)
RetrieveLabels(ctx)
assert.False(t, ctx.Written())
- labels, ok := ctx.Data["Labels"].([]*models.Label)
+ labels, ok := ctx.Data["Labels"].([]*issues_model.Label)
assert.True(t, ok)
if assert.Len(t, labels, len(testCase.ExpectedLabelIDs)) {
for i, label := range labels {
@@ -83,7 +83,7 @@ func TestNewLabel(t *testing.T) {
})
NewLabel(ctx)
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
- unittest.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &issues_model.Label{
Name: "newlabel",
Color: "#abcdef",
})
@@ -102,7 +102,7 @@ func TestUpdateLabel(t *testing.T) {
})
UpdateLabel(ctx)
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
- unittest.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &issues_model.Label{
ID: 2,
Name: "newnameforlabel",
Color: "#abcdef",
@@ -118,8 +118,8 @@ func TestDeleteLabel(t *testing.T) {
ctx.Req.Form.Set("id", "2")
DeleteLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- unittest.AssertNotExistsBean(t, &models.Label{ID: 2})
- unittest.AssertNotExistsBean(t, &models.IssueLabel{LabelID: 2})
+ unittest.AssertNotExistsBean(t, &issues_model.Label{ID: 2})
+ unittest.AssertNotExistsBean(t, &issues_model.IssueLabel{LabelID: 2})
assert.Equal(t, ctx.Tr("repo.issues.label_deletion_success"), ctx.Flash.SuccessMsg)
}
@@ -132,9 +132,9 @@ func TestUpdateIssueLabel_Clear(t *testing.T) {
ctx.Req.Form.Set("action", "clear")
UpdateIssueLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- unittest.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 1})
- unittest.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 3})
- unittest.CheckConsistencyFor(t, &models.Label{})
+ unittest.AssertNotExistsBean(t, &issues_model.IssueLabel{IssueID: 1})
+ unittest.AssertNotExistsBean(t, &issues_model.IssueLabel{IssueID: 3})
+ unittest.CheckConsistencyFor(t, &issues_model.Label{})
}
func TestUpdateIssueLabel_Toggle(t *testing.T) {
@@ -159,11 +159,11 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) {
UpdateIssueLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
for _, issueID := range testCase.IssueIDs {
- unittest.AssertExistsIf(t, testCase.ExpectedAdd, &models.IssueLabel{
+ unittest.AssertExistsIf(t, testCase.ExpectedAdd, &issues_model.IssueLabel{
IssueID: issueID,
LabelID: testCase.LabelID,
})
}
- unittest.CheckConsistencyFor(t, &models.Label{})
+ unittest.CheckConsistencyFor(t, &issues_model.Label{})
}
}
diff --git a/routers/web/repo/issue_lock.go b/routers/web/repo/issue_lock.go
index 5ac5cac52e..a89ea47571 100644
--- a/routers/web/repo/issue_lock.go
+++ b/routers/web/repo/issue_lock.go
@@ -5,7 +5,7 @@
package repo
import (
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
@@ -32,7 +32,7 @@ func LockIssue(ctx *context.Context) {
return
}
- if err := models.LockIssue(&models.IssueLockOptions{
+ if err := issues_model.LockIssue(&issues_model.IssueLockOptions{
Doer: ctx.Doer,
Issue: issue,
Reason: form.Reason,
@@ -57,7 +57,7 @@ func UnlockIssue(ctx *context.Context) {
return
}
- if err := models.UnlockIssue(&models.IssueLockOptions{
+ if err := issues_model.UnlockIssue(&issues_model.IssueLockOptions{
Doer: ctx.Doer,
Issue: issue,
}); err != nil {
diff --git a/routers/web/repo/issue_stopwatch.go b/routers/web/repo/issue_stopwatch.go
index 4e1f6af039..68f89b258d 100644
--- a/routers/web/repo/issue_stopwatch.go
+++ b/routers/web/repo/issue_stopwatch.go
@@ -8,8 +8,8 @@ import (
"net/http"
"strings"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/eventsource"
)
@@ -23,7 +23,7 @@ func IssueStopwatch(c *context.Context) {
var showSuccessMessage bool
- if !models.StopwatchExists(c.Doer.ID, issue.ID) {
+ if !issues_model.StopwatchExists(c.Doer.ID, issue.ID) {
showSuccessMessage = true
}
@@ -32,7 +32,7 @@ func IssueStopwatch(c *context.Context) {
return
}
- if err := models.CreateOrStopIssueStopwatch(c.Doer, issue); err != nil {
+ if err := issues_model.CreateOrStopIssueStopwatch(c.Doer, issue); err != nil {
c.ServerError("CreateOrStopIssueStopwatch", err)
return
}
@@ -56,12 +56,12 @@ func CancelStopwatch(c *context.Context) {
return
}
- if err := models.CancelStopwatch(c.Doer, issue); err != nil {
+ if err := issues_model.CancelStopwatch(c.Doer, issue); err != nil {
c.ServerError("CancelStopwatch", err)
return
}
- stopwatches, err := models.GetUserStopwatches(c.Doer.ID, db.ListOptions{})
+ stopwatches, err := issues_model.GetUserStopwatches(c.Doer.ID, db.ListOptions{})
if err != nil {
c.ServerError("GetUserStopwatches", err)
return
@@ -87,7 +87,7 @@ func GetActiveStopwatch(ctx *context.Context) {
return
}
- _, sw, err := models.HasUserStopwatch(ctx, ctx.Doer.ID)
+ _, sw, err := issues_model.HasUserStopwatch(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("HasUserStopwatch", err)
return
@@ -97,7 +97,7 @@ func GetActiveStopwatch(ctx *context.Context) {
return
}
- issue, err := models.GetIssueByID(sw.IssueID)
+ issue, err := issues_model.GetIssueByID(ctx, sw.IssueID)
if err != nil || issue == nil {
ctx.ServerError("GetIssueByID", err)
return
diff --git a/routers/web/repo/issue_test.go b/routers/web/repo/issue_test.go
index debd2a8a3c..ad82fe0f36 100644
--- a/routers/web/repo/issue_test.go
+++ b/routers/web/repo/issue_test.go
@@ -7,7 +7,7 @@ package repo
import (
"testing"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"github.com/stretchr/testify/assert"
)
@@ -15,50 +15,50 @@ import (
func TestCombineLabelComments(t *testing.T) {
kases := []struct {
name string
- beforeCombined []*models.Comment
- afterCombined []*models.Comment
+ beforeCombined []*issues_model.Comment
+ afterCombined []*issues_model.Comment
}{
{
name: "kase 1",
- beforeCombined: []*models.Comment{
+ beforeCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
- afterCombined: []*models.Comment{
+ afterCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
CreatedUnix: 0,
- AddedLabels: []*models.Label{},
- Label: &models.Label{
+ AddedLabels: []*issues_model.Label{},
+ Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
@@ -67,63 +67,63 @@ func TestCombineLabelComments(t *testing.T) {
},
{
name: "kase 2",
- beforeCombined: []*models.Comment{
+ beforeCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 70,
},
{
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
- afterCombined: []*models.Comment{
+ afterCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
CreatedUnix: 0,
- AddedLabels: []*models.Label{
+ AddedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
CreatedUnix: 70,
- RemovedLabels: []*models.Label{
+ RemovedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
@@ -132,63 +132,63 @@ func TestCombineLabelComments(t *testing.T) {
},
{
name: "kase 3",
- beforeCombined: []*models.Comment{
+ beforeCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 2,
Content: "",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
},
},
- afterCombined: []*models.Comment{
+ afterCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
CreatedUnix: 0,
- AddedLabels: []*models.Label{
+ AddedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 2,
Content: "",
CreatedUnix: 0,
- RemovedLabels: []*models.Label{
+ RemovedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
},
{
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
PosterID: 1,
Content: "test",
CreatedUnix: 0,
@@ -197,33 +197,33 @@ func TestCombineLabelComments(t *testing.T) {
},
{
name: "kase 4",
- beforeCombined: []*models.Comment{
+ beforeCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/backport",
},
CreatedUnix: 10,
},
},
- afterCombined: []*models.Comment{
+ afterCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
CreatedUnix: 10,
- AddedLabels: []*models.Label{
+ AddedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
@@ -231,7 +231,7 @@ func TestCombineLabelComments(t *testing.T) {
Name: "kind/backport",
},
},
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
},
@@ -239,41 +239,41 @@ func TestCombineLabelComments(t *testing.T) {
},
{
name: "kase 5",
- beforeCombined: []*models.Comment{
+ beforeCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
PosterID: 2,
Content: "testtest",
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
},
- afterCombined: []*models.Comment{
+ afterCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
- AddedLabels: []*models.Label{
+ AddedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
@@ -281,21 +281,21 @@ func TestCombineLabelComments(t *testing.T) {
CreatedUnix: 0,
},
{
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
PosterID: 2,
Content: "testtest",
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
- RemovedLabels: []*models.Label{
+ RemovedLabels: []*issues_model.Label{
{
Name: "kind/bug",
},
},
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
@@ -304,53 +304,53 @@ func TestCombineLabelComments(t *testing.T) {
},
{
name: "kase 6",
- beforeCombined: []*models.Comment{
+ beforeCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "reviewed/confirmed",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
CreatedUnix: 0,
},
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/feature",
},
CreatedUnix: 0,
},
},
- afterCombined: []*models.Comment{
+ afterCombined: []*issues_model.Comment{
{
- Type: models.CommentTypeLabel,
+ Type: issues_model.CommentTypeLabel,
PosterID: 1,
Content: "1",
- Label: &models.Label{
+ Label: &issues_model.Label{
Name: "kind/bug",
},
- AddedLabels: []*models.Label{
+ AddedLabels: []*issues_model.Label{
{
Name: "reviewed/confirmed",
},
@@ -366,7 +366,7 @@ func TestCombineLabelComments(t *testing.T) {
for _, kase := range kases {
t.Run(kase.name, func(t *testing.T) {
- issue := models.Issue{
+ issue := issues_model.Issue{
Comments: kase.beforeCombined,
}
combineLabelComments(&issue)
diff --git a/routers/web/repo/issue_timetrack.go b/routers/web/repo/issue_timetrack.go
index 28274a7f7b..817a2c6d20 100644
--- a/routers/web/repo/issue_timetrack.go
+++ b/routers/web/repo/issue_timetrack.go
@@ -8,8 +8,8 @@ import (
"net/http"
"time"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
@@ -43,7 +43,7 @@ func AddTimeManually(c *context.Context) {
return
}
- if _, err := models.AddTime(c.Doer, issue, int64(total.Seconds()), time.Now()); err != nil {
+ if _, err := issues_model.AddTime(c.Doer, issue, int64(total.Seconds()), time.Now()); err != nil {
c.ServerError("AddTime", err)
return
}
@@ -62,7 +62,7 @@ func DeleteTime(c *context.Context) {
return
}
- t, err := models.GetTrackedTimeByID(c.ParamsInt64(":timeid"))
+ t, err := issues_model.GetTrackedTimeByID(c.ParamsInt64(":timeid"))
if err != nil {
if db.IsErrNotExist(err) {
c.NotFound("time not found", err)
@@ -78,7 +78,7 @@ func DeleteTime(c *context.Context) {
return
}
- if err = models.DeleteTime(t); err != nil {
+ if err = issues_model.DeleteTime(t); err != nil {
c.ServerError("DeleteTime", err)
return
}
diff --git a/routers/web/repo/issue_watch.go b/routers/web/repo/issue_watch.go
index 53fec11cdc..5210ecf777 100644
--- a/routers/web/repo/issue_watch.go
+++ b/routers/web/repo/issue_watch.go
@@ -8,7 +8,7 @@ import (
"net/http"
"strconv"
- "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"
)
@@ -48,7 +48,7 @@ func IssueWatch(ctx *context.Context) {
return
}
- if err := models.CreateOrUpdateIssueWatch(ctx.Doer.ID, issue.ID, watch); err != nil {
+ if err := issues_model.CreateOrUpdateIssueWatch(ctx.Doer.ID, issue.ID, watch); err != nil {
ctx.ServerError("CreateOrUpdateIssueWatch", err)
return
}
diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go
index c1805944db..51c891dbf0 100644
--- a/routers/web/repo/projects.go
+++ b/routers/web/repo/projects.go
@@ -10,7 +10,7 @@ import (
"net/url"
"strings"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/perm"
project_model "code.gitea.io/gitea/models/project"
"code.gitea.io/gitea/models/unit"
@@ -296,13 +296,13 @@ func ViewProject(ctx *context.Context) {
boards[0].Title = ctx.Tr("repo.projects.type.uncategorized")
}
- issuesMap, err := models.LoadIssuesFromBoardList(boards)
+ issuesMap, err := issues_model.LoadIssuesFromBoardList(boards)
if err != nil {
ctx.ServerError("LoadIssuesOfBoards", err)
return
}
- linkedPrsMap := make(map[int64][]*models.Issue)
+ linkedPrsMap := make(map[int64][]*issues_model.Issue)
for _, issuesList := range issuesMap {
for _, issue := range issuesList {
var referencedIds []int64
@@ -313,7 +313,7 @@ func ViewProject(ctx *context.Context) {
}
if len(referencedIds) > 0 {
- if linkedPrs, err := models.Issues(&models.IssuesOptions{
+ if linkedPrs, err := issues_model.Issues(&issues_model.IssuesOptions{
IssueIDs: referencedIds,
IsPull: util.OptionalBoolTrue,
}); err == nil {
@@ -358,7 +358,7 @@ func UpdateIssueProject(ctx *context.Context) {
continue
}
- if err := models.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil {
+ if err := issues_model.ChangeProjectAssign(issue, ctx.Doer, projectID); err != nil {
ctx.ServerError("ChangeProjectAssign", err)
return
}
@@ -622,9 +622,9 @@ func MoveIssues(ctx *context.Context) {
issueIDs = append(issueIDs, issue.IssueID)
sortedIssueIDs[issue.Sorting] = issue.IssueID
}
- movedIssues, err := models.GetIssuesByIDs(ctx, issueIDs)
+ movedIssues, err := issues_model.GetIssuesByIDs(ctx, issueIDs)
if err != nil {
- if models.IsErrIssueNotExist(err) {
+ if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("IssueNotExisting", nil)
} else {
ctx.ServerError("GetIssueByID", err)
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index c1a59ca8c0..6e8f575ad5 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -19,6 +19,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"
"code.gitea.io/gitea/models/organization"
access_model "code.gitea.io/gitea/models/perm/access"
pull_model "code.gitea.io/gitea/models/pull"
@@ -256,10 +257,10 @@ func ForkPost(ctx *context.Context) {
ctx.Redirect(ctxUser.HomeLink() + "/" + url.PathEscape(repo.Name))
}
-func checkPullInfo(ctx *context.Context) *models.Issue {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func checkPullInfo(ctx *context.Context) *issues_model.Issue {
+ issue, err := issues_model.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
+ if issues_model.IsErrIssueNotExist(err) {
ctx.NotFound("GetIssueByIndex", err)
} else {
ctx.ServerError("GetIssueByIndex", err)
@@ -294,7 +295,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
if ctx.IsSigned {
// Update issue-user.
- if err = issue.ReadBy(ctx, ctx.Doer.ID); err != nil {
+ if err = models.SetIssueReadBy(ctx, issue.ID, ctx.Doer.ID); err != nil {
ctx.ServerError("ReadBy", err)
return nil
}
@@ -303,7 +304,7 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
return issue
}
-func setMergeTarget(ctx *context.Context, pull *models.PullRequest) {
+func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
if ctx.Repo.Owner.Name == pull.MustHeadUserName() {
ctx.Data["HeadTarget"] = pull.HeadBranch
} else if pull.HeadRepo == nil {
@@ -317,7 +318,7 @@ func setMergeTarget(ctx *context.Context, pull *models.PullRequest) {
}
// PrepareMergedViewPullInfo show meta information for a merged pull request view page
-func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
+func PrepareMergedViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.CompareInfo {
pull := issue.PullRequest
setMergeTarget(ctx, pull)
@@ -395,7 +396,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
}
// PrepareViewPullInfo show meta information for a pull request preview page
-func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.CompareInfo {
+func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.CompareInfo {
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
repo := ctx.Repo.Repository
@@ -482,14 +483,14 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
}
defer headGitRepo.Close()
- if pull.Flow == models.PullRequestFlowGithub {
+ if pull.Flow == issues_model.PullRequestFlowGithub {
headBranchExist = headGitRepo.IsBranchExist(pull.HeadBranch)
} else {
headBranchExist = git.IsReferenceExist(ctx, baseGitRepo.Path, pull.GetGitRefName())
}
if headBranchExist {
- if pull.Flow != models.PullRequestFlowGithub {
+ if pull.Flow != issues_model.PullRequestFlowGithub {
headBranchSha, err = baseGitRepo.GetRefCommitID(pull.GetGitRefName())
} else {
headBranchSha, err = headGitRepo.GetBranchCommitID(pull.HeadBranch)
@@ -752,7 +753,7 @@ func ViewPullFiles(ctx *context.Context) {
}
if ctx.IsSigned && ctx.Doer != nil {
- if ctx.Data["CanMarkConversation"], err = models.CanMarkConversation(issue, ctx.Doer); err != nil {
+ if ctx.Data["CanMarkConversation"], err = issues_model.CanMarkConversation(issue, ctx.Doer); err != nil {
ctx.ServerError("CanMarkConversation", err)
return
}
@@ -770,15 +771,15 @@ func ViewPullFiles(ctx *context.Context) {
return
}
- currentReview, err := models.GetCurrentReview(ctx, ctx.Doer, issue)
- if err != nil && !models.IsErrReviewNotExist(err) {
+ currentReview, err := issues_model.GetCurrentReview(ctx, ctx.Doer, issue)
+ if err != nil && !issues_model.IsErrReviewNotExist(err) {
ctx.ServerError("GetCurrentReview", err)
return
}
numPendingCodeComments := int64(0)
if currentReview != nil {
- numPendingCodeComments, err = models.CountComments(&models.FindCommentsOptions{
- Type: models.CommentTypeCode,
+ numPendingCodeComments, err = issues_model.CountComments(&issues_model.FindCommentsOptions{
+ Type: issues_model.CommentTypeCode,
ReviewID: currentReview.ID,
IssueID: issue.ID,
})
@@ -1062,7 +1063,7 @@ func MergePullRequest(ctx *context.Context) {
if form.DeleteBranchAfterMerge {
// Don't cleanup when other pr use this branch as head branch
- exist, err := models.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
+ exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
if err != nil {
ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
return
@@ -1109,9 +1110,9 @@ func CancelAutoMergePullRequest(ctx *context.Context) {
ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index))
}
-func stopTimerIfAvailable(user *user_model.User, issue *models.Issue) error {
- if models.StopwatchExists(user.ID, issue.ID) {
- if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil {
+func stopTimerIfAvailable(user *user_model.User, issue *issues_model.Issue) error {
+ if issues_model.StopwatchExists(user.ID, issue.ID) {
+ if err := issues_model.CreateOrStopIssueStopwatch(user, issue); err != nil {
return err
}
}
@@ -1190,7 +1191,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
return
}
- pullIssue := &models.Issue{
+ pullIssue := &issues_model.Issue{
RepoID: repo.ID,
Repo: repo,
Title: form.Title,
@@ -1200,7 +1201,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
IsPull: true,
Content: form.Content,
}
- pullRequest := &models.PullRequest{
+ pullRequest := &issues_model.PullRequest{
HeadRepoID: ci.HeadRepo.ID,
BaseRepoID: repo.ID,
HeadBranch: ci.HeadBranch,
@@ -1208,14 +1209,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
HeadRepo: ci.HeadRepo,
BaseRepo: repo,
MergeBase: ci.CompareInfo.MergeBase,
- Type: models.PullRequestGitea,
+ Type: issues_model.PullRequestGitea,
AllowMaintainerEdit: form.AllowMaintainerEdit,
}
// FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
// instead of 500.
if err := pull_service.NewPullRequest(ctx, repo, pullIssue, labelIDs, attachments, pullRequest, assigneeIDs); err != nil {
- if models.IsErrUserDoesNotHaveAccessToRepo(err) {
+ if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
return
} else if git.IsErrPushRejected(err) {
@@ -1262,7 +1263,7 @@ func CleanUpPullRequest(ctx *context.Context) {
}
// Don't cleanup when there are other PR's that use this branch as head branch.
- exist, err := models.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
+ exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(ctx, pr.HeadRepoID, pr.HeadBranch)
if err != nil {
ctx.ServerError("HasUnmergedPullRequestsByHeadInfo", err)
return
@@ -1356,7 +1357,7 @@ func CleanUpPullRequest(ctx *context.Context) {
deleteBranch(ctx, pr, gitRepo)
}
-func deleteBranch(ctx *context.Context, pr *models.PullRequest, gitRepo *git.Repository) {
+func deleteBranch(ctx *context.Context, pr *issues_model.PullRequest, gitRepo *git.Repository) {
fullBranchName := pr.HeadRepo.Owner.Name + "/" + pr.HeadBranch
if err := repo_service.DeleteBranch(ctx.Doer, pr.HeadRepo, gitRepo, pr.HeadBranch); err != nil {
switch {
@@ -1373,7 +1374,7 @@ func deleteBranch(ctx *context.Context, pr *models.PullRequest, gitRepo *git.Rep
return
}
- if err := models.AddDeletePRBranchComment(ctx, ctx.Doer, pr.BaseRepo, pr.IssueID, pr.HeadBranch); err != nil {
+ if err := issues_model.AddDeletePRBranchComment(ctx, ctx.Doer, pr.BaseRepo, pr.IssueID, pr.HeadBranch); err != nil {
// Do not fail here as branch has already been deleted
log.Error("DeleteBranch: %v", err)
}
@@ -1393,9 +1394,9 @@ func DownloadPullPatch(ctx *context.Context) {
// DownloadPullDiffOrPatch render a pull's raw diff or patch
func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
- pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrPullRequestNotExist(err) {
+ if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err)
} else {
ctx.ServerError("GetPullRequestByIndex", err)
@@ -1435,8 +1436,8 @@ func UpdatePullRequestTarget(ctx *context.Context) {
}
if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.Doer, targetBranch); err != nil {
- if models.IsErrPullRequestAlreadyExists(err) {
- err := err.(models.ErrPullRequestAlreadyExists)
+ if issues_model.IsErrPullRequestAlreadyExists(err) {
+ err := err.(issues_model.ErrPullRequestAlreadyExists)
RepoRelPath := ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name
errorMessage := ctx.Tr("repo.pulls.has_pull_request", html.EscapeString(ctx.Repo.RepoLink+"/pulls/"+strconv.FormatInt(err.IssueID, 10)), html.EscapeString(RepoRelPath), err.IssueID) // FIXME: Creates url insidde locale string
@@ -1446,7 +1447,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
"error": err.Error(),
"user_error": errorMessage,
})
- } else if models.IsErrIssueIsClosed(err) {
+ } else if issues_model.IsErrIssueIsClosed(err) {
errorMessage := ctx.Tr("repo.pulls.is_closed")
ctx.Flash.Error(errorMessage)
@@ -1486,9 +1487,9 @@ func UpdatePullRequestTarget(ctx *context.Context) {
func SetAllowEdits(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.UpdateAllowEditsForm)
- pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ pr, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrPullRequestNotExist(err) {
+ if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound("GetPullRequestByIndex", err)
} else {
ctx.ServerError("GetPullRequestByIndex", err)
diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go
index e051290200..cc7ae9bbfa 100644
--- a/routers/web/repo/pull_review.go
+++ b/routers/web/repo/pull_review.go
@@ -8,7 +8,7 @@ import (
"fmt"
"net/http"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
pull_model "code.gitea.io/gitea/models/pull"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
@@ -31,8 +31,8 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
if !issue.IsPull {
return
}
- currentReview, err := models.GetCurrentReview(ctx, ctx.Doer, issue)
- if err != nil && !models.IsErrReviewNotExist(err) {
+ currentReview, err := issues_model.GetCurrentReview(ctx, ctx.Doer, issue)
+ if err != nil && !issues_model.IsErrReviewNotExist(err) {
ctx.ServerError("GetCurrentReview", err)
return
}
@@ -107,7 +107,7 @@ func UpdateResolveConversation(ctx *context.Context) {
action := ctx.FormString("action")
commentID := ctx.FormInt64("comment_id")
- comment, err := models.GetCommentByID(ctx, commentID)
+ comment, err := issues_model.GetCommentByID(ctx, commentID)
if err != nil {
ctx.ServerError("GetIssueByID", err)
return
@@ -119,7 +119,7 @@ func UpdateResolveConversation(ctx *context.Context) {
}
var permResult bool
- if permResult, err = models.CanMarkConversation(comment.Issue, ctx.Doer); err != nil {
+ if permResult, err = issues_model.CanMarkConversation(comment.Issue, ctx.Doer); err != nil {
ctx.ServerError("CanMarkConversation", err)
return
}
@@ -134,7 +134,7 @@ func UpdateResolveConversation(ctx *context.Context) {
}
if action == "Resolve" || action == "UnResolve" {
- err = models.MarkConversation(comment, ctx.Doer, action == "Resolve")
+ err = issues_model.MarkConversation(comment, ctx.Doer, action == "Resolve")
if err != nil {
ctx.ServerError("MarkConversation", err)
return
@@ -153,8 +153,8 @@ func UpdateResolveConversation(ctx *context.Context) {
})
}
-func renderConversation(ctx *context.Context, comment *models.Comment) {
- comments, err := models.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line)
+func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
+ comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line)
if err != nil {
ctx.ServerError("FetchCodeCommentsByLine", err)
return
@@ -194,15 +194,15 @@ func SubmitReview(ctx *context.Context) {
reviewType := form.ReviewType()
switch reviewType {
- case models.ReviewTypeUnknown:
+ case issues_model.ReviewTypeUnknown:
ctx.ServerError("ReviewType", fmt.Errorf("unknown ReviewType: %s", form.Type))
return
// can not approve/reject your own PR
- case models.ReviewTypeApprove, models.ReviewTypeReject:
+ case issues_model.ReviewTypeApprove, issues_model.ReviewTypeReject:
if issue.IsPoster(ctx.Doer.ID) {
var translated string
- if reviewType == models.ReviewTypeApprove {
+ if reviewType == issues_model.ReviewTypeApprove {
translated = ctx.Tr("repo.issues.review.self.approval")
} else {
translated = ctx.Tr("repo.issues.review.self.rejection")
@@ -221,7 +221,7 @@ func SubmitReview(ctx *context.Context) {
_, comm, err := pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, issue, reviewType, form.Content, form.CommitID, attachments)
if err != nil {
- if models.IsContentEmptyErr(err) {
+ if issues_model.IsContentEmptyErr(err) {
ctx.Flash.Error(ctx.Tr("repo.issues.review.content.empty"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
} else {
diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index 9b4fc652f1..7fe80a2a4b 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -385,17 +385,17 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
viewType = ctx.FormString("type")
switch viewType {
case "assigned":
- filterMode = models.FilterModeAssign
+ filterMode = issues_model.FilterModeAssign
case "created_by":
- filterMode = models.FilterModeCreate
+ filterMode = issues_model.FilterModeCreate
case "mentioned":
- filterMode = models.FilterModeMention
+ filterMode = issues_model.FilterModeMention
case "review_requested":
- filterMode = models.FilterModeReviewRequested
+ filterMode = issues_model.FilterModeReviewRequested
case "your_repositories":
fallthrough
default:
- filterMode = models.FilterModeYourRepositories
+ filterMode = issues_model.FilterModeYourRepositories
viewType = "your_repositories"
}
@@ -416,7 +416,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
}
isPullList := unitType == unit.TypePullRequests
- opts := &models.IssuesOptions{
+ opts := &issues_model.IssuesOptions{
IsPull: util.OptionalBoolOf(isPullList),
SortType: sortType,
IsArchived: util.OptionalBoolFalse,
@@ -450,15 +450,15 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
}
switch filterMode {
- case models.FilterModeAll:
- case models.FilterModeYourRepositories:
- case models.FilterModeAssign:
+ case issues_model.FilterModeAll:
+ case issues_model.FilterModeYourRepositories:
+ case issues_model.FilterModeAssign:
opts.AssigneeID = ctx.Doer.ID
- case models.FilterModeCreate:
+ case issues_model.FilterModeCreate:
opts.PosterID = ctx.Doer.ID
- case models.FilterModeMention:
+ case issues_model.FilterModeMention:
opts.MentionedID = ctx.Doer.ID
- case models.FilterModeReviewRequested:
+ case issues_model.FilterModeReviewRequested:
opts.ReviewRequestedID = ctx.Doer.ID
}
@@ -491,7 +491,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// USING NON-FINAL STATE OF opts FOR A QUERY.
var issueCountByRepo map[int64]int64
if !forceEmpty {
- issueCountByRepo, err = models.CountIssuesByRepo(opts)
+ issueCountByRepo, err = issues_model.CountIssuesByRepo(opts)
if err != nil {
ctx.ServerError("CountIssuesByRepo", err)
return
@@ -532,15 +532,15 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// Slice of Issues that will be displayed on the overview page
// USING FINAL STATE OF opts FOR A QUERY.
- var issues []*models.Issue
+ var issues []*issues_model.Issue
if !forceEmpty {
- issues, err = models.Issues(opts)
+ issues, err = issues_model.Issues(opts)
if err != nil {
ctx.ServerError("Issues", err)
return
}
} else {
- issues = []*models.Issue{}
+ issues = []*issues_model.Issue{}
}
// ----------------------------------
@@ -578,9 +578,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// -------------------------------
// Fill stats to post to ctx.Data.
// -------------------------------
- var issueStats *models.IssueStats
+ var issueStats *issues_model.IssueStats
if !forceEmpty {
- statsOpts := models.UserIssueStatsOptions{
+ statsOpts := issues_model.UserIssueStatsOptions{
UserID: ctx.Doer.ID,
FilterMode: filterMode,
IsPull: isPullList,
@@ -592,13 +592,13 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
Team: team,
}
- issueStats, err = models.GetUserIssueStats(statsOpts)
+ issueStats, err = issues_model.GetUserIssueStats(statsOpts)
if err != nil {
ctx.ServerError("GetUserIssueStats Shown", err)
return
}
} else {
- issueStats = &models.IssueStats{}
+ issueStats = &issues_model.IssueStats{}
}
// Will be posted to ctx.Data.
@@ -623,7 +623,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
ctx.Data["Issues"] = issues
- approvalCounts, err := models.IssueList(issues).GetApprovalCounts(ctx)
+ approvalCounts, err := issues_model.IssueList(issues).GetApprovalCounts(ctx)
if err != nil {
ctx.ServerError("ApprovalCounts", err)
return
@@ -633,11 +633,11 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
if !ok || len(counts) == 0 {
return 0
}
- reviewTyp := models.ReviewTypeApprove
+ reviewTyp := issues_model.ReviewTypeApprove
if typ == "reject" {
- reviewTyp = models.ReviewTypeReject
+ reviewTyp = issues_model.ReviewTypeReject
} else if typ == "waiting" {
- reviewTyp = models.ReviewTypeRequest
+ reviewTyp = issues_model.ReviewTypeRequest
}
for _, count := range counts {
if count.Type == reviewTyp {
@@ -708,12 +708,12 @@ func getRepoIDs(reposQuery string) []int64 {
return repoIDs
}
-func issueIDsFromSearch(ctx *context.Context, ctxUser *user_model.User, keyword string, opts *models.IssuesOptions) ([]int64, error) {
+func issueIDsFromSearch(ctx *context.Context, ctxUser *user_model.User, keyword string, opts *issues_model.IssuesOptions) ([]int64, error) {
if len(keyword) == 0 {
return []int64{}, nil
}
- searchRepoIDs, err := models.GetRepoIDsForIssuesOptions(opts, ctxUser)
+ searchRepoIDs, err := issues_model.GetRepoIDsForIssuesOptions(opts, ctxUser)
if err != nil {
return nil, fmt.Errorf("GetRepoIDsForIssuesOptions: %v", err)
}
diff --git a/routers/web/user/stop_watch.go b/routers/web/user/stop_watch.go
index 4b16c9aeda..f40d850fc1 100644
--- a/routers/web/user/stop_watch.go
+++ b/routers/web/user/stop_watch.go
@@ -7,15 +7,15 @@ package user
import (
"net/http"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
)
// GetStopwatches get all stopwatches
func GetStopwatches(ctx *context.Context) {
- sws, err := models.GetUserStopwatches(ctx.Doer.ID, db.ListOptions{
+ sws, err := issues_model.GetUserStopwatches(ctx.Doer.ID, db.ListOptions{
Page: ctx.FormInt("page"),
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
})
@@ -24,7 +24,7 @@ func GetStopwatches(ctx *context.Context) {
return
}
- count, err := models.CountUserStopwatches(ctx.Doer.ID)
+ count, err := issues_model.CountUserStopwatches(ctx.Doer.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return