aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
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/api/v1/repo
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/api/v1/repo')
-rw-r--r--routers/api/v1/repo/file.go6
-rw-r--r--routers/api/v1/repo/issue.go59
-rw-r--r--routers/api/v1/repo/issue_comment.go66
-rw-r--r--routers/api/v1/repo/issue_label.go32
-rw-r--r--routers/api/v1/repo/issue_reaction.go17
-rw-r--r--routers/api/v1/repo/issue_stopwatch.go20
-rw-r--r--routers/api/v1/repo/issue_subscription.go24
-rw-r--r--routers/api/v1/repo/issue_tracked_time.go48
-rw-r--r--routers/api/v1/repo/label.go30
-rw-r--r--routers/api/v1/repo/patch.go3
-rw-r--r--routers/api/v1/repo/pull.go82
-rw-r--r--routers/api/v1/repo/pull_review.go64
12 files changed, 225 insertions, 226 deletions
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index ffa3ddc784..2190094bac 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -557,7 +557,7 @@ func handleCreateOrUpdateFileError(ctx *context.APIContext, err error) {
// Called from both CreateFile or UpdateFile to handle both
func createOrUpdateFile(ctx *context.APIContext, opts *files_service.UpdateRepoFileOptions) (*api.FileResponse, error) {
if !canWriteFiles(ctx, opts.OldBranch) {
- return nil, models.ErrUserDoesNotHaveAccessToRepo{
+ return nil, repo_model.ErrUserDoesNotHaveAccessToRepo{
UserID: ctx.Doer.ID,
RepoName: ctx.Repo.Repository.LowerName,
}
@@ -614,7 +614,7 @@ func DeleteFile(ctx *context.APIContext) {
apiOpts := web.GetForm(ctx).(*api.DeleteFileOptions)
if !canWriteFiles(ctx, apiOpts.BranchName) {
- ctx.Error(http.StatusForbidden, "DeleteFile", models.ErrUserDoesNotHaveAccessToRepo{
+ ctx.Error(http.StatusForbidden, "DeleteFile", repo_model.ErrUserDoesNotHaveAccessToRepo{
UserID: ctx.Doer.ID,
RepoName: ctx.Repo.Repository.LowerName,
})
@@ -712,7 +712,7 @@ func GetContents(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
if !canReadFiles(ctx.Repo) {
- ctx.Error(http.StatusInternalServerError, "GetContentsOrList", models.ErrUserDoesNotHaveAccessToRepo{
+ ctx.Error(http.StatusInternalServerError, "GetContentsOrList", repo_model.ErrUserDoesNotHaveAccessToRepo{
UserID: ctx.Doer.ID,
RepoName: ctx.Repo.Repository.LowerName,
})
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index c394ad1756..ddad18ef62 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -12,7 +12,6 @@ import (
"strings"
"time"
- "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"
@@ -184,7 +183,7 @@ func SearchIssues(ctx *context.APIContext) {
return
}
- var issues []*models.Issue
+ var issues []*issues_model.Issue
var filteredCount int64
keyword := ctx.FormTrim("q")
@@ -233,7 +232,7 @@ func SearchIssues(ctx *context.APIContext) {
// 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,
@@ -269,7 +268,7 @@ func SearchIssues(ctx *context.APIContext) {
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)
return
}
@@ -277,7 +276,7 @@ func SearchIssues(ctx *context.APIContext) {
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)
return
}
@@ -379,7 +378,7 @@ func ListIssues(ctx *context.APIContext) {
isClosed = util.OptionalBoolFalse
}
- var issues []*models.Issue
+ var issues []*issues_model.Issue
var filteredCount int64
keyword := ctx.FormTrim("q")
@@ -397,7 +396,7 @@ func ListIssues(ctx *context.APIContext) {
}
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, "GetLabelIDsInRepoByNames", err)
return
@@ -463,7 +462,7 @@ func ListIssues(ctx *context.APIContext) {
// 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,
@@ -478,7 +477,7 @@ func ListIssues(ctx *context.APIContext) {
MentionedID: mentionedByID,
}
- if issues, err = models.Issues(issuesOpt); err != nil {
+ if issues, err = issues_model.Issues(issuesOpt); err != nil {
ctx.Error(http.StatusInternalServerError, "Issues", err)
return
}
@@ -486,7 +485,7 @@ func ListIssues(ctx *context.APIContext) {
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)
return
}
@@ -547,9 +546,9 @@ func GetIssue(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- 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.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -598,7 +597,7 @@ func CreateIssue(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
}
- issue := &models.Issue{
+ issue := &issues_model.Issue{
RepoID: ctx.Repo.Repository.ID,
Repo: ctx.Repo.Repository,
Title: form.Title,
@@ -613,7 +612,7 @@ func CreateIssue(ctx *context.APIContext) {
var err error
if ctx.Repo.CanWrite(unit.TypeIssues) {
issue.MilestoneID = form.Milestone
- assigneeIDs, err = models.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
+ assigneeIDs, err = issues_model.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
if err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
@@ -637,7 +636,7 @@ func CreateIssue(ctx *context.APIContext) {
return
}
if !valid {
- ctx.Error(http.StatusUnprocessableEntity, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: ctx.Repo.Repository.Name})
+ ctx.Error(http.StatusUnprocessableEntity, "canBeAssigned", repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: ctx.Repo.Repository.Name})
return
}
}
@@ -647,7 +646,7 @@ func CreateIssue(ctx *context.APIContext) {
}
if err := issue_service.NewIssue(ctx.Repo.Repository, issue, form.Labels, nil, assigneeIDs); err != nil {
- if models.IsErrUserDoesNotHaveAccessToRepo(err) {
+ if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
return
}
@@ -657,7 +656,7 @@ func CreateIssue(ctx *context.APIContext) {
if form.Closed {
if err := issue_service.ChangeStatus(issue, ctx.Doer, true); err != nil {
- if models.IsErrDependenciesLeft(err) {
+ if issues_model.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
return
}
@@ -667,7 +666,7 @@ func CreateIssue(ctx *context.APIContext) {
}
// Refetch from database to assign some automatic values
- issue, err = models.GetIssueByID(issue.ID)
+ issue, err = issues_model.GetIssueByID(ctx, issue.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetIssueByID", err)
return
@@ -716,9 +715,9 @@ func EditIssue(ctx *context.APIContext) {
// "$ref": "#/responses/error"
form := web.GetForm(ctx).(*api.EditIssueOption)
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -728,7 +727,7 @@ func EditIssue(ctx *context.APIContext) {
issue.Repo = ctx.Repo.Repository
canWrite := ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
- err = issue.LoadAttributes()
+ err = issue.LoadAttributes(ctx)
if err != nil {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
@@ -764,7 +763,7 @@ func EditIssue(ctx *context.APIContext) {
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)
return
}
@@ -813,9 +812,9 @@ func EditIssue(ctx *context.APIContext) {
}
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
- statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.Doer)
+ statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(issue, ctx.Doer)
if err != nil {
- if models.IsErrDependenciesLeft(err) {
+ if issues_model.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
return
}
@@ -832,7 +831,7 @@ func EditIssue(ctx *context.APIContext) {
}
// Refetch from database to assign some automatic values
- issue, err = models.GetIssueByID(issue.ID)
+ issue, err = issues_model.GetIssueByID(ctx, issue.ID)
if err != nil {
ctx.InternalServerError(err)
return
@@ -872,9 +871,9 @@ func DeleteIssue(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
- 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(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByID", err)
@@ -928,9 +927,9 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -951,7 +950,7 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
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)
return
}
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index 22533c3810..89038e4f16 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -10,7 +10,7 @@ import (
"errors"
"net/http"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -65,33 +65,33 @@ func ListIssueComments(ctx *context.APIContext) {
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
return
}
- 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 {
ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err)
return
}
issue.Repo = ctx.Repo.Repository
- opts := &models.FindCommentsOptions{
+ opts := &issues_model.FindCommentsOptions{
IssueID: issue.ID,
Since: since,
Before: before,
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
}
- comments, err := models.FindComments(ctx, opts)
+ comments, err := issues_model.FindComments(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindComments", err)
return
}
- totalCount, err := models.CountComments(opts)
+ totalCount, err := issues_model.CountComments(opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- if err := models.CommentList(comments).LoadPosters(); err != nil {
+ if err := issues_model.CommentList(comments).LoadPosters(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
@@ -157,35 +157,35 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
ctx.Error(http.StatusUnprocessableEntity, "GetQueryBeforeSince", err)
return
}
- 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 {
ctx.Error(http.StatusInternalServerError, "GetRawIssueByIndex", err)
return
}
issue.Repo = ctx.Repo.Repository
- opts := &models.FindCommentsOptions{
+ opts := &issues_model.FindCommentsOptions{
ListOptions: utils.GetListOptions(ctx),
IssueID: issue.ID,
Since: since,
Before: before,
- Type: models.CommentTypeUnknown,
+ Type: issues_model.CommentTypeUnknown,
}
- comments, err := models.FindComments(ctx, opts)
+ comments, err := issues_model.FindComments(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindComments", err)
return
}
- if err := models.CommentList(comments).LoadPosters(); err != nil {
+ if err := issues_model.CommentList(comments).LoadPosters(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
var apiComments []*api.TimelineComment
for _, comment := range comments {
- if comment.Type != models.CommentTypeCode && isXRefCommentAccessible(ctx, ctx.Doer, comment, issue.RepoID) {
+ if comment.Type != issues_model.CommentTypeCode && isXRefCommentAccessible(ctx, ctx.Doer, comment, issue.RepoID) {
comment.Issue = issue
apiComments = append(apiComments, convert.ToTimelineComment(comment, ctx.Doer))
}
@@ -195,9 +195,9 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, &apiComments)
}
-func isXRefCommentAccessible(ctx stdCtx.Context, user *user_model.User, c *models.Comment, issueRepoID int64) bool {
+func isXRefCommentAccessible(ctx stdCtx.Context, user *user_model.User, c *issues_model.Comment, issueRepoID int64) bool {
// Remove comments that the user has no permissions to see
- if models.CommentTypeIsRef(c.Type) && c.RefRepoID != issueRepoID && c.RefRepoID != 0 {
+ if issues_model.CommentTypeIsRef(c.Type) && c.RefRepoID != issueRepoID && c.RefRepoID != 0 {
var err error
// Set RefRepo for description in template
c.RefRepo, err = repo_model.GetRepositoryByIDCtx(ctx, c.RefRepoID)
@@ -261,41 +261,41 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return
}
- opts := &models.FindCommentsOptions{
+ opts := &issues_model.FindCommentsOptions{
ListOptions: utils.GetListOptions(ctx),
RepoID: ctx.Repo.Repository.ID,
- Type: models.CommentTypeComment,
+ Type: issues_model.CommentTypeComment,
Since: since,
Before: before,
}
- comments, err := models.FindComments(ctx, opts)
+ comments, err := issues_model.FindComments(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindComments", err)
return
}
- totalCount, err := models.CountComments(opts)
+ totalCount, err := issues_model.CountComments(opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- if err = models.CommentList(comments).LoadPosters(); err != nil {
+ if err = issues_model.CommentList(comments).LoadPosters(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
apiComments := make([]*api.Comment, len(comments))
- if err := models.CommentList(comments).LoadIssues(); err != nil {
+ if err := issues_model.CommentList(comments).LoadIssues(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadIssues", err)
return
}
- if err := models.CommentList(comments).LoadPosters(); err != nil {
+ if err := issues_model.CommentList(comments).LoadPosters(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
- if _, err := models.CommentList(comments).Issues().LoadRepositories(); err != nil {
+ if _, err := issues_model.CommentList(comments).Issues().LoadRepositories(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadRepositories", err)
return
}
@@ -343,7 +343,7 @@ func CreateIssueComment(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
form := web.GetForm(ctx).(*api.CreateIssueCommentOption)
- 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 {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
return
@@ -399,9 +399,9 @@ func GetIssueComment(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrCommentNotExist(err) {
+ if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
@@ -418,7 +418,7 @@ func GetIssueComment(ctx *context.APIContext) {
return
}
- if comment.Type != models.CommentTypeComment {
+ if comment.Type != issues_model.CommentTypeComment {
ctx.Status(http.StatusNoContent)
return
}
@@ -526,9 +526,9 @@ func EditIssueCommentDeprecated(ctx *context.APIContext) {
}
func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrCommentNotExist(err) {
+ if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
@@ -541,7 +541,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption)
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.Status(http.StatusNoContent)
return
}
@@ -629,9 +629,9 @@ func DeleteIssueCommentDeprecated(ctx *context.APIContext) {
}
func deleteIssueComment(ctx *context.APIContext) {
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrCommentNotExist(err) {
+ if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
@@ -642,7 +642,7 @@ func deleteIssueComment(ctx *context.APIContext) {
if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
ctx.Status(http.StatusForbidden)
return
- } else if comment.Type != models.CommentTypeComment {
+ } else if comment.Type != issues_model.CommentTypeComment {
ctx.Status(http.StatusNoContent)
return
}
diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go
index 0193eb4230..50c09e02fa 100644
--- a/routers/api/v1/repo/issue_label.go
+++ b/routers/api/v1/repo/issue_label.go
@@ -8,7 +8,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/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -46,9 +46,9 @@ func ListIssueLabels(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -56,7 +56,7 @@ func ListIssueLabels(ctx *context.APIContext) {
return
}
- if err := issue.LoadAttributes(); err != nil {
+ if err := issue.LoadAttributes(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
@@ -111,7 +111,7 @@ func AddIssueLabels(ctx *context.APIContext) {
return
}
- labels, err = models.GetLabelsByIssueID(ctx, issue.ID)
+ labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err)
return
@@ -158,9 +158,9 @@ func DeleteIssueLabel(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -173,9 +173,9 @@ func DeleteIssueLabel(ctx *context.APIContext) {
return
}
- label, err := models.GetLabelByID(ctx, ctx.ParamsInt64(":id"))
+ label, err := issues_model.GetLabelByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrLabelNotExist(err) {
+ if issues_model.IsErrLabelNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetLabelByID", err)
@@ -237,7 +237,7 @@ func ReplaceIssueLabels(ctx *context.APIContext) {
return
}
- labels, err = models.GetLabelsByIssueID(ctx, issue.ID)
+ labels, err = issues_model.GetLabelsByIssueID(ctx, issue.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err)
return
@@ -276,9 +276,9 @@ func ClearIssueLabels(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -299,10 +299,10 @@ func ClearIssueLabels(ctx *context.APIContext) {
ctx.Status(http.StatusNoContent)
}
-func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (issue *models.Issue, labels []*models.Label, err error) {
- issue, err = models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption) (issue *issues_model.Issue, labels []*issues_model.Label, err error) {
+ 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -310,7 +310,7 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
return
}
- labels, err = models.GetLabelsByIDs(form.Labels)
+ labels, err = issues_model.GetLabelsByIDs(form.Labels)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByIDs", err)
return
diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go
index 45be7a92dd..f4c40d2bcd 100644
--- a/routers/api/v1/repo/issue_reaction.go
+++ b/routers/api/v1/repo/issue_reaction.go
@@ -8,7 +8,6 @@ import (
"errors"
"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/convert"
@@ -49,9 +48,9 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrCommentNotExist(err) {
+ if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
@@ -176,9 +175,9 @@ func DeleteIssueCommentReaction(ctx *context.APIContext) {
}
func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) {
- comment, err := models.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
+ comment, err := issues_model.GetCommentByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrCommentNotExist(err) {
+ if issues_model.IsErrCommentNotExist(err) {
ctx.NotFound(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetCommentByID", err)
@@ -271,9 +270,9 @@ func GetIssueReactions(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
- 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.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -391,9 +390,9 @@ func DeleteIssueReaction(ctx *context.APIContext) {
}
func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, isCreateType bool) {
- 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.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
diff --git a/routers/api/v1/repo/issue_stopwatch.go b/routers/api/v1/repo/issue_stopwatch.go
index 382f294346..941b22e454 100644
--- a/routers/api/v1/repo/issue_stopwatch.go
+++ b/routers/api/v1/repo/issue_stopwatch.go
@@ -8,7 +8,7 @@ import (
"errors"
"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/convert"
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -55,7 +55,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
return
}
- if err := models.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
+ if err := issues_model.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
return
}
@@ -104,7 +104,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
return
}
- if err := models.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
+ if err := issues_model.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
return
}
@@ -153,7 +153,7 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
return
}
- if err := models.CancelStopwatch(ctx.Doer, issue); err != nil {
+ if err := issues_model.CancelStopwatch(ctx.Doer, issue); err != nil {
ctx.Error(http.StatusInternalServerError, "CancelStopwatch", err)
return
}
@@ -161,10 +161,10 @@ func DeleteIssueStopwatch(ctx *context.APIContext) {
ctx.Status(http.StatusNoContent)
}
-func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.Issue, error) {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*issues_model.Issue, error) {
+ 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -183,7 +183,7 @@ func prepareIssueStopwatch(ctx *context.APIContext, shouldExist bool) (*models.I
return nil, errors.New("Cannot use time tracker")
}
- if models.StopwatchExists(ctx.Doer.ID, issue.ID) != shouldExist {
+ if issues_model.StopwatchExists(ctx.Doer.ID, issue.ID) != shouldExist {
if shouldExist {
ctx.Error(http.StatusConflict, "StopwatchExists", "cannot stop/cancel a non existent stopwatch")
err = errors.New("cannot stop/cancel a non existent stopwatch")
@@ -219,13 +219,13 @@ func GetStopwatches(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/StopWatchList"
- sws, err := models.GetUserStopwatches(ctx.Doer.ID, utils.GetListOptions(ctx))
+ sws, err := issues_model.GetUserStopwatches(ctx.Doer.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserStopwatches", err)
return
}
- count, err := models.CountUserStopwatches(ctx.Doer.ID)
+ count, err := issues_model.CountUserStopwatches(ctx.Doer.ID)
if err != nil {
ctx.InternalServerError(err)
return
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go
index a608ba2278..5e03e42b4c 100644
--- a/routers/api/v1/repo/issue_subscription.go
+++ b/routers/api/v1/repo/issue_subscription.go
@@ -8,7 +8,7 @@ import (
"fmt"
"net/http"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@@ -105,9 +105,9 @@ func DelIssueSubscription(ctx *context.APIContext) {
}
func setIssueSubscription(ctx *context.APIContext, watch bool) {
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -133,7 +133,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
return
}
- current, err := models.CheckIssueWatch(user, issue)
+ current, err := issues_model.CheckIssueWatch(user, issue)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CheckIssueWatch", err)
return
@@ -146,7 +146,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
}
// Update watch state
- if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil {
+ if err := issues_model.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil {
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
return
}
@@ -186,9 +186,9 @@ func CheckIssueSubscription(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -197,7 +197,7 @@ func CheckIssueSubscription(ctx *context.APIContext) {
return
}
- watching, err := models.CheckIssueWatch(ctx.Doer, issue)
+ watching, err := issues_model.CheckIssueWatch(ctx.Doer, issue)
if err != nil {
ctx.InternalServerError(err)
return
@@ -252,9 +252,9 @@ func GetIssueSubscribers(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -263,7 +263,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
return
}
- iwl, err := models.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx))
+ iwl, err := issues_model.GetIssueWatchers(ctx, issue.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetIssueWatchers", err)
return
@@ -284,7 +284,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
apiUsers = append(apiUsers, convert.ToUser(v, ctx.Doer))
}
- count, err := models.CountIssueWatchers(ctx, issue.ID)
+ count, err := issues_model.CountIssueWatchers(ctx, issue.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CountIssueWatchers", err)
return
diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go
index 19e1a82590..b9a6c5af64 100644
--- a/routers/api/v1/repo/issue_tracked_time.go
+++ b/routers/api/v1/repo/issue_tracked_time.go
@@ -9,8 +9,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/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
@@ -76,9 +76,9 @@ func ListTrackedTimes(ctx *context.APIContext) {
ctx.NotFound("Timetracker is disabled")
return
}
- 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(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -86,7 +86,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
return
}
- opts := &models.FindTrackedTimesOptions{
+ opts := &issues_model.FindTrackedTimesOptions{
ListOptions: utils.GetListOptions(ctx),
RepositoryID: ctx.Repo.Repository.ID,
IssueID: issue.ID,
@@ -122,13 +122,13 @@ func ListTrackedTimes(ctx *context.APIContext) {
}
}
- count, err := models.CountTrackedTimes(opts)
+ count, err := issues_model.CountTrackedTimes(opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- trackedTimes, err := models.GetTrackedTimes(ctx, opts)
+ trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
return
@@ -180,9 +180,9 @@ func AddTime(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
form := web.GetForm(ctx).(*api.AddTimeOption)
- 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(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -215,7 +215,7 @@ func AddTime(ctx *context.APIContext) {
created = form.Created
}
- trackedTime, err := models.AddTime(user, issue, form.Time, created)
+ trackedTime, err := issues_model.AddTime(user, issue, form.Time, created)
if err != nil {
ctx.Error(http.StatusInternalServerError, "AddTime", err)
return
@@ -261,9 +261,9 @@ func ResetIssueTime(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
- 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(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -280,7 +280,7 @@ func ResetIssueTime(ctx *context.APIContext) {
return
}
- err = models.DeleteIssueUserTimes(issue, ctx.Doer)
+ err = issues_model.DeleteIssueUserTimes(issue, ctx.Doer)
if err != nil {
if db.IsErrNotExist(err) {
ctx.Error(http.StatusNotFound, "DeleteIssueUserTimes", err)
@@ -332,9 +332,9 @@ func DeleteTime(ctx *context.APIContext) {
// "403":
// "$ref": "#/responses/forbidden"
- 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(err)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
@@ -351,7 +351,7 @@ func DeleteTime(ctx *context.APIContext) {
return
}
- time, err := models.GetTrackedTimeByID(ctx.ParamsInt64(":id"))
+ time, err := issues_model.GetTrackedTimeByID(ctx.ParamsInt64(":id"))
if err != nil {
if db.IsErrNotExist(err) {
ctx.NotFound(err)
@@ -371,7 +371,7 @@ func DeleteTime(ctx *context.APIContext) {
return
}
- err = models.DeleteTime(time)
+ err = issues_model.DeleteTime(time)
if err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteTime", err)
return
@@ -434,12 +434,12 @@ func ListTrackedTimesByUser(ctx *context.APIContext) {
return
}
- opts := &models.FindTrackedTimesOptions{
+ opts := &issues_model.FindTrackedTimesOptions{
UserID: user.ID,
RepositoryID: ctx.Repo.Repository.ID,
}
- trackedTimes, err := models.GetTrackedTimes(ctx, opts)
+ trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
return
@@ -504,7 +504,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
return
}
- opts := &models.FindTrackedTimesOptions{
+ opts := &issues_model.FindTrackedTimesOptions{
ListOptions: utils.GetListOptions(ctx),
RepositoryID: ctx.Repo.Repository.ID,
}
@@ -541,13 +541,13 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
}
}
- count, err := models.CountTrackedTimes(opts)
+ count, err := issues_model.CountTrackedTimes(opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- trackedTimes, err := models.GetTrackedTimes(ctx, opts)
+ trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTrackedTimes", err)
return
@@ -592,7 +592,7 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/TrackedTimeList"
- opts := &models.FindTrackedTimesOptions{
+ opts := &issues_model.FindTrackedTimesOptions{
ListOptions: utils.GetListOptions(ctx),
UserID: ctx.Doer.ID,
}
@@ -603,13 +603,13 @@ func ListMyTrackedTimes(ctx *context.APIContext) {
return
}
- count, err := models.CountTrackedTimes(opts)
+ count, err := issues_model.CountTrackedTimes(opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- trackedTimes, err := models.GetTrackedTimes(ctx, opts)
+ trackedTimes, err := issues_model.GetTrackedTimes(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTrackedTimesByUser", err)
return
diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go
index 4332b8e627..8b1e298668 100644
--- a/routers/api/v1/repo/label.go
+++ b/routers/api/v1/repo/label.go
@@ -11,7 +11,7 @@ import (
"strconv"
"strings"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -49,13 +49,13 @@ func ListLabels(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/LabelList"
- labels, err := models.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
+ labels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err)
return
}
- count, err := models.CountLabelsByRepoID(ctx.Repo.Repository.ID)
+ count, err := issues_model.CountLabelsByRepoID(ctx.Repo.Repository.ID)
if err != nil {
ctx.InternalServerError(err)
return
@@ -94,17 +94,17 @@ func GetLabel(ctx *context.APIContext) {
// "$ref": "#/responses/Label"
var (
- label *models.Label
+ label *issues_model.Label
err error
)
strID := ctx.Params(":id")
if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil {
- label, err = models.GetLabelInRepoByName(ctx, ctx.Repo.Repository.ID, strID)
+ label, err = issues_model.GetLabelInRepoByName(ctx, ctx.Repo.Repository.ID, strID)
} else {
- label, err = models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, intID)
+ label, err = issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, intID)
}
if err != nil {
- if models.IsErrRepoLabelNotExist(err) {
+ if issues_model.IsErrRepoLabelNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetLabelByRepoID", err)
@@ -150,18 +150,18 @@ func CreateLabel(ctx *context.APIContext) {
if len(form.Color) == 6 {
form.Color = "#" + form.Color
}
- if !models.LabelColorPattern.MatchString(form.Color) {
+ if !issues_model.LabelColorPattern.MatchString(form.Color) {
ctx.Error(http.StatusUnprocessableEntity, "ColorPattern", fmt.Errorf("bad color code: %s", form.Color))
return
}
- label := &models.Label{
+ label := &issues_model.Label{
Name: form.Name,
Color: form.Color,
RepoID: ctx.Repo.Repository.ID,
Description: form.Description,
}
- if err := models.NewLabel(ctx, label); err != nil {
+ if err := issues_model.NewLabel(ctx, label); err != nil {
ctx.Error(http.StatusInternalServerError, "NewLabel", err)
return
}
@@ -206,9 +206,9 @@ func EditLabel(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditLabelOption)
- label, err := models.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+ label, err := issues_model.GetLabelInRepoByID(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrRepoLabelNotExist(err) {
+ if issues_model.IsErrRepoLabelNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetLabelByRepoID", err)
@@ -224,7 +224,7 @@ func EditLabel(ctx *context.APIContext) {
if len(label.Color) == 6 {
label.Color = "#" + label.Color
}
- if !models.LabelColorPattern.MatchString(label.Color) {
+ if !issues_model.LabelColorPattern.MatchString(label.Color) {
ctx.Error(http.StatusUnprocessableEntity, "ColorPattern", fmt.Errorf("bad color code: %s", label.Color))
return
}
@@ -232,7 +232,7 @@ func EditLabel(ctx *context.APIContext) {
if form.Description != nil {
label.Description = *form.Description
}
- if err := models.UpdateLabel(label); err != nil {
+ if err := issues_model.UpdateLabel(label); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateLabel", err)
return
}
@@ -266,7 +266,7 @@ func DeleteLabel(ctx *context.APIContext) {
// "204":
// "$ref": "#/responses/empty"
- if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
+ if err := issues_model.DeleteLabel(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
return
}
diff --git a/routers/api/v1/repo/patch.go b/routers/api/v1/repo/patch.go
index 6dbf979701..40afe2d92b 100644
--- a/routers/api/v1/repo/patch.go
+++ b/routers/api/v1/repo/patch.go
@@ -9,6 +9,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
@@ -78,7 +79,7 @@ func ApplyDiffPatch(ctx *context.APIContext) {
}
if !canWriteFiles(ctx, apiOpts.BranchName) {
- ctx.Error(http.StatusInternalServerError, "ApplyPatch", models.ErrUserDoesNotHaveAccessToRepo{
+ ctx.Error(http.StatusInternalServerError, "ApplyPatch", repo_model.ErrUserDoesNotHaveAccessToRepo{
UserID: ctx.Doer.ID,
RepoName: ctx.Repo.Repository.LowerName,
})
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 393f2d1576..50d2c9484f 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -92,7 +92,7 @@ func ListPullRequests(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx)
- prs, maxResults, err := models.PullRequests(ctx.Repo.Repository.ID, &models.PullRequestsOptions{
+ prs, maxResults, err := issues_model.PullRequests(ctx.Repo.Repository.ID, &issues_model.PullRequestsOptions{
ListOptions: listOptions,
State: ctx.FormTrim("state"),
SortType: ctx.FormTrim("sort"),
@@ -160,9 +160,9 @@ func GetPullRequest(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -220,9 +220,9 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) {
// "$ref": "#/responses/string"
// "404":
// "$ref": "#/responses/notFound"
- 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()
} else {
ctx.InternalServerError(err)
@@ -297,14 +297,14 @@ func CreatePullRequest(ctx *context.APIContext) {
defer headGitRepo.Close()
// Check if another PR exists with the same targets
- existingPr, err := models.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch, models.PullRequestFlowGithub)
+ existingPr, err := issues_model.GetUnmergedPullRequest(headRepo.ID, ctx.Repo.Repository.ID, headBranch, baseBranch, issues_model.PullRequestFlowGithub)
if err != nil {
- if !models.IsErrPullRequestNotExist(err) {
+ if !issues_model.IsErrPullRequestNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetUnmergedPullRequest", err)
return
}
} else {
- err = models.ErrPullRequestAlreadyExists{
+ err = issues_model.ErrPullRequestAlreadyExists{
ID: existingPr.ID,
IssueID: existingPr.Index,
HeadRepoID: existingPr.HeadRepoID,
@@ -317,7 +317,7 @@ func CreatePullRequest(ctx *context.APIContext) {
}
if len(form.Labels) > 0 {
- labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
+ labels, err := issues_model.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDs", err)
return
@@ -331,7 +331,7 @@ func CreatePullRequest(ctx *context.APIContext) {
}
if ctx.Repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels)
+ orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err)
return
@@ -364,7 +364,7 @@ func CreatePullRequest(ctx *context.APIContext) {
deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
}
- prIssue := &models.Issue{
+ prIssue := &issues_model.Issue{
RepoID: repo.ID,
Title: form.Title,
PosterID: ctx.Doer.ID,
@@ -374,7 +374,7 @@ func CreatePullRequest(ctx *context.APIContext) {
Content: form.Body,
DeadlineUnix: deadlineUnix,
}
- pr := &models.PullRequest{
+ pr := &issues_model.PullRequest{
HeadRepoID: headRepo.ID,
BaseRepoID: repo.ID,
HeadBranch: headBranch,
@@ -382,11 +382,11 @@ func CreatePullRequest(ctx *context.APIContext) {
HeadRepo: headRepo,
BaseRepo: repo,
MergeBase: compareInfo.MergeBase,
- Type: models.PullRequestGitea,
+ Type: issues_model.PullRequestGitea,
}
// Get all assignee IDs
- assigneeIDs, err := models.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
+ assigneeIDs, err := issues_model.MakeIDsFromAPIAssigneesToAdd(form.Assignee, form.Assignees)
if err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("Assignee does not exist: [name: %s]", err))
@@ -409,13 +409,13 @@ func CreatePullRequest(ctx *context.APIContext) {
return
}
if !valid {
- ctx.Error(http.StatusUnprocessableEntity, "canBeAssigned", models.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name})
+ ctx.Error(http.StatusUnprocessableEntity, "canBeAssigned", repo_model.ErrUserDoesNotHaveAccessToRepo{UserID: aID, RepoName: repo.Name})
return
}
}
if err := pull_service.NewPullRequest(ctx, repo, prIssue, labelIDs, []string{}, pr, assigneeIDs); err != nil {
- if models.IsErrUserDoesNotHaveAccessToRepo(err) {
+ if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
return
}
@@ -470,9 +470,9 @@ func EditPullRequest(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditPullRequestOption)
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -510,7 +510,7 @@ func EditPullRequest(ctx *context.APIContext) {
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)
return
}
@@ -548,14 +548,14 @@ func EditPullRequest(ctx *context.APIContext) {
}
if ctx.Repo.CanWrite(unit.TypePullRequests) && form.Labels != nil {
- labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
+ labels, err := issues_model.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDsError", err)
return
}
if ctx.Repo.Owner.IsOrganization() {
- orgLabels, err := models.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels)
+ orgLabels, err := issues_model.GetLabelsInOrgByIDs(ctx.Repo.Owner.ID, form.Labels)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetLabelsInOrgByIDs", err)
return
@@ -564,7 +564,7 @@ func EditPullRequest(ctx *context.APIContext) {
labels = append(labels, orgLabels...)
}
- if err = models.ReplaceIssueLabels(issue, labels, ctx.Doer); err != nil {
+ if err = issues_model.ReplaceIssueLabels(issue, labels, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "ReplaceLabelsError", err)
return
}
@@ -577,9 +577,9 @@ func EditPullRequest(ctx *context.APIContext) {
}
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
- statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.Doer)
+ statusChangeComment, titleChanged, err := issues_model.UpdateIssueByAPI(issue, ctx.Doer)
if err != nil {
- if models.IsErrDependenciesLeft(err) {
+ if issues_model.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
return
}
@@ -602,10 +602,10 @@ func EditPullRequest(ctx *context.APIContext) {
return
}
if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.Doer, form.Base); err != nil {
- if models.IsErrPullRequestAlreadyExists(err) {
+ if issues_model.IsErrPullRequestAlreadyExists(err) {
ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
return
- } else if models.IsErrIssueIsClosed(err) {
+ } else if issues_model.IsErrIssueIsClosed(err) {
ctx.Error(http.StatusUnprocessableEntity, "IsErrIssueIsClosed", err)
return
} else if models.IsErrPullRequestHasMerged(err) {
@@ -632,9 +632,9 @@ func EditPullRequest(ctx *context.APIContext) {
}
// Refetch from database
- pr, err = models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pr.Index)
+ pr, err = issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pr.Index)
if err != nil {
- if models.IsErrPullRequestNotExist(err) {
+ if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -676,9 +676,9 @@ func IsPullRequestMerged(ctx *context.APIContext) {
// "404":
// description: pull request has not been merged
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -730,9 +730,9 @@ func MergePullRequest(ctx *context.APIContext) {
form := web.GetForm(ctx).(*forms.MergePullRequestForm)
- 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.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -753,7 +753,7 @@ func MergePullRequest(ctx *context.APIContext) {
if ctx.IsSigned {
// Update issue-user.
- if err = pr.Issue.ReadBy(ctx, ctx.Doer.ID); err != nil {
+ if err = models.SetIssueReadBy(ctx, pr.Issue.ID, ctx.Doer.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "ReadBy", err)
return
}
@@ -868,7 +868,7 @@ func MergePullRequest(ctx *context.APIContext) {
if form.DeleteBranchAfterMerge {
// 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
@@ -902,7 +902,7 @@ func MergePullRequest(ctx *context.APIContext) {
}
return
}
- if err := models.AddDeletePRBranchComment(ctx, ctx.Doer, pr.BaseRepo, pr.Issue.ID, pr.HeadBranch); err != nil {
+ if err := issues_model.AddDeletePRBranchComment(ctx, ctx.Doer, pr.BaseRepo, pr.Issue.ID, pr.HeadBranch); err != nil {
// Do not fail here as branch has already been deleted
log.Error("DeleteBranch: %v", err)
}
@@ -1079,9 +1079,9 @@ func UpdatePullRequest(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -1177,9 +1177,9 @@ func CancelScheduledAutoMerge(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
pullIndex := ctx.ParamsInt64(":index")
- pull, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex)
+ pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex)
if err != nil {
- if models.IsErrPullRequestNotExist(err) {
+ if issues_model.IsErrPullRequestNotExist(err) {
ctx.NotFound()
return
}
@@ -1254,9 +1254,9 @@ func GetPullRequestCommits(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- 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()
} else {
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go
index 5175fa921f..57548f2102 100644
--- a/routers/api/v1/repo/pull_review.go
+++ b/routers/api/v1/repo/pull_review.go
@@ -9,7 +9,7 @@ import (
"net/http"
"strings"
- "code.gitea.io/gitea/models"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/organization"
access_model "code.gitea.io/gitea/models/perm/access"
user_model "code.gitea.io/gitea/models/user"
@@ -61,9 +61,9 @@ func ListPullReviews(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- 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.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -81,19 +81,19 @@ func ListPullReviews(ctx *context.APIContext) {
return
}
- opts := models.FindReviewOptions{
+ opts := issues_model.FindReviewOptions{
ListOptions: utils.GetListOptions(ctx),
- Type: models.ReviewTypeUnknown,
+ Type: issues_model.ReviewTypeUnknown,
IssueID: pr.IssueID,
}
- allReviews, err := models.FindReviews(ctx, opts)
+ allReviews, err := issues_model.FindReviews(ctx, opts)
if err != nil {
ctx.InternalServerError(err)
return
}
- count, err := models.CountReviews(opts)
+ count, err := issues_model.CountReviews(opts)
if err != nil {
ctx.InternalServerError(err)
return
@@ -261,7 +261,7 @@ func DeletePullReview(ctx *context.APIContext) {
return
}
- if err := models.DeleteReview(review); err != nil {
+ if err := issues_model.DeleteReview(review); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteReview", fmt.Errorf("can not delete ReviewID: %d", review.ID))
return
}
@@ -307,9 +307,9 @@ func CreatePullReview(ctx *context.APIContext) {
// "$ref": "#/responses/validationError"
opts := web.GetForm(ctx).(*api.CreatePullReviewOptions)
- 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.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -435,7 +435,7 @@ func SubmitPullReview(ctx *context.APIContext) {
return
}
- if review.Type != models.ReviewTypePending {
+ if review.Type != issues_model.ReviewTypePending {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("only a pending review can be submitted"))
return
}
@@ -447,7 +447,7 @@ func SubmitPullReview(ctx *context.APIContext) {
}
// if review stay pending return
- if reviewType == models.ReviewTypePending {
+ if reviewType == issues_model.ReviewTypePending {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("review stay pending"))
return
}
@@ -475,7 +475,7 @@ func SubmitPullReview(ctx *context.APIContext) {
}
// preparePullReviewType return ReviewType and false or nil and true if an error happen
-func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, event api.ReviewStateType, body string, hasComments bool) (models.ReviewType, bool) {
+func preparePullReviewType(ctx *context.APIContext, pr *issues_model.PullRequest, event api.ReviewStateType, body string, hasComments bool) (issues_model.ReviewType, bool) {
if err := pr.LoadIssue(); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadIssue", err)
return -1, true
@@ -484,7 +484,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
needsBody := true
hasBody := len(strings.TrimSpace(body)) > 0
- var reviewType models.ReviewType
+ var reviewType issues_model.ReviewType
switch event {
case api.ReviewStateApproved:
// can not approve your own PR
@@ -492,7 +492,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("approve your own pull is not allowed"))
return -1, true
}
- reviewType = models.ReviewTypeApprove
+ reviewType = issues_model.ReviewTypeApprove
needsBody = false
case api.ReviewStateRequestChanges:
@@ -501,10 +501,10 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("reject your own pull is not allowed"))
return -1, true
}
- reviewType = models.ReviewTypeReject
+ reviewType = issues_model.ReviewTypeReject
case api.ReviewStateComment:
- reviewType = models.ReviewTypeComment
+ reviewType = issues_model.ReviewTypeComment
needsBody = false
// if there is no body we need to ensure that there are comments
if !hasBody && !hasComments {
@@ -512,7 +512,7 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
return -1, true
}
default:
- reviewType = models.ReviewTypePending
+ reviewType = issues_model.ReviewTypePending
}
// reject reviews with empty body if a body is required for this call
@@ -525,10 +525,10 @@ func preparePullReviewType(ctx *context.APIContext, pr *models.PullRequest, even
}
// prepareSingleReview return review, related pull and false or nil, nil and true if an error happen
-func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullRequest, bool) {
- pr, err := models.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func prepareSingleReview(ctx *context.APIContext) (*issues_model.Review, *issues_model.PullRequest, bool) {
+ 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.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -536,9 +536,9 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
return nil, nil, true
}
- review, err := models.GetReviewByID(ctx, ctx.ParamsInt64(":id"))
+ review, err := issues_model.GetReviewByID(ctx, ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrReviewNotExist(err) {
+ if issues_model.IsErrReviewNotExist(err) {
ctx.NotFound("GetReviewByID", err)
} else {
ctx.Error(http.StatusInternalServerError, "GetReviewByID", err)
@@ -553,7 +553,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
}
// make sure that the user has access to this review if it is pending
- if review.Type == models.ReviewTypePending && review.ReviewerID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
+ if review.Type == issues_model.ReviewTypePending && review.ReviewerID != ctx.Doer.ID && !ctx.Doer.IsAdmin {
ctx.NotFound("GetReviewByID")
return nil, nil, true
}
@@ -648,9 +648,9 @@ func DeleteReviewRequests(ctx *context.APIContext) {
}
func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions, isAdd 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.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
@@ -690,7 +690,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
err = issue_service.IsValidReviewRequest(ctx, reviewer, ctx.Doer, isAdd, pr.Issue, &permDoer)
if err != nil {
- if models.IsErrNotValidReviewRequest(err) {
+ if issues_model.IsErrNotValidReviewRequest(err) {
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
return
}
@@ -701,9 +701,9 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
reviewers = append(reviewers, reviewer)
}
- var reviews []*models.Review
+ var reviews []*issues_model.Review
if isAdd {
- reviews = make([]*models.Review, 0, len(reviewers))
+ reviews = make([]*issues_model.Review, 0, len(reviewers))
}
for _, reviewer := range reviewers {
@@ -739,7 +739,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
err = issue_service.IsValidTeamReviewRequest(ctx, teamReviewer, ctx.Doer, isAdd, pr.Issue)
if err != nil {
- if models.IsErrNotValidReviewRequest(err) {
+ if issues_model.IsErrNotValidReviewRequest(err) {
ctx.Error(http.StatusUnprocessableEntity, "NotValidReviewRequest", err)
return
}
@@ -876,7 +876,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
return
}
- if review.Type != models.ReviewTypeApprove && review.Type != models.ReviewTypeReject {
+ if review.Type != issues_model.ReviewTypeApprove && review.Type != issues_model.ReviewTypeReject {
ctx.Error(http.StatusForbidden, "", "not need to dismiss this review because it's type is not Approve or change request")
return
}
@@ -892,7 +892,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
return
}
- if review, err = models.GetReviewByID(ctx, review.ID); err != nil {
+ if review, err = issues_model.GetReviewByID(ctx, review.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "GetReviewByID", err)
return
}