diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-05 22:36:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-05 22:36:00 +0800 |
commit | f35b20b04212b2085d44d34933c04c4fd30d3a08 (patch) | |
tree | 30efeadd293fed2b656c373decf625927744130a /models | |
parent | 027591a3a556477a26d6c849e1ed9b9a53c15110 (diff) | |
download | gitea-f35b20b04212b2085d44d34933c04c4fd30d3a08.tar.gz gitea-f35b20b04212b2085d44d34933c04c4fd30d3a08.zip |
track issue title changes (#841)
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 20 | ||||
-rw-r--r-- | models/issue_comment.go | 19 |
2 files changed, 36 insertions, 3 deletions
diff --git a/models/issue.go b/models/issue.go index 2f4c157920..7cbb5bb5f8 100644 --- a/models/issue.go +++ b/models/issue.go @@ -641,8 +641,23 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e func (issue *Issue) ChangeTitle(doer *User, title string) (err error) { oldTitle := issue.Title issue.Title = title - if err = UpdateIssueCols(issue, "name"); err != nil { - return fmt.Errorf("UpdateIssueCols: %v", err) + sess := x.NewSession() + defer sess.Close() + + if err = sess.Begin(); err != nil { + return err + } + + if err = updateIssueCols(sess, issue, "name"); err != nil { + return fmt.Errorf("updateIssueCols: %v", err) + } + + if _, err = createChangeTitleComment(sess, doer, issue.Repo, issue, oldTitle, title); err != nil { + return fmt.Errorf("createChangeTitleComment: %v", err) + } + + if err = sess.Commit(); err != nil { + return err } if issue.IsPull { @@ -1106,7 +1121,6 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { return issues, nil } - // UpdateIssueMentions extracts mentioned people from content and // updates issue-user relations for them. func UpdateIssueMentions(e Engine, issueID int64, mentions []string) error { diff --git a/models/issue_comment.go b/models/issue_comment.go index 9e5e87e3c9..e011f5f0d5 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -42,6 +42,8 @@ const ( CommentTypeMilestone // Assignees changed CommentTypeAssignees + // Change Title + CommentTypeChangeTitle ) // CommentTag defines comment tag type @@ -72,6 +74,8 @@ type Comment struct { AssigneeID int64 Assignee *User `xorm:"-"` OldAssignee *User `xorm:"-"` + OldTitle string + NewTitle string CommitID int64 Line int64 @@ -308,6 +312,8 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err CommitSHA: opts.CommitSHA, Line: opts.LineNum, Content: opts.Content, + OldTitle: opts.OldTitle, + NewTitle: opts.NewTitle, } if _, err = e.Insert(comment); err != nil { return nil, err @@ -455,6 +461,17 @@ func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue }) } +func createChangeTitleComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldTitle, newTitle string) (*Comment, error) { + return createComment(e, &CreateCommentOptions{ + Type: CommentTypeChangeTitle, + Doer: doer, + Repo: repo, + Issue: issue, + OldTitle: oldTitle, + NewTitle: newTitle, + }) +} + // CreateCommentOptions defines options for creating comment type CreateCommentOptions struct { Type CommentType @@ -467,6 +484,8 @@ type CreateCommentOptions struct { MilestoneID int64 OldAssigneeID int64 AssigneeID int64 + OldTitle string + NewTitle string CommitID int64 CommitSHA string LineNum int64 |