@@ -535,6 +535,10 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
535
535
return nil , err
536
536
}
537
537
538
+ if err = updateCommentInfos (e , opts , comment ); err != nil {
539
+ return nil , err
540
+ }
541
+
538
542
if err = sendCreateCommentAction (e , opts , comment ); err != nil {
539
543
return nil , err
540
544
}
@@ -546,19 +550,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
546
550
return comment , nil
547
551
}
548
552
549
- func sendCreateCommentAction (e * xorm.Session , opts * CreateCommentOptions , comment * Comment ) (err error ) {
550
- // Compose comment action, could be plain comment, close or reopen issue/pull request.
551
- // This object will be used to notify watchers in the end of function.
552
- act := & Action {
553
- ActUserID : opts .Doer .ID ,
554
- ActUser : opts .Doer ,
555
- Content : fmt .Sprintf ("%d|%s" , opts .Issue .Index , strings .Split (opts .Content , "\n " )[0 ]),
556
- RepoID : opts .Repo .ID ,
557
- Repo : opts .Repo ,
558
- Comment : comment ,
559
- CommentID : comment .ID ,
560
- IsPrivate : opts .Repo .IsPrivate ,
561
- }
553
+ func updateCommentInfos (e * xorm.Session , opts * CreateCommentOptions , comment * Comment ) (err error ) {
562
554
// Check comment type.
563
555
switch opts .Type {
564
556
case CommentTypeCode :
@@ -574,8 +566,6 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen
574
566
}
575
567
fallthrough
576
568
case CommentTypeComment :
577
- act .OpType = ActionCommentIssue
578
-
579
569
if _ , err = e .Exec ("UPDATE `issue` SET num_comments=num_comments+1 WHERE id=?" , opts .Issue .ID ); err != nil {
580
570
return err
581
571
}
@@ -601,30 +591,54 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen
601
591
return fmt .Errorf ("update attachment [%d]: %v" , attachments [i ].ID , err )
602
592
}
603
593
}
594
+ case CommentTypeReopen , CommentTypeClose :
595
+ if err = opts .Issue .updateClosedNum (e ); err != nil {
596
+ return err
597
+ }
598
+ }
599
+ // update the issue's updated_unix column
600
+ return updateIssueCols (e , opts .Issue , "updated_unix" )
601
+ }
604
602
603
+ func sendCreateCommentAction (e * xorm.Session , opts * CreateCommentOptions , comment * Comment ) (err error ) {
604
+ // Compose comment action, could be plain comment, close or reopen issue/pull request.
605
+ // This object will be used to notify watchers in the end of function.
606
+ act := & Action {
607
+ ActUserID : opts .Doer .ID ,
608
+ ActUser : opts .Doer ,
609
+ Content : fmt .Sprintf ("%d|%s" , opts .Issue .Index , strings .Split (opts .Content , "\n " )[0 ]),
610
+ RepoID : opts .Repo .ID ,
611
+ Repo : opts .Repo ,
612
+ Comment : comment ,
613
+ CommentID : comment .ID ,
614
+ IsPrivate : opts .Repo .IsPrivate ,
615
+ }
616
+ // Check comment type.
617
+ switch opts .Type {
618
+ case CommentTypeCode :
619
+ if comment .ReviewID != 0 {
620
+ if comment .Review == nil {
621
+ if err := comment .loadReview (e ); err != nil {
622
+ return err
623
+ }
624
+ }
625
+ if comment .Review .Type <= ReviewTypePending {
626
+ return nil
627
+ }
628
+ }
629
+ fallthrough
630
+ case CommentTypeComment :
631
+ act .OpType = ActionCommentIssue
605
632
case CommentTypeReopen :
606
633
act .OpType = ActionReopenIssue
607
634
if opts .Issue .IsPull {
608
635
act .OpType = ActionReopenPullRequest
609
636
}
610
-
611
- if err = opts .Issue .updateClosedNum (e ); err != nil {
612
- return err
613
- }
614
-
615
637
case CommentTypeClose :
616
638
act .OpType = ActionCloseIssue
617
639
if opts .Issue .IsPull {
618
640
act .OpType = ActionClosePullRequest
619
641
}
620
-
621
- if err = opts .Issue .updateClosedNum (e ); err != nil {
622
- return err
623
- }
624
- }
625
- // update the issue's updated_unix column
626
- if err = updateIssueCols (e , opts .Issue , "updated_unix" ); err != nil {
627
- return err
628
642
}
629
643
// Notify watchers for whatever action comes in, ignore if no action type.
630
644
if act .OpType > 0 {
0 commit comments