44 "errors"
55 "fmt"
66 "os"
7+ "regexp"
78 "strconv"
89 "strings"
910
@@ -295,12 +296,6 @@ func reviewSurvey(cmd *cobra.Command) (*api.PullRequestReviewInput, error) {
295296}
296297
297298func patchReview (cmd * cobra.Command ) (* api.PullRequestReviewInput , error ) {
298- type Hunk struct {
299- File string
300- Diff string
301- Comment string
302- }
303-
304299 hunks := []Hunk {
305300 {"diff --git a/command/pr_review.go b/command/pr_review.go" ,
306301 `@@ -11,7 +11,8 @@ import (
@@ -423,6 +418,7 @@ func patchReview(cmd *cobra.Command) (*api.PullRequestReviewInput, error) {
423418 return nil , nil
424419 }
425420
421+ commentsMade := 0
426422 skipFile := false
427423 var skipping string
428424 for _ , hunk := range hunks {
@@ -488,7 +484,11 @@ func patchReview(cmd *cobra.Command) (*api.PullRequestReviewInput, error) {
488484 if err != nil {
489485 return nil , err
490486 }
491- hunk .Comment = bodyAnswers .Body
487+ body := trimBody (bodyAnswers .Body )
488+ if ! isBlank (body ) {
489+ hunk .Comment = bodyAnswers .Body
490+ commentsMade ++
491+ }
492492 }
493493
494494 if action == HunkActionQuit {
@@ -497,11 +497,30 @@ func patchReview(cmd *cobra.Command) (*api.PullRequestReviewInput, error) {
497497 }
498498 }
499499
500- fmt .Fprintln (out )
500+ // TODO commentsMade ending up at 0, debug the string helpers.
501+ fmt .Fprintf (out , "\n Wrapping up a review with %s comments.\n " , utils .Bold (fmt .Sprintf ("%d" , commentsMade )))
502+
503+ reviewData , err := reviewSurvey (cmd )
504+
505+ if err != nil {
506+ return nil , err
507+ }
508+ if reviewData == nil && err == nil {
509+ fmt .Fprint (out , "Discarding.\n " )
510+ return nil , nil
511+ }
512+
513+ fmt .Fprintln (out , "would actually submit, here~" )
501514
502515 return nil , nil
503516}
504517
518+ type Hunk struct {
519+ File string
520+ Diff string
521+ Comment string
522+ }
523+
505524type HunkAction int
506525
507526const (
@@ -546,3 +565,14 @@ func patchSurvey() (HunkAction, error) {
546565
547566 return - 1 , nil
548567}
568+
569+ func trimBody (body string ) string {
570+ r := regexp .MustCompile (`(?s)======= everything below.*$` )
571+ return r .ReplaceAllString (body , "" )
572+ }
573+
574+ func isBlank (body string ) bool {
575+ fmt .Println (body )
576+ r := regexp .MustCompile (`(?s)\w*` )
577+ return r .MatchString (body )
578+ }
0 commit comments