From d8b89b01db975144e3fe121762253275cb702142 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 5 Feb 2017 11:22:59 +0800 Subject: [PATCH] track issue title changes --- models/issue.go | 20 +++++++++++++++++--- models/issue_comment.go | 19 +++++++++++++++++++ options/locale/locale_en-US.ini | 1 + options/locale/locale_zh-CN.ini | 4 ++++ public/js/index.js | 1 + templates/repo/issue/view_content.tmpl | 10 ++++++++++ 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/models/issue.go b/models/issue.go index 2f4c15792064..7cbb5bb5f897 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 9e5e87e3c9c3..e011f5f0d546 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 diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 0859709db170..e86ef61dfe0f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -549,6 +549,7 @@ issues.remove_milestone_at = `removed this from the %s milestone %s` issues.self_assign_at = `self-assigned this %s` issues.add_assignee_at = `was assigned by %s %s` issues.remove_assignee_at = `removed their assignment %s` +issues.change_title_at = `changed title from %s to %s %s` issues.open_tab = %d Open issues.close_tab = %d Closed issues.filter_label = Label diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index dfb9bbb17282..ac2e906ff48b 100644 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -506,6 +506,10 @@ issues.remove_label_at = ` %[4]s 删除了标签
{{.Poster.Name}} {{$.i18n.Tr "repo.issues.remove_assignee_at" $createdStr | Safe}} {{end}}
+ {{else if eq .Type 10}} +
+ +
+ + + + {{.Poster.Name}} + {{$.i18n.Tr "repo.issues.change_title_at" .OldTitle .NewTitle $createdStr | Safe}} + {{end}} {{end}}