From 8a0be5e9f01caaf3667c420f08541ac7c26127b8 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 11 Feb 2017 20:56:57 +0800 Subject: [PATCH] Bug fixed for deleted label in issue comment (#904) * bug fixed for deleted label in issue comment * fix indent --- models/issue_comment.go | 11 ++++++----- models/issue_label.go | 5 +++++ templates/repo/issue/view_content.tmpl | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index 2eadba810b30..e133cc049bdc 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -214,12 +214,13 @@ func (c *Comment) LoadLabel() error { has, err := x.ID(c.LabelID).Get(&label) if err != nil { return err - } else if !has { - return ErrLabelNotExist{ - LabelID: c.LabelID, - } + } else if has { + c.Label = &label + } else { + // Ignore Label is deleted, but not clear this table + log.Warn("Commit %d cannot load label %d", c.ID, c.LabelID) } - c.Label = &label + return nil } diff --git a/models/issue_label.go b/models/issue_label.go index 970b3fcc4cfc..015e7f128dcc 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -249,6 +249,11 @@ func DeleteLabel(repoID, labelID int64) error { return err } + // Clear label id in comment table + if _, err = sess.Where("label_id = ?", labelID).Cols("label_id").Update(&Comment{}); err != nil { + return err + } + return sess.Commit() } diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 40993e54d218..381c80cdaf9c 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -145,14 +145,16 @@ {{else if eq .Type 7}} -
- - - - - {{.Poster.Name}} - {{if .Content}}{{$.i18n.Tr "repo.issues.add_label_at" .Label.ForegroundColor .Label.Color .Label.Name $createdStr | Safe}}{{else}}{{$.i18n.Tr "repo.issues.remove_label_at" .Label.ForegroundColor .Label.Color .Label.Name $createdStr | Safe}}{{end}} -
+ {{if .Label}} +
+ + + + + {{.Poster.Name}} + {{if .Content}}{{$.i18n.Tr "repo.issues.add_label_at" .Label.ForegroundColor .Label.Color .Label.Name $createdStr | Safe}}{{else}}{{$.i18n.Tr "repo.issues.remove_label_at" .Label.ForegroundColor .Label.Color .Label.Name $createdStr | Safe}}{{end}} +
+ {{end}} {{else if eq .Type 8}}