remove duplicated actions

This commit is contained in:
Lunny Xiao
2019-11-13 20:54:12 +08:00
parent 5067294f32
commit 0e063de211
3 changed files with 26 additions and 17 deletions

View File

@@ -539,8 +539,10 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
return nil, err return nil, err
} }
if err = sendCreateCommentAction(e, opts, comment); err != nil { if !opts.NoAction {
return nil, err if err = sendCreateCommentAction(e, opts, comment); err != nil {
return nil, err
}
} }
if err = comment.addCrossReferences(e, opts.Doer); err != nil { if err = comment.addCrossReferences(e, opts.Doer); err != nil {
@@ -816,6 +818,7 @@ type CreateCommentOptions struct {
RefCommentID int64 RefCommentID int64
RefAction references.XRefAction RefAction references.XRefAction
RefIsPull bool RefIsPull bool
NoAction bool
} }
// CreateComment creates comment of issue or commit. // CreateComment creates comment of issue or commit.

View File

@@ -269,6 +269,13 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content strin
return nil, nil, err return nil, nil, err
} }
} else { } 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.Issue = issue
review.Content = content review.Content = content
review.Type = reviewType review.Type = reviewType
@@ -284,16 +291,13 @@ func SubmitReview(doer *User, issue *Issue, reviewType ReviewType, content strin
Issue: issue, Issue: issue,
Repo: issue.Repo, Repo: issue.Repo,
ReviewID: review.ID, ReviewID: review.ID,
NoAction: true,
}) })
if err != nil || comm == nil { if err != nil || comm == nil {
return nil, nil, err return nil, nil, err
} }
comm.Review = review comm.Review = review
if err := updateIssueCols(sess, review.Issue, "updated_unix"); err != nil {
return nil, nil, err
}
return review, comm, sess.Commit() return review, comm, sess.Commit()
} }

View File

@@ -149,17 +149,19 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
} }
} }
actions = append(actions, &models.Action{ if strings.TrimSpace(comment.Content) != "" {
ActUserID: review.Reviewer.ID, actions = append(actions, &models.Action{
ActUser: review.Reviewer, ActUserID: review.Reviewer.ID,
Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(content, "\n")[0]), ActUser: review.Reviewer,
OpType: models.ActionCommentIssue, Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(content, "\n")[0]),
RepoID: review.Issue.RepoID, OpType: models.ActionCommentIssue,
Repo: review.Issue.Repo, RepoID: review.Issue.RepoID,
IsPrivate: review.Issue.Repo.IsPrivate, Repo: review.Issue.Repo,
Comment: comment, IsPrivate: review.Issue.Repo.IsPrivate,
CommentID: comment.ID, Comment: comment,
}) CommentID: comment.ID,
})
}
if err := models.NotifyWatchersActions(actions); err != nil { if err := models.NotifyWatchersActions(actions); err != nil {
log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err) log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err)