diff --git a/cmd/issue_show.go b/cmd/issue_show.go index d42ed73c..74d00576 100644 --- a/cmd/issue_show.go +++ b/cmd/issue_show.go @@ -56,7 +56,7 @@ var issueShowCmd = &cobra.Command{ log.Fatal(err) } - printDiscussions(discussions, since, int(issueNum)) + PrintDiscussions(discussions, since, "issues", int(issueNum)) } }, } @@ -118,10 +118,10 @@ WebURL: %s ) } -func printDiscussions(discussions []*gitlab.Discussion, since string, issueNum int) { +func PrintDiscussions(discussions []*gitlab.Discussion, since string, idstr string, idNum int) { NewAccessTime := time.Now().UTC() - issueEntry := fmt.Sprintf("issue%d", issueNum) + issueEntry := fmt.Sprintf("%s%d", idstr, idNum) // if specified on command line use that, o/w use config, o/w Now var ( CompareTime time.Time diff --git a/cmd/mr_show.go b/cmd/mr_show.go index f491cae6..b2d71ec7 100644 --- a/cmd/mr_show.go +++ b/cmd/mr_show.go @@ -4,16 +4,12 @@ import ( "fmt" "log" "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" "github.com/zaquestion/lab/internal/action" - "github.com/zaquestion/lab/internal/config" "github.com/zaquestion/lab/internal/git" lab "github.com/zaquestion/lab/internal/gitlab" ) @@ -80,7 +76,7 @@ var mrShowCmd = &cobra.Command{ log.Fatal(err) } - printMRDiscussions(discussions, since, int(mrNum)) + PrintDiscussions(discussions, since, "mr", int(mrNum)) } }, } @@ -162,74 +158,6 @@ WebURL: %s mr.Author.Username, milestone, labels, mr.WebURL) } -func printMRDiscussions(discussions []*gitlab.Discussion, since string, mrNum int) { - NewAccessTime := time.Now().UTC() - - mrEntry := fmt.Sprintf("mr%d", mrNum) - // if specified on command line use that, o/w use config, o/w Now - var ( - CompareTime time.Time - err error - sinceIsSet = true - ) - CompareTime, err = dateparse.ParseLocal(since) - if err != nil || CompareTime.IsZero() { - CompareTime = getMainConfig().GetTime(CommandPrefix + mrEntry) - if CompareTime.IsZero() { - CompareTime = time.Now().UTC() - } - sinceIsSet = false - } - - // for available fields, see - // https://godoc.org/github.com/xanzy/go-gitlab#Note - // https://godoc.org/github.com/xanzy/go-gitlab#Discussion - for _, discussion := range discussions { - for i, note := range discussion.Notes { - - // skip system notes - if note.System { - continue - } - - indentHeader, indentNote := "", "" - commented := "commented" - if !time.Time(*note.CreatedAt).Equal(time.Time(*note.UpdatedAt)) { - commented = "updated comment" - } - - if !discussion.IndividualNote { - indentNote = " " - - if i == 0 { - commented = "started a discussion" - } else { - indentHeader = " " - } - } - - printit := color.New().PrintfFunc() - printit(` -%s-----------------------------------`, indentHeader) - - if time.Time(*note.UpdatedAt).After(CompareTime) { - printit = color.New(color.Bold).PrintfFunc() - } - printit(` -%s%s %s at %s - -%s%s -`, - indentHeader, note.Author.Username, commented, time.Time(*note.UpdatedAt).String(), - indentNote, note.Body) - } - } - - if sinceIsSet == false { - config.WriteConfigEntry(CommandPrefix+mrEntry, NewAccessTime, "", "") - } -} - 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")