Skip to content

Commit 9981e16

Browse files
committed
report on how many comments made and finish review
1 parent f3f1c4b commit 9981e16

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

command/pr_review.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
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

297298
func 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, "\nWrapping 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+
505524
type HunkAction int
506525

507526
const (
@@ -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

Comments
 (0)