Skip to content

Commit

Permalink
show: Migrate metadata to lab toml file
Browse files Browse the repository at this point in the history
Migrate the show command's metadata to the lab toml file.  This can be
done by using the nested key feature of viper and toml.  For example,
the .git/lab/show_metadata.toml file contains

comments = true
mr49 = 2020-09-16T15:49:07Z
issue23 = 2020-09-10T10:22:01Z

and the new .git/lab/lab.toml will contain

[mr_show]
  comments = true
  mr49 = 2020-09-16T15:49:07Z
[issue_show]
  comments = true
  issue23 = 2020-09-10T10:22:01Z

This new model allows for better default command granularity.  In the
existing show_metadata.toml "comments = true" affects both the 'mr show'
and 'issue show' commands.  In the new lab.toml the setting can be set for
each command.

Centralizing around lab.toml will also allow for future changes to the
config layout.

I am not writing a show_metadata.toml to lab.toml conversion function
because the metadata functionality is very new.

Migrate the show command metadata to the lab toml file.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>

this mr_show and issue_show
  • Loading branch information
prarit committed Sep 18, 2020
1 parent c7ddf19 commit 4289c25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions cmd/issue_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

var (
issueShowConfig *viper.Viper
issueShowPrefix string = "issue_show."
)

var issueShowCmd = &cobra.Command{
Expand All @@ -39,7 +40,7 @@ var issueShowCmd = &cobra.Command{
log.Fatal(err)
}

issueShowConfig = config.LoadConfig("", "show_metadata")
issueShowConfig = config.LoadConfig("", "")

noMarkdown, _ := cmd.Flags().GetBool("no-markdown")
if err != nil {
Expand All @@ -51,7 +52,7 @@ var issueShowCmd = &cobra.Command{

showComments, _ := cmd.Flags().GetBool("comments")
if showComments == false {
showComments = issueShowConfig.GetBool("comments")
showComments = issueShowConfig.GetBool(issueShowPrefix + "comments")
}
if showComments {
discussions, err := lab.IssueListDiscussions(rn, int(issueNum))
Expand Down Expand Up @@ -138,7 +139,7 @@ func printDiscussions(discussions []*gitlab.Discussion, since string, issueNum i
)
CompareTime, err = dateparse.ParseLocal(since)
if err != nil || CompareTime.IsZero() {
CompareTime = issueShowConfig.GetTime(issueEntry)
CompareTime = issueShowConfig.GetTime(issueShowPrefix + issueEntry)
if CompareTime.IsZero() {
CompareTime = time.Now().UTC()
}
Expand Down Expand Up @@ -189,7 +190,7 @@ func printDiscussions(discussions []*gitlab.Discussion, since string, issueNum i
}

if sinceIsSet == false {
config.WriteConfigEntry(issueEntry, NewAccessTime, "", "show_metadata")
config.WriteConfigEntry(issueShowPrefix+issueEntry, NewAccessTime, "", "")
}
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/mr_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
mrShowPatch bool
mrShowPatchReverse bool
mrShowConfig *viper.Viper
mrShowPrefix string = "mr_show."
)

var mrShowCmd = &cobra.Command{
Expand All @@ -42,7 +43,7 @@ var mrShowCmd = &cobra.Command{
log.Fatal(err)
}

mrShowConfig = config.LoadConfig("", "show_metadata")
mrShowConfig = config.LoadConfig("", "")

noMarkdown, _ := cmd.Flags().GetBool("no-markdown")
if err != nil {
Expand Down Expand Up @@ -72,7 +73,7 @@ var mrShowCmd = &cobra.Command{

showComments, _ := cmd.Flags().GetBool("comments")
if showComments == false {
showComments = mrShowConfig.GetBool("comments")
showComments = mrShowConfig.GetBool(mrShowPrefix + "comments")
}
if showComments {
discussions, err := lab.MRListDiscussions(rn, int(mrNum))
Expand Down Expand Up @@ -179,7 +180,7 @@ func printMRDiscussions(discussions []*gitlab.Discussion, since string, mrNum in
)
CompareTime, err = dateparse.ParseLocal(since)
if err != nil || CompareTime.IsZero() {
CompareTime = mrShowConfig.GetTime(mrEntry)
CompareTime = mrShowConfig.GetTime(mrShowPrefix + mrEntry)
if CompareTime.IsZero() {
CompareTime = time.Now().UTC()
}
Expand Down Expand Up @@ -231,7 +232,7 @@ func printMRDiscussions(discussions []*gitlab.Discussion, since string, mrNum in
}

if sinceIsSet == false {
config.WriteConfigEntry("show."+mrEntry, NewAccessTime, "", "show_metadata")
config.WriteConfigEntry(mrShowPrefix+mrEntry, NewAccessTime, "", "")
}
}

Expand Down

0 comments on commit 4289c25

Please sign in to comment.