Skip to content

Commit

Permalink
mr show: Add --since option
Browse files Browse the repository at this point in the history
The show command shows all comments in the default font which makes
finding new comments difficult on merge requests with many comments.
It is useful to have a mechanism to highlight, in bold text, new
comments.

Add a --since option which allows users to specify a date to highlight
comments added after that date.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
  • Loading branch information
prarit committed Aug 26, 2020
1 parent 2d4445f commit e1076ee
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions cmd/mr_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"strings"
"time"

"github.com/araddon/dateparse"
"github.com/charmbracelet/glamour"
"github.com/fatih/color"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
Expand Down Expand Up @@ -46,7 +48,12 @@ var mrShowCmd = &cobra.Command{
log.Fatal(err)
}

printMRDiscussions(discussions)
since, err := cmd.Flags().GetString("since")
if err != nil {
log.Fatal(err)
}

printMRDiscussions(discussions, since)
}
},
}
Expand Down Expand Up @@ -98,7 +105,13 @@ WebURL: %s
mr.Author.Username, milestone, labels, mr.WebURL)
}

func printMRDiscussions(discussions []*gitlab.Discussion) {
func printMRDiscussions(discussions []*gitlab.Discussion, since string) {

sinceString, err := dateparse.ParseLocal(since)
if err != nil {
sinceString = time.Now().UTC()
}

// for available fields, see
// https://godoc.org/github.com/xanzy/go-gitlab#Note
// https://godoc.org/github.com/xanzy/go-gitlab#Discussion
Expand Down Expand Up @@ -126,13 +139,18 @@ func printMRDiscussions(discussions []*gitlab.Discussion) {
}
}

fmt.Printf(`
%s-----------------------------------
printit := color.New().PrintfFunc()
printit(`
%s-----------------------------------`, indentHeader)

if time.Time(*note.UpdatedAt).After(sinceString) {
printit = color.New(color.Bold).PrintfFunc()
}
printit(`
%s%s %s at %s
%s%s
`,
indentHeader,
indentHeader, note.Author.Username, commented, time.Time(*note.UpdatedAt).String(),
indentNote, note.Body)
}
Expand All @@ -142,6 +160,7 @@ func printMRDiscussions(discussions []*gitlab.Discussion) {
func init() {
mrShowCmd.Flags().BoolP("no-markdown", "M", false, "Don't use markdown renderer to print the issue description")
mrShowCmd.Flags().BoolP("comments", "c", false, "Show comments for the merge request")
mrShowCmd.Flags().StringP("since", "s", "", "Show comments since specified date (format: 2020-08-21 14:57:46.808 +0000 UTC)")
mrCmd.AddCommand(mrShowCmd)
carapace.Gen(mrShowCmd).PositionalCompletion(
action.Remotes(),
Expand Down

0 comments on commit e1076ee

Please sign in to comment.