From e1076ee841cb615fd7ce4e112e4cf3219caba8b9 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Fri, 21 Aug 2020 13:05:49 -0400 Subject: [PATCH] mr show: Add --since option 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 --- cmd/mr_show.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/cmd/mr_show.go b/cmd/mr_show.go index 7e6c6574..e174bb1e 100644 --- a/cmd/mr_show.go +++ b/cmd/mr_show.go @@ -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" @@ -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) } }, } @@ -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 @@ -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) } @@ -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(),