Hook up the UpdateIssuesComment function to various actions

The UpdateIssuesComment function is now being called when:
- a pull request is merged, so the pull request title or description can
open/close issues
- a new pull request is created, so it can reference an issue from its
title or description
- a new issue is created, so it can reference an issue from its title or
description
- a pull request or issue title or description is updated
- a comment is created or updated, so it can reference an issue from its
title or description
This commit is contained in:
Keith Rutkowski 2018-04-02 10:28:46 -04:00
parent 59d91723a1
commit e20edf6507
3 changed files with 57 additions and 0 deletions

View File

@ -805,6 +805,10 @@ func MergePullRequestAction(doer *User, repo *Repository, pull *Issue, commits *
log.Error(4, "UpdateIssuesCommit: %v", err)
}
if err := UpdateIssuesComment(doer, repo, pull, nil, true); err != nil {
log.Error(4, "UpdateIssuesCommit: %v", err)
}
if err := notifyWatchers(x, &Action{
ActUserID: doer.ID,
ActUser: doer,
@ -826,6 +830,10 @@ func NewPullRequestAction(doer *User, repo *Repository, pull *Issue, commits *Pu
log.Error(4, "UpdateIssuesCommit: %v", err)
}
if err := UpdateIssuesComment(doer, repo, pull, nil, false); err != nil {
log.Error(4, "UpdateIssuesCommit: %v", err)
}
if err := NotifyWatchers(&Action{
ActUserID: doer.ID,
ActUser: doer,
@ -849,6 +857,30 @@ func CommitPullRequestAction(doer *User, repo *Repository, commits *PushCommits)
log.Error(4, "UpdateIssuesCommit: %v", err)
}
// no action added
return nil
}
// CreateOrUpdateCommentAction adds new action when creating or updating a comment.
func CreateOrUpdateCommentAction(doer *User, repo *Repository, issue *Issue, comment *Comment) error {
if err := UpdateIssuesComment(doer, repo, issue, comment, false); err != nil {
log.Error(4, "UpdateIssuesComment: %v", err)
}
// no action added
return nil
}
// CreateOrUpdateIssueAction adds new action when creating a new issue or pull request.
func CreateOrUpdateIssueAction(doer *User, repo *Repository, issue *Issue) error {
if err := UpdateIssuesComment(doer, repo, issue, nil, false); err != nil {
log.Error(4, "UpdateIssuesComment: %v", err)
}
// no action added
return nil
}

View File

@ -802,6 +802,10 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
go HookQueue.Add(issue.RepoID)
}
if err = CreateOrUpdateIssueAction(doer, issue.Repo, issue); err != nil {
return fmt.Errorf("CreateOrUpdateIssueAction: %v", err)
}
return nil
}
@ -867,6 +871,10 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
go HookQueue.Add(issue.RepoID)
}
if err = CreateOrUpdateIssueAction(doer, issue.Repo, issue); err != nil {
return fmt.Errorf("CreateOrUpdateIssueAction: %v", err)
}
return nil
}
@ -1037,6 +1045,10 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, assigneeIDs []in
UpdateIssueIndexer(issue.ID)
if err = CreateOrUpdateIssueAction(issue.Poster, issue.Repo, issue); err != nil {
return fmt.Errorf("CreateOrUpdateIssueAction: %v", err)
}
if err = NotifyWatchers(&Action{
ActUserID: issue.Poster.ID,
ActUser: issue.Poster,

View File

@ -590,6 +590,10 @@ func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
if opts.Type == CommentTypeComment {
UpdateIssueIndexer(opts.Issue.ID)
if err = CreateOrUpdateCommentAction(comment.Poster, opts.Repo, opts.Issue, comment); err != nil {
return nil, err
}
}
return comment, nil
}
@ -758,6 +762,15 @@ func UpdateComment(doer *User, c *Comment, oldContent string) error {
return err
} else if c.Type == CommentTypeComment {
UpdateIssueIndexer(c.IssueID)
issue, err := GetIssueByID(c.IssueID)
if err != nil {
return err
}
if err = CreateOrUpdateCommentAction(c.Poster, issue.Repo, issue, c); err != nil {
return err
}
}
if err := c.LoadIssue(); err != nil {