Skip to content

Commit

Permalink
remove duplicated actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Nov 14, 2019
1 parent 5067294 commit 0e063de
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
7 changes: 5 additions & 2 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,10 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
return nil, err
}

if err = sendCreateCommentAction(e, opts, comment); err != nil {
return nil, err
if !opts.NoAction {
if err = sendCreateCommentAction(e, opts, comment); err != nil {
return nil, err
}
}

if err = comment.addCrossReferences(e, opts.Doer); err != nil {
Expand Down Expand Up @@ -816,6 +818,7 @@ type CreateCommentOptions struct {
RefCommentID int64
RefAction references.XRefAction
RefIsPull bool
NoAction bool
}

// CreateComment creates comment of issue or commit.
Expand Down
12 changes: 8 additions & 4 deletions models/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content strin
return nil, nil, err
}
} else {
if err := review.loadCodeComments(sess); err != nil {
return nil, nil, err
}
if len(review.CodeComments) == 0 && len(strings.TrimSpace(content)) == 0 {
return nil, nil, ContentEmptyErr{}
}

review.Issue = issue
review.Content = content
review.Type = reviewType
Expand All @@ -284,16 +291,13 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content strin
Issue: issue,
Repo: issue.Repo,
ReviewID: review.ID,
NoAction: true,
})
if err != nil || comm == nil {
return nil, nil, err
}

comm.Review = review

if err := updateIssueCols(sess, review.Issue, "updated_unix"); err != nil {
return nil, nil, err
}
return review, comm, sess.Commit()
}

Expand Down
24 changes: 13 additions & 11 deletions modules/notification/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,19 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
}
}

actions = append(actions, &models.Action{
ActUserID: review.Reviewer.ID,
ActUser: review.Reviewer,
Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(content, "\n")[0]),
OpType: models.ActionCommentIssue,
RepoID: review.Issue.RepoID,
Repo: review.Issue.Repo,
IsPrivate: review.Issue.Repo.IsPrivate,
Comment: comment,
CommentID: comment.ID,
})
if strings.TrimSpace(comment.Content) != "" {
actions = append(actions, &models.Action{
ActUserID: review.Reviewer.ID,
ActUser: review.Reviewer,
Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(content, "\n")[0]),
OpType: models.ActionCommentIssue,
RepoID: review.Issue.RepoID,
Repo: review.Issue.Repo,
IsPrivate: review.Issue.Repo.IsPrivate,
Comment: comment,
CommentID: comment.ID,
})
}

if err := models.NotifyWatchersActions(actions); err != nil {
log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err)
Expand Down

0 comments on commit 0e063de

Please sign in to comment.