aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-10-11 14:44:43 +0800
committerGitHub <noreply@github.com>2019-10-11 14:44:43 +0800
commit46a12f196b1742a2462259ed3dd9c33c4c2f150b (patch)
treeb8203c7d6d91841ce53a7b875135714b372fa1a5 /models
parent9ff9f5ad1d8d2680c9c146831458afdbd4e641df (diff)
downloadgitea-46a12f196b1742a2462259ed3dd9c33c4c2f150b.tar.gz
gitea-46a12f196b1742a2462259ed3dd9c33c4c2f150b.zip
Move change issue title from models to issue service package (#8456)
* move change issue title from models to issue service package * make the change less * fix typo
Diffstat (limited to 'models')
-rw-r--r--models/issue.go57
-rw-r--r--models/issue_lock.go17
-rw-r--r--models/issue_test.go2
3 files changed, 17 insertions, 59 deletions
diff --git a/models/issue.go b/models/issue.go
index f8fa1377a8..8ce7d496ab 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -714,11 +714,6 @@ func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
return nil
}
-// UpdateIssueCols only updates values of specific columns for given issue.
-func UpdateIssueCols(issue *Issue, cols ...string) error {
- return updateIssueCols(x, issue, cols...)
-}
-
func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (err error) {
// Reload the issue
currentIssue, err := getIssueByID(e, issue.ID)
@@ -844,9 +839,7 @@ func (issue *Issue) ChangeStatus(doer *User, isClosed bool) (err error) {
}
// ChangeTitle changes the title of this issue, as the given user.
-func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
- oldTitle := issue.Title
- issue.Title = title
+func (issue *Issue) ChangeTitle(doer *User, oldTitle string) (err error) {
sess := x.NewSession()
defer sess.Close()
@@ -862,7 +855,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
return fmt.Errorf("loadRepo: %v", err)
}
- if _, err = createChangeTitleComment(sess, doer, issue.Repo, issue, oldTitle, title); err != nil {
+ if _, err = createChangeTitleComment(sess, doer, issue.Repo, issue, oldTitle, issue.Title); err != nil {
return fmt.Errorf("createChangeTitleComment: %v", err)
}
@@ -874,51 +867,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
return err
}
- if err = sess.Commit(); err != nil {
- return err
- }
- sess.Close()
-
- mode, _ := AccessLevel(issue.Poster, issue.Repo)
- if issue.IsPull {
- if err = issue.loadPullRequest(sess); err != nil {
- return fmt.Errorf("loadPullRequest: %v", err)
- }
- issue.PullRequest.Issue = issue
- err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
- Action: api.HookIssueEdited,
- Index: issue.Index,
- Changes: &api.ChangesPayload{
- Title: &api.ChangesFromPayload{
- From: oldTitle,
- },
- },
- PullRequest: issue.PullRequest.APIFormat(),
- Repository: issue.Repo.APIFormat(mode),
- Sender: doer.APIFormat(),
- })
- } else {
- err = PrepareWebhooks(issue.Repo, HookEventIssues, &api.IssuePayload{
- Action: api.HookIssueEdited,
- Index: issue.Index,
- Changes: &api.ChangesPayload{
- Title: &api.ChangesFromPayload{
- From: oldTitle,
- },
- },
- Issue: issue.APIFormat(),
- Repository: issue.Repo.APIFormat(mode),
- Sender: issue.Poster.APIFormat(),
- })
- }
-
- if err != nil {
- log.Error("PrepareWebhooks [is_pull: %v]: %v", issue.IsPull, err)
- } else {
- go HookQueue.Add(issue.RepoID)
- }
-
- return nil
+ return sess.Commit()
}
// AddDeletePRBranchComment adds delete branch comment for pull request issue
diff --git a/models/issue_lock.go b/models/issue_lock.go
index 5a2d996b64..dc6655ad3b 100644
--- a/models/issue_lock.go
+++ b/models/issue_lock.go
@@ -28,7 +28,6 @@ func updateIssueLock(opts *IssueLockOptions, lock bool) error {
}
opts.Issue.IsLocked = lock
-
var commentType CommentType
if opts.Issue.IsLocked {
commentType = CommentTypeLock
@@ -36,16 +35,26 @@ func updateIssueLock(opts *IssueLockOptions, lock bool) error {
commentType = CommentTypeUnlock
}
- if err := UpdateIssueCols(opts.Issue, "is_locked"); err != nil {
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+
+ if err := updateIssueCols(sess, opts.Issue, "is_locked"); err != nil {
return err
}
- _, err := CreateComment(&CreateCommentOptions{
+ _, err := createComment(sess, &CreateCommentOptions{
Doer: opts.Doer,
Issue: opts.Issue,
Repo: opts.Issue.Repo,
Type: commentType,
Content: opts.Reason,
})
- return err
+ if err != nil {
+ return err
+ }
+
+ return sess.Commit()
}
diff --git a/models/issue_test.go b/models/issue_test.go
index 5b039bc1d5..0be3f68808 100644
--- a/models/issue_test.go
+++ b/models/issue_test.go
@@ -160,7 +160,7 @@ func TestUpdateIssueCols(t *testing.T) {
issue.Content = "This should have no effect"
now := time.Now().Unix()
- assert.NoError(t, UpdateIssueCols(issue, "name"))
+ assert.NoError(t, updateIssueCols(x, issue, "name"))
then := time.Now().Unix()
updatedIssue := AssertExistsAndLoadBean(t, &Issue{ID: issue.ID}).(*Issue)