diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-01-30 20:46:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-30 20:46:45 +0800 |
commit | f94869d2d19afd7110a0b996a7e6da339fb4e161 (patch) | |
tree | 8fe91beb0dcfce8e78515ebd525ee1decb633e68 /models/issue_comment.go | |
parent | d078aa30d6e6f40978ea68e9ae6eee53dc028ada (diff) | |
download | gitea-f94869d2d19afd7110a0b996a7e6da339fb4e161.tar.gz gitea-f94869d2d19afd7110a0b996a7e6da339fb4e161.zip |
Track labels changed on issue view & resolved #542 (#788)
* track labels changed on issue view & resolved #542
* add missing head comment & sort & fix refresh
Diffstat (limited to 'models/issue_comment.go')
-rw-r--r-- | models/issue_comment.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go index bab002fcad..be7044a8e7 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -36,6 +36,8 @@ const ( CommentTypeCommentRef // Reference from a pull request CommentTypePullRef + // Labels changed + CommentTypeLabel ) // CommentTag defines comment tag type @@ -57,6 +59,8 @@ type Comment struct { Poster *User `xorm:"-"` IssueID int64 `xorm:"INDEX"` CommitID int64 + LabelID int64 + Label *Label `xorm:"-"` Line int64 Content string `xorm:"TEXT"` RenderedContent string `xorm:"-"` @@ -185,6 +189,21 @@ func (c *Comment) EventTag() string { return "event-" + com.ToStr(c.ID) } +// LoadLabel if comment.Type is CommentTypeLabel, then load Label +func (c *Comment) LoadLabel() error { + var label Label + has, err := x.ID(c.LabelID).Get(&label) + if err != nil { + return err + } else if !has { + return ErrLabelNotExist{ + LabelID: c.LabelID, + } + } + c.Label = &label + return nil +} + // MailParticipants sends new comment emails to repository watchers // and mentioned people. func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (err error) { @@ -209,11 +228,16 @@ func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (e } func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) { + var LabelID int64 + if opts.Label != nil { + LabelID = opts.Label.ID + } comment := &Comment{ Type: opts.Type, PosterID: opts.Doer.ID, Poster: opts.Doer, IssueID: opts.Issue.ID, + LabelID: LabelID, CommitID: opts.CommitID, CommitSHA: opts.CommitSHA, Line: opts.LineNum, @@ -223,6 +247,10 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err return nil, err } + if err = opts.Repo.getOwner(e); err != nil { + return nil, err + } + // Compose comment action, could be plain comment, close or reopen issue/pull request. // This object will be used to notify watchers in the end of function. act := &Action{ @@ -324,12 +352,28 @@ func createStatusComment(e *xorm.Session, doer *User, repo *Repository, issue *I }) } +func createLabelComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, label *Label, add bool) (*Comment, error) { + var content string + if add { + content = "1" + } + return createComment(e, &CreateCommentOptions{ + Type: CommentTypeLabel, + Doer: doer, + Repo: repo, + Issue: issue, + Label: label, + Content: content, + }) +} + // CreateCommentOptions defines options for creating comment type CreateCommentOptions struct { Type CommentType Doer *User Repo *Repository Issue *Issue + Label *Label CommitID int64 CommitSHA string |