#8 delete cobra, add parsing .netrc
This commit is contained in:
		| @@ -1,7 +0,0 @@ | ||||
| package main | ||||
|  | ||||
| import "git.unistack.org/unistack-org/pkgdash/internal/cli" | ||||
|  | ||||
| func main() { | ||||
| 	cli.Execute() | ||||
| } | ||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @@ -35,8 +35,10 @@ require ( | ||||
| require ( | ||||
| 	github.com/google/go-cmp v0.6.0 // indirect | ||||
| 	github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||||
| 	github.com/jdx/go-netrc v1.0.0 // indirect | ||||
| 	github.com/silas/dag v0.0.0-20220518035006-a7e85ada93c5 // indirect | ||||
| 	github.com/spf13/pflag v1.0.5 // indirect | ||||
| 	go.unistack.org/micro-config-flag/v4 v4.0.4 // indirect | ||||
| 	google.golang.org/genproto/googleapis/rpc v0.0.0-20240311132316-a219d84964c2 // indirect | ||||
| 	gopkg.in/yaml.v2 v2.4.0 // indirect | ||||
| ) | ||||
|   | ||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							| @@ -686,6 +686,8 @@ github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv | ||||
| github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= | ||||
| github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= | ||||
| github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= | ||||
| github.com/jdx/go-netrc v1.0.0 h1:QbLMLyCZGj0NA8glAhxUpf1zDg6cxnWgMBbjq40W0gQ= | ||||
| github.com/jdx/go-netrc v1.0.0/go.mod h1:Gh9eFQJnoTNIRHXl2j5bJXA1u84hQWJWgGh569zF3v8= | ||||
| github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= | ||||
| github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||||
| github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= | ||||
|   | ||||
| @@ -33,7 +33,8 @@ func NewCheckUpdateCommand() *cobra.Command { | ||||
| 		Short: "CheckUpdate collects a list of dependencies with the latest updates.", | ||||
| 		Long:  `CheckUpdate collects a list of dependencies with the latest updates.`, | ||||
| 		RunE: func(cmd *cobra.Command, args []string) error { | ||||
| 			fmt.Println("checkupdate called") | ||||
| 			logger.Info(ctx, "CheckUpdate called") | ||||
|  | ||||
| 			path := "." | ||||
| 			if len(os.Args) > 1 { | ||||
| 				path = os.Args[1] | ||||
|   | ||||
| @@ -6,10 +6,12 @@ package cli | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
|  | ||||
| 	"git.unistack.org/unistack-org/pkgdash/internal/configcli" | ||||
| 	"git.unistack.org/unistack-org/pkgdash/internal/source" | ||||
| 	"git.unistack.org/unistack-org/pkgdash/internal/source/github" | ||||
| 	"github.com/spf13/cobra" | ||||
| 	yamlcodec "go.unistack.org/micro-codec-yaml/v4" | ||||
| 	envconfig "go.unistack.org/micro-config-env/v4" | ||||
| @@ -23,7 +25,7 @@ import ( | ||||
| // initCmd represents the init command | ||||
| var initCmd = NewInitCommand() | ||||
|  | ||||
| var gitsource = source.SourceControl(nil) | ||||
| var gitsource source.SourceControl = (*github.Github)(nil) | ||||
|  | ||||
| var cfg = configcli.NewConfig() | ||||
|  | ||||
| @@ -63,16 +65,18 @@ func NewInitCommand() *cobra.Command { | ||||
| 		Short: "Init fills the config with data from the configuration file.", | ||||
| 		Long:  `Init fills the config with data from the configuration file.`, | ||||
| 		RunE: func(cmd *cobra.Command, args []string) error { | ||||
| 			fmt.Println("init called") | ||||
| 			logger.Info(ctx, "Init called") | ||||
| 			var err error | ||||
|  | ||||
| 			lCfg := configcli.NewConfig() | ||||
|  | ||||
| 			if err = config.Load(ctx, | ||||
| 				[]config.Config{ | ||||
| 					config.NewConfig( | ||||
| 						config.Struct(cfg), | ||||
| 						config.Struct(lCfg), | ||||
| 					), | ||||
| 					envconfig.NewConfig( | ||||
| 						config.Struct(cfg), | ||||
| 						config.Struct(lCfg), | ||||
| 					), | ||||
| 				}, | ||||
| 				config.LoadOverride(true), | ||||
| @@ -82,12 +86,16 @@ func NewInitCommand() *cobra.Command { | ||||
|  | ||||
| 			for _, configDir := range configDirs { | ||||
| 				for _, configFile := range configFiles { | ||||
| 					logger.Info(ctx, fmt.Sprintf("path: %s", filepath.Join(configDir, configFile))) | ||||
| 					path := filepath.Join(configDir, configFile) | ||||
| 					if _, err = os.Stat(path); os.IsNotExist(err) { | ||||
| 						continue | ||||
| 					} | ||||
|  | ||||
| 					c := fileconfig.NewConfig( | ||||
| 						config.AllowFail(false), | ||||
| 						config.Struct(cfg), | ||||
| 						config.Struct(lCfg), | ||||
| 						options.Codec(yamlcodec.NewCodec()), | ||||
| 						fileconfig.Path(".gitea/pkgdashcli.yaml"), | ||||
| 						fileconfig.Path(path), | ||||
| 					) | ||||
| 					err = c.Init(options.Context(ctx)) | ||||
| 					if err != nil { | ||||
| @@ -101,7 +109,7 @@ func NewInitCommand() *cobra.Command { | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			logger.Info(ctx, fmt.Sprintf("Load config... %s", cfg.Source.Repository)) | ||||
| 			logger.Info(ctx, fmt.Sprintf("Load config... \n %s", cfg)) | ||||
|  | ||||
| 			if cfg.PullRequestBody == "" { | ||||
| 				cfg.PullRequestBody = DefaultPullRequestBody | ||||
| @@ -111,7 +119,11 @@ func NewInitCommand() *cobra.Command { | ||||
| 				cfg.PullRequestTitle = DefaultPullRequestTitle | ||||
| 			} | ||||
|  | ||||
| 			gitsource = source.NewSourceControl(*cfg) | ||||
| 			gitsource = source.NewSourceControl(*lCfg) | ||||
|  | ||||
| 			logger.Info(ctx, fmt.Sprintf("Git: %s", gitsource.Name())) | ||||
|  | ||||
| 			cfg = lCfg | ||||
|  | ||||
| 			return nil | ||||
| 		}, | ||||
|   | ||||
| @@ -35,8 +35,6 @@ func init() { | ||||
| func NewListCommand() *cobra.Command { | ||||
| 	ctx := context.Background() | ||||
|  | ||||
| 	logger.Info(ctx, "RequestList start") | ||||
|  | ||||
| 	cmd := &cobra.Command{ | ||||
| 		Use:   "list", | ||||
| 		Short: "Update allows you to start the process of creating a PR in the repository", | ||||
| @@ -45,6 +43,9 @@ Update allows you to start the process of creating a PR in the repository. | ||||
| Use the -a flag to update all dependencies or -m flag a specific module. | ||||
| `, | ||||
| 		RunE: func(cmd *cobra.Command, args []string) error { | ||||
|  | ||||
| 			logger.Info(ctx, "RequestList start") | ||||
|  | ||||
| 			if gitsource == nil { | ||||
| 				return errSourceNil | ||||
| 			} | ||||
| @@ -54,8 +55,9 @@ Use the -a flag to update all dependencies or -m flag a specific module. | ||||
| 			} | ||||
|  | ||||
| 			prList = make(map[string]map[string]string) | ||||
|  | ||||
| 			logger.Info(ctx, fmt.Sprintf("Load config... \n %s", cfg)) | ||||
| 			for _, branch := range cfg.Branches { | ||||
| 				logger.Info(ctx, fmt.Sprintf("Start getting pr for %s", branch)) | ||||
| 				rMap, err := gitsource.RequestList(ctx, branch) | ||||
| 				if err != nil { | ||||
| 					return err | ||||
| @@ -65,6 +67,8 @@ Use the -a flag to update all dependencies or -m flag a specific module. | ||||
| 				logger.Info(ctx, fmt.Sprintf("for %s:\n%s", branch, rMap)) | ||||
| 			} | ||||
|  | ||||
| 			logger.Info(ctx, "Successful getting pull requests") | ||||
|  | ||||
| 			return nil | ||||
| 		}, | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user