summaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go109
1 files changed, 53 insertions, 56 deletions
diff --git a/models/issue.go b/models/issue.go
index 751ff36c54..b1fa2d02ad 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -16,7 +16,7 @@ import (
admin_model "code.gitea.io/gitea/models/admin"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/foreignreference"
- "code.gitea.io/gitea/models/issues"
+ issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/organization"
"code.gitea.io/gitea/models/perm"
project_model "code.gitea.io/gitea/models/project"
@@ -46,14 +46,14 @@ type Issue struct {
PosterID int64 `xorm:"INDEX"`
Poster *user_model.User `xorm:"-"`
OriginalAuthor string
- OriginalAuthorID int64 `xorm:"index"`
- Title string `xorm:"name"`
- Content string `xorm:"LONGTEXT"`
- RenderedContent string `xorm:"-"`
- Labels []*Label `xorm:"-"`
- MilestoneID int64 `xorm:"INDEX"`
- Milestone *Milestone `xorm:"-"`
- Project *project_model.Project `xorm:"-"`
+ OriginalAuthorID int64 `xorm:"index"`
+ Title string `xorm:"name"`
+ Content string `xorm:"LONGTEXT"`
+ RenderedContent string `xorm:"-"`
+ Labels []*Label `xorm:"-"`
+ MilestoneID int64 `xorm:"INDEX"`
+ Milestone *issues_model.Milestone `xorm:"-"`
+ Project *project_model.Project `xorm:"-"`
Priority int
AssigneeID int64 `xorm:"-"`
Assignee *user_model.User `xorm:"-"`
@@ -72,7 +72,7 @@ type Issue struct {
Attachments []*repo_model.Attachment `xorm:"-"`
Comments []*Comment `xorm:"-"`
- Reactions issues.ReactionList `xorm:"-"`
+ Reactions issues_model.ReactionList `xorm:"-"`
TotalTrackedTime int64 `xorm:"-"`
Assignees []*user_model.User `xorm:"-"`
ForeignReference *foreignreference.ForeignReference `xorm:"-"`
@@ -124,11 +124,7 @@ func (issue *Issue) IsOverdue() bool {
}
// LoadRepo loads issue's repository
-func (issue *Issue) LoadRepo() error {
- return issue.loadRepo(db.DefaultContext)
-}
-
-func (issue *Issue) loadRepo(ctx context.Context) (err error) {
+func (issue *Issue) LoadRepo(ctx context.Context) (err error) {
if issue.Repo == nil {
issue.Repo, err = repo_model.GetRepositoryByIDCtx(ctx, issue.RepoID)
if err != nil {
@@ -144,7 +140,7 @@ func (issue *Issue) IsTimetrackerEnabled() bool {
}
func (issue *Issue) isTimetrackerEnabled(ctx context.Context) bool {
- if err := issue.loadRepo(ctx); err != nil {
+ if err := issue.LoadRepo(ctx); err != nil {
log.Error(fmt.Sprintf("loadRepo: %v", err))
return false
}
@@ -244,17 +240,17 @@ func (issue *Issue) loadReactions(ctx context.Context) (err error) {
if issue.Reactions != nil {
return nil
}
- reactions, _, err := issues.FindReactions(ctx, issues.FindReactionsOptions{
+ reactions, _, err := issues_model.FindReactions(ctx, issues_model.FindReactionsOptions{
IssueID: issue.ID,
})
if err != nil {
return err
}
- if err = issue.loadRepo(ctx); err != nil {
+ if err = issue.LoadRepo(ctx); err != nil {
return err
}
// Load reaction user data
- if _, err := issues.ReactionList(reactions).LoadUsers(ctx, issue.Repo); err != nil {
+ if _, err := issues_model.ReactionList(reactions).LoadUsers(ctx, issue.Repo); err != nil {
return err
}
@@ -297,10 +293,10 @@ func (issue *Issue) loadForeignReference(ctx context.Context) (err error) {
return nil
}
-func (issue *Issue) loadMilestone(e db.Engine) (err error) {
+func (issue *Issue) loadMilestone(ctx context.Context) (err error) {
if (issue.Milestone == nil || issue.Milestone.ID != issue.MilestoneID) && issue.MilestoneID > 0 {
- issue.Milestone, err = getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
- if err != nil && !IsErrMilestoneNotExist(err) {
+ issue.Milestone, err = issues_model.GetMilestoneByRepoID(ctx, issue.RepoID, issue.MilestoneID)
+ if err != nil && !issues_model.IsErrMilestoneNotExist(err) {
return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err)
}
}
@@ -309,7 +305,7 @@ func (issue *Issue) loadMilestone(e db.Engine) (err error) {
func (issue *Issue) loadAttributes(ctx context.Context) (err error) {
e := db.GetEngine(ctx)
- if err = issue.loadRepo(ctx); err != nil {
+ if err = issue.LoadRepo(ctx); err != nil {
return
}
@@ -321,7 +317,7 @@ func (issue *Issue) loadAttributes(ctx context.Context) (err error) {
return
}
- if err = issue.loadMilestone(e); err != nil {
+ if err = issue.loadMilestone(ctx); err != nil {
return
}
@@ -372,7 +368,7 @@ func (issue *Issue) LoadAttributes() error {
// LoadMilestone load milestone of this issue.
func (issue *Issue) LoadMilestone() error {
- return issue.loadMilestone(db.GetEngine(db.DefaultContext))
+ return issue.loadMilestone(db.DefaultContext)
}
// GetIsRead load the `IsRead` field of the issue
@@ -391,7 +387,7 @@ func (issue *Issue) GetIsRead(userID int64) error {
// APIURL returns the absolute APIURL to this issue.
func (issue *Issue) APIURL() string {
if issue.Repo == nil {
- err := issue.LoadRepo()
+ err := issue.LoadRepo(db.DefaultContext)
if err != nil {
log.Error("Issue[%d].APIURL(): %v", issue.ID, err)
return ""
@@ -491,7 +487,7 @@ func ClearIssueLabels(issue *Issue, doer *user_model.User) (err error) {
}
defer committer.Close()
- if err := issue.loadRepo(ctx); err != nil {
+ if err := issue.LoadRepo(ctx); err != nil {
return err
} else if err = issue.loadPullRequest(db.GetEngine(ctx)); err != nil {
return err
@@ -539,7 +535,7 @@ func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (e
}
defer committer.Close()
- if err = issue.loadRepo(ctx); err != nil {
+ if err = issue.LoadRepo(ctx); err != nil {
return err
}
@@ -607,7 +603,8 @@ func (issue *Issue) ReadBy(userID int64) error {
return setIssueNotificationStatusReadIfUnread(db.GetEngine(db.DefaultContext), userID, issue.ID)
}
-func updateIssueCols(ctx context.Context, issue *Issue, cols ...string) error {
+// UpdateIssueCols updates cols of issue
+func UpdateIssueCols(ctx context.Context, issue *Issue, cols ...string) error {
if _, err := db.GetEngine(ctx).ID(issue.ID).Cols(cols...).Update(issue); err != nil {
return err
}
@@ -658,7 +655,7 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
issue.ClosedUnix = 0
}
- if err := updateIssueCols(ctx, issue, "is_closed", "closed_unix"); err != nil {
+ if err := UpdateIssueCols(ctx, issue, "is_closed", "closed_unix"); err != nil {
return nil, err
}
@@ -674,7 +671,7 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
// Update issue count of milestone
if issue.MilestoneID > 0 {
- if err := updateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
+ if err := issues_model.UpdateMilestoneCounters(ctx, issue.MilestoneID); err != nil {
return nil, err
}
}
@@ -691,7 +688,7 @@ func doChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.Use
cmtType = CommentTypeMergePull
}
- return createComment(ctx, &CreateCommentOptions{
+ return CreateCommentCtx(ctx, &CreateCommentOptions{
Type: cmtType,
Doer: doer,
Repo: issue.Repo,
@@ -707,7 +704,7 @@ func ChangeIssueStatus(issue *Issue, doer *user_model.User, isClosed bool) (*Com
}
defer committer.Close()
- if err := issue.loadRepo(ctx); err != nil {
+ if err := issue.LoadRepo(ctx); err != nil {
return nil, err
}
if err := issue.loadPoster(db.GetEngine(ctx)); err != nil {
@@ -734,11 +731,11 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err
}
defer committer.Close()
- if err = updateIssueCols(ctx, issue, "name"); err != nil {
+ if err = UpdateIssueCols(ctx, issue, "name"); err != nil {
return fmt.Errorf("updateIssueCols: %v", err)
}
- if err = issue.loadRepo(ctx); err != nil {
+ if err = issue.LoadRepo(ctx); err != nil {
return fmt.Errorf("loadRepo: %v", err)
}
@@ -750,7 +747,7 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err
OldTitle: oldTitle,
NewTitle: issue.Title,
}
- if _, err = createComment(ctx, opts); err != nil {
+ if _, err = CreateCommentCtx(ctx, opts); err != nil {
return fmt.Errorf("createComment: %v", err)
}
if err = issue.addCrossReferences(ctx, doer, true); err != nil {
@@ -768,11 +765,11 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err
}
defer committer.Close()
- if err = updateIssueCols(ctx, issue, "ref"); err != nil {
+ if err = UpdateIssueCols(ctx, issue, "ref"); err != nil {
return fmt.Errorf("updateIssueCols: %v", err)
}
- if err = issue.loadRepo(ctx); err != nil {
+ if err = issue.LoadRepo(ctx); err != nil {
return fmt.Errorf("loadRepo: %v", err)
}
oldRefFriendly := strings.TrimPrefix(oldRef, git.BranchPrefix)
@@ -786,7 +783,7 @@ func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err err
OldRef: oldRefFriendly,
NewRef: newRefFriendly,
}
- if _, err = createComment(ctx, opts); err != nil {
+ if _, err = CreateCommentCtx(ctx, opts); err != nil {
return fmt.Errorf("createComment: %v", err)
}
@@ -811,7 +808,7 @@ func AddDeletePRBranchComment(doer *user_model.User, repo *repo_model.Repository
Issue: issue,
OldRef: branchName,
}
- if _, err = createComment(ctx, opts); err != nil {
+ if _, err = CreateCommentCtx(ctx, opts); err != nil {
return err
}
@@ -846,12 +843,12 @@ func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (er
}
defer committer.Close()
- hasContentHistory, err := issues.HasIssueContentHistory(ctx, issue.ID, 0)
+ hasContentHistory, err := issues_model.HasIssueContentHistory(ctx, issue.ID, 0)
if err != nil {
return fmt.Errorf("HasIssueContentHistory: %v", err)
}
if !hasContentHistory {
- if err = issues.SaveIssueContentHistory(db.GetEngine(ctx), issue.PosterID, issue.ID, 0,
+ if err = issues_model.SaveIssueContentHistory(db.GetEngine(ctx), issue.PosterID, issue.ID, 0,
issue.CreatedUnix, issue.Content, true); err != nil {
return fmt.Errorf("SaveIssueContentHistory: %v", err)
}
@@ -859,11 +856,11 @@ func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (er
issue.Content = content
- if err = updateIssueCols(ctx, issue, "content"); err != nil {
+ if err = UpdateIssueCols(ctx, issue, "content"); err != nil {
return fmt.Errorf("UpdateIssueCols: %v", err)
}
- if err = issues.SaveIssueContentHistory(db.GetEngine(ctx), doer.ID, issue.ID, 0,
+ if err = issues_model.SaveIssueContentHistory(db.GetEngine(ctx), doer.ID, issue.ID, 0,
timeutil.TimeStampNow(), issue.Content, false); err != nil {
return fmt.Errorf("SaveIssueContentHistory: %v", err)
}
@@ -943,8 +940,8 @@ func newIssue(ctx context.Context, doer *user_model.User, opts NewIssueOptions)
opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)
if opts.Issue.MilestoneID > 0 {
- milestone, err := getMilestoneByRepoID(e, opts.Issue.RepoID, opts.Issue.MilestoneID)
- if err != nil && !IsErrMilestoneNotExist(err) {
+ milestone, err := issues_model.GetMilestoneByRepoID(ctx, opts.Issue.RepoID, opts.Issue.MilestoneID)
+ if err != nil && !issues_model.IsErrMilestoneNotExist(err) {
return fmt.Errorf("getMilestoneByID: %v", err)
}
@@ -968,7 +965,7 @@ func newIssue(ctx context.Context, doer *user_model.User, opts NewIssueOptions)
}
if opts.Issue.MilestoneID > 0 {
- if err := updateMilestoneCounters(ctx, opts.Issue.MilestoneID); err != nil {
+ if err := issues_model.UpdateMilestoneCounters(ctx, opts.Issue.MilestoneID); err != nil {
return err
}
@@ -980,7 +977,7 @@ func newIssue(ctx context.Context, doer *user_model.User, opts NewIssueOptions)
OldMilestoneID: 0,
MilestoneID: opts.Issue.MilestoneID,
}
- if _, err = createComment(ctx, opts); err != nil {
+ if _, err = CreateCommentCtx(ctx, opts); err != nil {
return err
}
}
@@ -1956,7 +1953,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
defer committer.Close()
sess := db.GetEngine(ctx)
- if err := issue.loadRepo(ctx); err != nil {
+ if err := issue.LoadRepo(ctx); err != nil {
return nil, false, fmt.Errorf("loadRepo: %v", err)
}
@@ -1983,7 +1980,7 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
OldTitle: currentIssue.Title,
NewTitle: issue.Title,
}
- _, err := createComment(ctx, opts)
+ _, err := CreateCommentCtx(ctx, opts)
if err != nil {
return nil, false, fmt.Errorf("createComment: %v", err)
}
@@ -2015,7 +2012,7 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us
defer committer.Close()
// Update the deadline
- if err = updateIssueCols(ctx, &Issue{ID: issue.ID, DeadlineUnix: deadlineUnix}, "deadline_unix"); err != nil {
+ if err = UpdateIssueCols(ctx, &Issue{ID: issue.ID, DeadlineUnix: deadlineUnix}, "deadline_unix"); err != nil {
return err
}
@@ -2104,14 +2101,14 @@ func deleteIssue(ctx context.Context, issue *Issue) error {
// delete all database data still assigned to this issue
if err := deleteInIssue(e, issue.ID,
- &issues.ContentHistory{},
+ &issues_model.ContentHistory{},
&Comment{},
&IssueLabel{},
&IssueDependency{},
&IssueAssignees{},
&IssueUser{},
&Notification{},
- &issues.Reaction{},
+ &issues_model.Reaction{},
&IssueWatch{},
&Stopwatch{},
&TrackedTime{},
@@ -2242,7 +2239,7 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
if len(mentions) == 0 {
return
}
- if err = issue.loadRepo(ctx); err != nil {
+ if err = issue.LoadRepo(ctx); err != nil {
return
}
@@ -2401,7 +2398,7 @@ func deleteIssuesByRepoID(sess db.Engine, repoID int64) (attachmentPaths []strin
// Delete content histories
if _, err = sess.In("issue_id", deleteCond).
- Delete(&issues.ContentHistory{}); err != nil {
+ Delete(&issues_model.ContentHistory{}); err != nil {
return
}
@@ -2429,7 +2426,7 @@ func deleteIssuesByRepoID(sess db.Engine, repoID int64) (attachmentPaths []strin
}
if _, err = sess.In("issue_id", deleteCond).
- Delete(&issues.Reaction{}); err != nil {
+ Delete(&issues_model.Reaction{}); err != nil {
return
}