From 20bc28ad368684b403aac72d50dac341ded9145d Mon Sep 17 00:00:00 2001 From: Ryan D McGuire Date: Thu, 7 Dec 2023 12:08:56 -0500 Subject: [PATCH] wip --- cmd/clear.go | 29 +++++++ cmd/dump.go | 43 +--------- cmd/init.go | 32 +++++--- cmd/load.go | 20 ++--- cmd/root.go | 40 ++++----- go.mod | 15 +++- go.sum | 83 ++++++++++++++++++- internal/config/config.go | 7 +- internal/gitlab/gitlab.go | 147 +++++++++++++++++++++++++++++++--- internal/projects/cache.go | 62 ++++++++++---- internal/projects/projects.go | 53 ++++++++++++ 11 files changed, 411 insertions(+), 120 deletions(-) create mode 100644 cmd/clear.go create mode 100644 internal/projects/projects.go diff --git a/cmd/clear.go b/cmd/clear.go new file mode 100644 index 0000000..5ccc45a --- /dev/null +++ b/cmd/clear.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "github.com/spf13/cobra" + "github.com/spf13/viper" + "golang.org/x/exp/slog" +) + +const longDesc = `Used to reset a project cache, forcing it to be rebuilt. + +If --clearAliases is provided, will also reset aliases. Use with caution.` + +var clearCmd = &cobra.Command{ + Use: "clear", + Short: "Clear GitLab Project Cache", + Long: longDesc, + Run: clearCache, +} + +func clearCache(cmd *cobra.Command, args []string) { + slog.Debug("Preparing to clear local cache") + cache.Clear(conf.Cache.Clear.ClearAliases) +} + +func init() { + cacheCmd.AddCommand(clearCmd) + clearCmd.Flags().Bool("clearAliases", false, "Will also clear aliases from the cache, use with caution") + viper.BindPFlag("cache.clear.clearAliases", clearCmd.LocalFlags().Lookup("clearAliases")) +} diff --git a/cmd/dump.go b/cmd/dump.go index 2eb92e1..c1149bf 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -1,24 +1,3 @@ -/* -Copyright © 2023 Ryan McGuire - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ package cmd import ( @@ -27,31 +6,15 @@ import ( "github.com/spf13/cobra" ) -// dumpCmd represents the dump command var dumpCmd = &cobra.Command{ Use: "dump", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "Dump GitLab project cache", + Long: `Dumps cache to display`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("dump called") + fmt.Println(cache.String()) }, } func init() { cacheCmd.AddCommand(dumpCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // dumpCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // dumpCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/init.go b/cmd/init.go index 642256f..a129bec 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -7,8 +7,8 @@ import ( "strings" "github.com/spf13/cobra" + "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab" "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/projects" - "golang.org/x/exp/slog" "golang.org/x/sys/unix" ) @@ -18,22 +18,28 @@ import ( // func from their PersistentPreRun commands func initProjectCache(cmd *cobra.Command, args []string) { - slog.Debug("Running persistent pre-run for cacheCmd") + plog.Debug("Running persistent pre-run for cacheCmd") conf.Cache.File = conf.ProjectPath + "/.cache.json" - var err error + gitlabClient, err := gitlab.NewGitlabClient(cmd.Context(), conf.GitlabHost, conf.GitlabToken) + if err != nil { + plog.Error("Failed to create GitLab client", plog.Args("error", err)) + os.Exit(1) + } + cacheOpts := &projects.CacheOpts{ Path: conf.Cache.File, TTL: conf.Cache.Ttl, - Logger: slog.Default(), + Logger: plog, + Gitlab: gitlabClient, } if cache, err = projects.NewProjectCache(cacheOpts); err != nil { - slog.Error("Failed to prepare project cache", "error", err) + plog.Error("Failed to prepare project cache", plog.Args("error", err)) os.Exit(1) } if err := cache.Load(); err != nil { - slog.Error("Cache load failed", "error", err) + plog.Error("Cache load failed", plog.Args("error", err)) os.Exit(1) } } @@ -43,25 +49,25 @@ func postProjectCache(cmd *cobra.Command, args []string) { } func initProjectPath(cmd *cobra.Command, args []string) { - slog.Debug("Running persistent pre-run for rootCmd") + plog.Debug("Running persistent pre-run for rootCmd") var err error if conf.ProjectPath, err = resolvePath(conf.ProjectPath); err != nil { - slog.Error("Failed to determine project path", "error", err) + plog.Error("Failed to determine project path", plog.Args("error", err)) os.Exit(1) } _, err = os.Stat(conf.ProjectPath) if err != nil { - slog.Error("Failed to stat project path, trying to create", "error", err) + plog.Error("Failed to stat project path, trying to create", plog.Args("error", err)) if err := os.Mkdir(conf.ProjectPath, 0750); err != nil { - slog.Error("Failed to create project path", "error", err) + plog.Error("Failed to create project path", plog.Args("error", err)) os.Exit(1) } - slog.Info("Project path created", "path", conf.ProjectPath) + plog.Info("Project path created", plog.Args("path", conf.ProjectPath)) } else { if err = unix.Access(conf.ProjectPath, unix.W_OK); err != nil { - slog.Error("Unable to write to project path", + plog.Error("Unable to write to project path", plog.Args( "path", conf.ProjectPath, - "error", err) + "error", err)) os.Exit(1) } } diff --git a/cmd/load.go b/cmd/load.go index d0d2992..a5903d9 100644 --- a/cmd/load.go +++ b/cmd/load.go @@ -1,32 +1,22 @@ package cmd import ( - "fmt" - "github.com/spf13/cobra" ) -// loadCmd represents the load command var loadCmd = &cobra.Command{ Use: "load", Short: "Load GitLab Project Cache", Long: `Used to initialize or update a new GitLab cache. With thousands of projects, it would be too much work to hit the API every time a user wants to find a new project.`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("load called") - }, + Run: loadCache, +} + +func loadCache(cmd *cobra.Command, args []string) { + cache.Refresh() } func init() { cacheCmd.AddCommand(loadCmd) - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // loadCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // loadCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/cmd/root.go b/cmd/root.go index 0838afe..29db9a0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -6,10 +6,10 @@ import ( "os/signal" "strings" + "github.com/pterm/pterm" "github.com/spf13/cobra" "github.com/spf13/viper" "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config" - "golang.org/x/exp/slog" ) const ( @@ -19,6 +19,7 @@ const ( ) var conf config.Config +var plog *pterm.Logger var rootCmd = &cobra.Command{ Use: "gitlab-project-manager", @@ -44,7 +45,7 @@ func Execute() { err := rootCmd.ExecuteContext(ctx) if err != nil { - slog.Error("Failed to execute command", "err", err) + plog.Error("Failed to execute command", plog.Args("err", err)) os.Exit(1) } } @@ -89,47 +90,48 @@ func initConfig() { checkConfigPerms(viper.ConfigFileUsed()) // Abort on world-readable config - // Configure default logger - logger := slog.New(slog.NewTextHandler(os.Stdout, - &slog.HandlerOptions{Level: getSlogLevel(viper.GetString("logLevel"))})) - slog.SetDefault(logger) + // Configure pretty logger + plog = pterm.DefaultLogger.WithLevel(getPtermLogLevel(viper.GetString("logLevel"))) + if plog.Level == pterm.LogLevelDebug { + pterm.EnableDebugMessages() + } // Load into struct to not be so darn pythonic, retrieving // settings by untyped string "name" if err := viper.Unmarshal(&conf); err != nil { - slog.Error("Failed loading config", "err", err) + plog.Error("Failed loading config", plog.Args("err", err)) } - slog.Debug("Configuration loaded", "conf", conf) + plog.Debug("Configuration loaded", plog.Args("conf", conf)) } -func getSlogLevel(level string) slog.Level { - var slogLevel slog.Level +func getPtermLogLevel(level string) pterm.LogLevel { + var pLevel pterm.LogLevel switch strings.ToLower(level) { case "error": - slogLevel = slog.LevelError + pLevel = pterm.LogLevelError case "warn": - slogLevel = slog.LevelWarn + pLevel = pterm.LogLevelWarn case "info": - slogLevel = slog.LevelInfo + pLevel = pterm.LogLevelInfo case "debug": - slogLevel = slog.LevelDebug + pLevel = pterm.LogLevelDebug default: - slogLevel = slog.LevelInfo + pLevel = pterm.LogLevelInfo } - return slogLevel + return pLevel } // Don't allow world-readable configuration func checkConfigPerms(file string) { stat, err := os.Stat(file) if err != nil { - slog.Error("Failure reading configuration", "err", err) + plog.Error("Failure reading configuration", plog.Args("err", err)) return } if stat.Mode().Perm()&0004 == 0004 { - slog.Error("Configuration is world-readable. Recomment 0400.", - "mode", stat.Mode().String()) + plog.Error("Configuration is world-readable. Recomment 0400.", + plog.Args("mode", stat.Mode().String())) os.Exit(1) } } diff --git a/go.mod b/go.mod index 6951613..8917341 100644 --- a/go.mod +++ b/go.mod @@ -3,23 +3,34 @@ module gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager go 1.21.2 require ( + github.com/pterm/pterm v0.12.71 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.17.0 github.com/xanzy/go-gitlab v0.94.0 golang.org/x/exp v0.0.0-20231127185646-65229373498e + golang.org/x/sys v0.13.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( + atomicgo.dev/cursor v0.2.0 // indirect + atomicgo.dev/keyboard v0.2.9 // indirect + atomicgo.dev/schedule v0.1.0 // indirect + github.com/containerd/console v1.0.3 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-querystring v1.1.0 // indirect + github.com/gookit/color v1.5.4 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/lithammer/fuzzysearch v1.1.8 // indirect github.com/magiconair/properties v1.8.7 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/sagikazarmark/locafero v0.3.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect @@ -27,15 +38,15 @@ require ( github.com/spf13/cast v1.5.1 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/net v0.15.0 // indirect golang.org/x/oauth2 v0.12.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 3442b86..c2f09c9 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,11 @@ +atomicgo.dev/assert v0.0.2 h1:FiKeMiZSgRrZsPo9qn/7vmr7mCsh5SZyXY4YGYiYwrg= +atomicgo.dev/assert v0.0.2/go.mod h1:ut4NcI3QDdJtlmAxQULOmA13Gz6e2DWbSAS8RUOmNYQ= +atomicgo.dev/cursor v0.2.0 h1:H6XN5alUJ52FZZUkI7AlJbUc1aW38GWZalpYRPpoPOw= +atomicgo.dev/cursor v0.2.0/go.mod h1:Lr4ZJB3U7DfPPOkbH7/6TOtJ4vFGHlgj1nc+n900IpU= +atomicgo.dev/keyboard v0.2.9 h1:tOsIid3nlPLZ3lwgG8KZMp/SFmr7P0ssEN5JUsm78K8= +atomicgo.dev/keyboard v0.2.9/go.mod h1:BC4w9g00XkxH/f1HXhW2sXmJFOCWbKn9xrOunSFtExQ= +atomicgo.dev/schedule v0.1.0 h1:nTthAbhZS5YZmgYbb2+DH8uQIZcTlIrd4eYr3UQxEjs= +atomicgo.dev/schedule v0.1.0/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= @@ -38,6 +46,16 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs= +github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8= +github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII= +github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k= +github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI= +github.com/MarvinJWendt/testza v0.3.0/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c= +github.com/MarvinJWendt/testza v0.4.2/go.mod h1:mSdhXiKH8sg/gQehJ63bINcCKp7RtYewEjXsvsVUPbE= +github.com/MarvinJWendt/testza v0.5.2 h1:53KDo64C1z/h/d/stCYCPY69bt/OSwjq5KpFNwi+zB4= +github.com/MarvinJWendt/testza v0.5.2/go.mod h1:xu53QFE5sCdjtMCKk8YMQ2MnymimEctc4n3EjyIYvEY= +github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -46,6 +64,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= +github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -128,6 +148,10 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= +github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= +github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= +github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= @@ -146,6 +170,11 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= +github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= +github.com/klauspost/cpuid/v2 v2.2.3 h1:sxCkb+qR91z4vsqw4vGGZlDgPz3G7gjaLyK3V8y70BU= +github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -154,12 +183,17 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4= +github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= @@ -170,6 +204,18 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI= +github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg= +github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE= +github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU= +github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE= +github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8= +github.com/pterm/pterm v0.12.40/go.mod h1:ffwPLwlbXxP+rxT0GsgDTzS3y3rmpAO1NMjUkGTYf8s= +github.com/pterm/pterm v0.12.71 h1:KcEJ98EiVCbzDkFbktJ2gMlr4pn8IzyGb9bwK6ffkuA= +github.com/pterm/pterm v0.12.71/go.mod h1:SUAcoZjRt+yjPWlWba+/Fd8zJJ2lSXBQWf0Z0HbFiIQ= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= @@ -178,6 +224,8 @@ github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9c github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= @@ -197,6 +245,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -206,10 +255,14 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/xanzy/go-gitlab v0.94.0 h1:GmBl2T5zqUHqyjkxFSvsT7CbelGdAH/dmBqUBqS+4BE= github.com/xanzy/go-gitlab v0.94.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -226,6 +279,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -262,6 +316,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -294,6 +350,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -317,6 +375,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -348,14 +408,27 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -364,6 +437,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -418,6 +493,8 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -523,7 +600,9 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/config/config.go b/internal/config/config.go index 70072ad..6f3e9ef 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,6 +11,9 @@ type Config struct { } type cacheConfig struct { - Ttl time.Duration `yaml:"ttl" json:"ttl"` - File string + Ttl time.Duration `yaml:"ttl" json:"ttl"` + File string `yaml:"file" json:"file"` + Clear struct { + ClearAliases bool `yaml:"clearAliases" json:"clearAliases"` + } `yaml:"clear" json:"clear"` } diff --git a/internal/gitlab/gitlab.go b/internal/gitlab/gitlab.go index fd92db1..18ec100 100644 --- a/internal/gitlab/gitlab.go +++ b/internal/gitlab/gitlab.go @@ -1,31 +1,154 @@ package gitlab -import "github.com/xanzy/go-gitlab" +import ( + "context" + "time" + + "github.com/xanzy/go-gitlab" +) + +const defProjectsPerPage = 100 type Client struct { + Ctx context.Context gitlab *gitlab.Client } -type ProjectInfo struct { - Name string `yaml:"name" json:"name"` - Id int `yaml:"id" json:"id"` - Path string `yaml:"path" json:"path"` - URI string `yaml:"uri" json:"uri"` - Description string `yaml:"description" json:"description"` +type Project struct { + ID int + Description string + SSHURLToRepo string + HTTPURLToRepo string + WebURL string + // Owner User + Name string + NameWithNamespace string + Path string + PathWithNamespace string + AvatarURL string + LastActivityAt time.Time } -type ProjectAlias struct { - Alias string - ProjectID string - Project *ProjectInfo +type User struct { + ID int + Username string + Email string + Name string + AvatarURL string } -func NewGitlabClient(host, token string) (*Client, error) { +type ProgressInfo struct { + ProgressChan chan Progress + ProjectsChan chan []*Project + ErrorChan chan error + DoneChan chan interface{} +} + +type Progress struct { + Page int + Pages int + Projects int + TotalProjects int +} + +// Given there may be thousands of projects, this will return +// channels that stream progress info and then finally the full +// list of projects on separate channels +func (c *Client) StreamProjects() *ProgressInfo { + pi := &ProgressInfo{ + ProgressChan: make(chan Progress), + ProjectsChan: make(chan []*Project), + ErrorChan: make(chan error), + DoneChan: make(chan interface{}), + } + + go c.streamProjects(pi) + + return pi +} + +func (c *Client) streamProjects(pi *ProgressInfo) { + defer close(pi.ProgressChan) + defer close(pi.ProjectsChan) + + listOpts := &gitlab.ListProjectsOptions{ + ListOptions: gitlab.ListOptions{ + PerPage: defProjectsPerPage, + Page: 1, + }, + Archived: new(bool), + } + + var numProjects int + for { + projects, resp, err := c.ListProjects(listOpts) + + // We're done when we have it all or our context is done + if c.Ctx.Err() != nil || resp.NextPage == 0 { + pi.DoneChan <- nil + break + } + + if err != nil { + pi.ErrorChan <- err + } + + numProjects += len(projects) + pi.ProjectsChan <- projects + pi.ProgressChan <- Progress{ + Page: resp.CurrentPage, + Pages: resp.TotalPages, + Projects: numProjects, + TotalProjects: resp.TotalItems, + } + listOpts.Page = resp.NextPage + } +} + +// Returns a list of projects along with the next page and an error +// if there was an error +func (c *Client) ListProjects(opts *gitlab.ListProjectsOptions) ( + []*Project, *gitlab.Response, error) { + pList := make([]*Project, 0) + projects, resp, err := c.gitlab.Projects.ListProjects( + opts, + gitlab.WithContext(c.Ctx), + ) + if err == nil { + pList = append(pList, c.handleProjects(projects)...) + } + return pList, resp, err +} + +func (c *Client) handleProjects(projects []*gitlab.Project) []*Project { + // Opportunity to perform any filtering or additional lookups + // on a per-project basis + pList := make([]*Project, 0, len(projects)) + for _, project := range projects { + p := &Project{ + ID: project.ID, + Description: project.Description, + SSHURLToRepo: project.SSHURLToRepo, + HTTPURLToRepo: project.HTTPURLToRepo, + WebURL: project.WebURL, + Name: project.Name, + NameWithNamespace: project.NameWithNamespace, + Path: project.Path, + PathWithNamespace: project.PathWithNamespace, + LastActivityAt: *project.LastActivityAt, + } + pList = append(pList, p) + } + return pList +} + +func NewGitlabClient(ctx context.Context, host, token string) (*Client, error) { client, err := gitlab.NewClient(token, gitlab.WithBaseURL(host)) if err != nil { return nil, err } gitlabClient := &Client{ + Ctx: ctx, gitlab: client, } return gitlabClient, nil diff --git a/internal/projects/cache.go b/internal/projects/cache.go index 1455fc6..c475f8c 100644 --- a/internal/projects/cache.go +++ b/internal/projects/cache.go @@ -7,30 +7,33 @@ import ( "sync" "time" + "github.com/pterm/pterm" "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab" - "golang.org/x/exp/slog" "gopkg.in/yaml.v3" ) type Cache struct { - Projects []*gitlab.ProjectInfo - Aliases []*gitlab.ProjectAlias + Projects []*gitlab.Project + Aliases []*ProjectAlias Updated time.Time readFromFile bool lock *sync.Mutex ttl time.Duration file string - log *slog.Logger + log *pterm.Logger + gitlab *gitlab.Client } type CacheOpts struct { Path string TTL time.Duration - Logger *slog.Logger + Logger *pterm.Logger + Gitlab *gitlab.Client } -// Load cache, if already loaded and -// up to date, +// Load cache, if already loaded and up to date, nothing is done. +// If the cache is not yet loaded from disk, it is loaded +// If the updated timestamp is beyond the set ttl, a refresh is triggered func (c *Cache) Load() error { var err error if !c.readFromFile { @@ -43,27 +46,34 @@ func (c *Cache) Load() error { return err } -func (c *Cache) Write() { +// Saves the current state of the cache to disk +func (c *Cache) write() { file, err := os.OpenFile(c.file, os.O_RDWR, fs.ModeAppend) if err != nil { - c.log.Error("Failed to write cache to disk", "error", err) + c.log.Error("Failed to write cache to disk", c.log.Args("error", err)) } d := yaml.NewEncoder(file) if err = d.Encode(*c); err != nil { - c.log.Error("Failed to Marshal cache to yaml", "error", err) + c.log.Error("Failed to Marshal cache to yaml", c.log.Args("error", err)) } else { - c.log.Info("Cache saved to disk") + c.log.Debug("Cache saved to disk") } } +func (c *Cache) Write() { + c.lock.Lock() + defer c.lock.Unlock() + c.write() +} +// Loads and unmarshals the project cache from disk. func (c *Cache) Read() { c.lock.Lock() defer c.lock.Unlock() - c.log.Info("Reading project cache from disk", "file", c.file) + c.log.Debug("Reading project cache from disk", c.log.Args("file", c.file)) file, err := os.Open(c.file) if err != nil { - c.log.Error("Failed to read project cache", "error", err) + c.log.Error("Failed to read project cache", c.log.Args("error", err)) return } @@ -78,11 +88,32 @@ func (c *Cache) Read() { c.log.Debug(c.String()) } +// Resets projects cache and also optionally clears +// project aliase cache. Writes to disk. +func (c *Cache) clear(clearAliases bool) { + c.log.Info("Clearing project cache") + c.Projects = make([]*gitlab.Project, 0) + if clearAliases { + c.log.Info("Clearing project alias cache") + c.Aliases = make([]*ProjectAlias, 0) + } + c.setUpdated() + c.log.Debug(c.String()) +} +func (c *Cache) Clear(clearAliases bool) { + c.lock.Lock() + defer c.lock.Unlock() + c.clear(clearAliases) +} + func (c *Cache) refresh() { c.log.Info("Refreshing project cache, this may take a while") defer c.setUpdated() + c.LoadProjects() } +// Iterates through all GitLab projects the user has access to, updating +// the project cache where necessary func (c *Cache) Refresh() { c.lock.Lock() defer c.lock.Unlock() @@ -121,12 +152,13 @@ func NewProjectCache(opts *CacheOpts) (*Cache, error) { } cache := &Cache{ - Projects: make([]*gitlab.ProjectInfo, 0), - Aliases: make([]*gitlab.ProjectAlias, 0), + Projects: make([]*gitlab.Project, 0), + Aliases: make([]*ProjectAlias, 0), file: opts.Path, ttl: opts.TTL, lock: &sync.Mutex{}, log: opts.Logger, + gitlab: opts.Gitlab, } return cache, err diff --git a/internal/projects/projects.go b/internal/projects/projects.go new file mode 100644 index 0000000..29aac64 --- /dev/null +++ b/internal/projects/projects.go @@ -0,0 +1,53 @@ +package projects + +import ( + "fmt" + + "github.com/pterm/pterm" + "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab" +) + +type ProjectAlias struct { + Alias string + ProjectID string + Project *gitlab.Project +} + +func (c *Cache) LoadProjects() { + progressInfo := c.gitlab.StreamProjects() + c.Projects = make([]*gitlab.Project, 0) + + pBar := pterm.DefaultProgressbar. + WithShowPercentage(true). + WithTotal(-1). + WithTitle("Listing GitLab Projects"). + WithMaxWidth(0) + + defer pBar.Stop() + + var curProjects int + for { + select { + case p := <-progressInfo.ProgressChan: + if pBar.Total == -1 { + pBar = pBar.WithTotal(p.TotalProjects) + pBar, _ = pBar.Start() + } + // This sucks, has to be a better way, and why is the logger incompatible + // with the progressbar? + pterm.Debug.Println(fmt.Sprintf("Update received: %#v", p)) + pBar.Add(p.Projects - curProjects) + curProjects = p.Projects + case p := <-progressInfo.ProjectsChan: + c.Projects = append(c.Projects, p...) + case e := <-progressInfo.ErrorChan: + c.log.Error("Fetch GitLab projects error", c.log.Args("error", e)) + case <-c.gitlab.Ctx.Done(): + c.log.Warn("LoadProjects cancelled", c.log.Args("reason", c.gitlab.Ctx.Err())) + return + case <-progressInfo.DoneChan: + c.log.Info("Project load complete") + return + } + } +}