Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track issue title changes #841

Merged
merged 1 commit into from
Feb 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const (
CommentTypeMilestone
// Assignees changed
CommentTypeAssignees
// Change Title
CommentTypeChangeTitle
)

// CommentTag defines comment tag type
Expand Down Expand Up @@ -72,6 +74,8 @@ type Comment struct {
AssigneeID int64
Assignee *User `xorm:"-"`
OldAssignee *User `xorm:"-"`
OldTitle string
NewTitle string

CommitID int64
Line int64
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -467,6 +484,8 @@ type CreateCommentOptions struct {
MilestoneID int64
OldAssigneeID int64
AssigneeID int64
OldTitle string
NewTitle string
CommitID int64
CommitSHA string
LineNum int64
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ issues.remove_milestone_at = `removed this from the <b>%s</b> milestone %s`
issues.self_assign_at = `self-assigned this %s`
issues.add_assignee_at = `was assigned by <b>%s</b> %s`
issues.remove_assignee_at = `removed their assignment %s`
issues.change_title_at = `changed title from <b>%s</b> to <b>%s</b> %s`
issues.open_tab = %d Open
issues.close_tab = %d Closed
issues.filter_label = Label
Expand Down
4 changes: 4 additions & 0 deletions options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ issues.remove_label_at = ` %[4]s 删除了标签 <div class="ui label" style="co
issues.add_milestone_at = ` %[2]s 添加了里程碑 <b>%[1]s</b>`
issues.change_milestone_at = `%[3]s 修改了里程碑从 <b>%[1]s</b> 到 <b>%[2]s</b>`
issues.remove_milestone_at = `%[2]s 删除了里程碑 <b>%[1]s</b>`
issues.self_assign_at = `于 %s 指派给自己`
issues.add_assignee_at = `于 %[2]s 被 <b>%[1]s</b> 指派`
issues.remove_assignee_at = `于 %s 取消了指派`
issues.change_title_at = `于 %[3]s 修改标题 <b>%[1]s</b> 为 <b>%[2]s</b>`
issues.open_tab=%d 个开启中
issues.close_tab=%d 个已关闭
issues.filter_label=标签筛选
Expand Down
1 change: 1 addition & 0 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ function initRepository() {
function (data) {
$editInput.val(data.title);
$issueTitle.text(data.title);
location.reload();
});
return false;
});
Expand Down
10 changes: 10 additions & 0 deletions templates/repo/issue/view_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@
<img src="{{.Poster.RelAvatarLink}}">
</a> <span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> {{$.i18n.Tr "repo.issues.remove_assignee_at" $createdStr | Safe}} </span>{{end}}
</div>
{{else if eq .Type 10}}
<div class="event">
<span class="octicon octicon-primitive-dot"></span>
</div>
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
<img src="{{.Poster.RelAvatarLink}}">
</a>
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
{{$.i18n.Tr "repo.issues.change_title_at" .OldTitle .NewTitle $createdStr | Safe}}
</span>
{{end}}

{{end}}
Expand Down