Skip to content

Commit

Permalink
Bug fixed for deleted label in issue comment (go-gitea#904)
Browse files Browse the repository at this point in the history
* bug fixed for deleted label in issue comment

* fix indent
  • Loading branch information
lunny committed Feb 11, 2017
1 parent 442145d commit 8a0be5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
11 changes: 6 additions & 5 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions models/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
18 changes: 10 additions & 8 deletions templates/repo/issue/view_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@
</div>
</div>
{{else if eq .Type 7}}
<div class="event">
<span class="octicon octicon-primitive-dot"></span>
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
<img src="{{.Poster.RelAvatarLink}}">
</a>
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
{{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}}</span>
</div>
{{if .Label}}
<div class="event">
<span class="octicon octicon-primitive-dot"></span>
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
<img src="{{.Poster.RelAvatarLink}}">
</a>
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
{{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}}</span>
</div>
{{end}}
{{else if eq .Type 8}}
<div class="event">
<span class="octicon octicon-primitive-dot"></span>
Expand Down

0 comments on commit 8a0be5e

Please sign in to comment.