Send notifications / actions to users until review gets published
Fix diff generation bug Fix wrong hashtag
This commit is contained in:
parent
aee593bc13
commit
8f77329aee
|
@ -352,8 +352,8 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
|
|||
if currentLine == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if len(hunk)-headerLines < numbersOfLine {
|
||||
// headerLines + hunkLine (1) = totalNonCodeLines
|
||||
if len(hunk)-headerLines-1 <= numbersOfLine {
|
||||
// No need to cut the hunk => return existing hunk
|
||||
return strings.Join(hunk, "\n")
|
||||
}
|
||||
|
|
|
@ -459,6 +459,14 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if err = sendCreateCommentAction(e, opts, comment); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return comment, nil
|
||||
}
|
||||
|
||||
func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, comment *Comment) (err error) {
|
||||
// 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{
|
||||
|
@ -471,14 +479,18 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
CommentID: comment.ID,
|
||||
IsPrivate: opts.Repo.IsPrivate,
|
||||
}
|
||||
|
||||
// Check comment type.
|
||||
switch opts.Type {
|
||||
case CommentTypeCode:
|
||||
if comment.Review == nil || comment.Review.Type <= ReviewTypePending {
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
case CommentTypeComment:
|
||||
act.OpType = ActionCommentIssue
|
||||
|
||||
if _, err = e.Exec("UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?", opts.Issue.ID); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
// Check attachments
|
||||
|
@ -489,7 +501,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
if IsErrAttachmentNotExist(err) {
|
||||
continue
|
||||
}
|
||||
return nil, fmt.Errorf("getAttachmentByUUID [%s]: %v", uuid, err)
|
||||
return fmt.Errorf("getAttachmentByUUID [%s]: %v", uuid, err)
|
||||
}
|
||||
attachments = append(attachments, attach)
|
||||
}
|
||||
|
@ -499,7 +511,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
attachments[i].CommentID = comment.ID
|
||||
// No assign value could be 0, so ignore AllCols().
|
||||
if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
|
||||
return nil, fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
|
||||
return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -515,7 +527,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
_, err = e.Exec("UPDATE `repository` SET num_closed_issues=num_closed_issues-1 WHERE id=?", opts.Repo.ID)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
case CommentTypeClose:
|
||||
|
@ -530,15 +542,13 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
_, err = e.Exec("UPDATE `repository` SET num_closed_issues=num_closed_issues+1 WHERE id=?", opts.Repo.ID)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// update the issue's updated_unix column
|
||||
if err = updateIssueCols(e, opts.Issue, "updated_unix"); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
// Notify watchers for whatever action comes in, ignore if no action type.
|
||||
if act.OpType > 0 {
|
||||
if err = notifyWatchers(e, act); err != nil {
|
||||
|
@ -548,8 +558,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
log.Error(4, "MailParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return comment, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func createStatusComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue) (*Comment, error) {
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"github.com/go-xorm/xorm"
|
||||
|
||||
"github.com/go-xorm/builder"
|
||||
)
|
||||
|
@ -97,6 +101,50 @@ func (r *Review) LoadAttributes() error {
|
|||
return r.loadAttributes(x)
|
||||
}
|
||||
|
||||
// Publish will send notifications / actions to participants for all code comments; parts are concurrent
|
||||
func (r *Review) Publish() error {
|
||||
return r.publish(x)
|
||||
}
|
||||
|
||||
func (r *Review) publish(e *xorm.Engine) error {
|
||||
if r.Type == ReviewTypePending || r.Type == ReviewTypeUnknown {
|
||||
return fmt.Errorf("review cannot be published if type is pending or unknown")
|
||||
}
|
||||
if r.Issue == nil {
|
||||
if err := r.loadIssue(e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := r.Issue.loadRepo(e); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(r.CodeComments) == 0 {
|
||||
if err := r.loadCodeComments(e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, lines := range r.CodeComments {
|
||||
for _, comments := range lines {
|
||||
for _, comment := range comments {
|
||||
go func() {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sendCreateCommentAction(sess, &CreateCommentOptions{
|
||||
Doer: comment.Poster,
|
||||
Issue: r.Issue,
|
||||
Repo: r.Issue.Repo,
|
||||
Type: comment.Type,
|
||||
Content: comment.Content,
|
||||
}, comment); err != nil {
|
||||
log.Warn("sendCreateCommentAction: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getReviewByID(e Engine, id int64) (*Review, error) {
|
||||
review := new(Review)
|
||||
if has, err := e.ID(id).Get(review); err != nil {
|
||||
|
|
|
@ -101,25 +101,6 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) {
|
|||
}
|
||||
var review *models.Review
|
||||
var err error
|
||||
defer func() {
|
||||
if review != nil {
|
||||
comm, err := models.CreateComment(&models.CreateCommentOptions{
|
||||
Type: models.CommentTypeReview,
|
||||
Doer: ctx.User,
|
||||
Content: review.Content,
|
||||
Issue: issue,
|
||||
Repo: issue.Repo,
|
||||
ReviewID: review.ID,
|
||||
})
|
||||
if err != nil || comm == nil {
|
||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
||||
return
|
||||
}
|
||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d#%s", ctx.Repo.RepoLink, issue.Index, comm.HashTag()))
|
||||
} else {
|
||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
|
||||
}
|
||||
}()
|
||||
|
||||
reviewType := form.ReviewType()
|
||||
if reviewType == models.ReviewTypeUnknown {
|
||||
|
@ -142,11 +123,29 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) {
|
|||
ctx.ServerError("CreateReview", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
review.Content = form.Content
|
||||
review.Type = reviewType
|
||||
if err = models.UpdateReview(review); err != nil {
|
||||
ctx.ServerError("UpdateReview", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
comm, err := models.CreateComment(&models.CreateCommentOptions{
|
||||
Type: models.CommentTypeReview,
|
||||
Doer: ctx.User,
|
||||
Content: review.Content,
|
||||
Issue: issue,
|
||||
Repo: issue.Repo,
|
||||
ReviewID: review.ID,
|
||||
})
|
||||
if err != nil || comm == nil {
|
||||
ctx.ServerError("CreateComment", err)
|
||||
return
|
||||
}
|
||||
review.Content = form.Content
|
||||
review.Type = reviewType
|
||||
if err = models.UpdateReview(review); err != nil {
|
||||
if err = review.Publish(); err != nil {
|
||||
ctx.ServerError("Publish", err)
|
||||
return
|
||||
}
|
||||
ctx.Redirect(fmt.Sprintf("%s/pulls/%d#%s", ctx.Repo.RepoLink, issue.Index, comm.HashTag()))
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@
|
|||
<div class="ui comments">
|
||||
{{range $comms}}
|
||||
{{ $createdSubStr:= TimeSinceUnix .CreatedUnix $.Lang }}
|
||||
<div class="comment">
|
||||
<div class="comment" id="{{.HashTag}}">
|
||||
<a class="avatar">
|
||||
<img src="{{.Poster.RelAvatarLink}}">
|
||||
</a>
|
||||
|
|
Loading…
Reference in New Issue
Block a user