diff --git a/Taskfile.yml b/Taskfile.yml index c0aa124..efc253e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -15,15 +15,16 @@ vars: VERSION: sh: cd version/ && versionManager go version - ## Binary name ## - WINDOWS_BINARY_NAME: ./release/windows/{{.VERSION}}/kode-starter.exe - LINUX_BINARY_NAME: ./release/linux/{{.VERSION}}/kode-starter + ## Binary name of kode-creator ## + WINDOWS_BINARY_NAME: ./release/windows/{{.VERSION}}/kode-creator.exe + LINUX_BINARY_NAME: ./release/linux/{{.VERSION}}/kode-creator # faire un build pour Windows sur linux il faut installer mingw-w64 # sudo apt-get install mingw-w64 -env: - GOOS: windows - GOARCH: amd64 +# ** Cette fonctionnalité est toujours en cours de test ** +# env: +# GOOS: windows +# GOARCH: amd64 tasks: ###### LINUX ###### diff --git a/cmdCreate/create.go b/cmdCreate/create.go index 4d6f38a..bf21f82 100644 --- a/cmdCreate/create.go +++ b/cmdCreate/create.go @@ -4,9 +4,9 @@ import ( "bytes" "encoding/json" "fmt" - "kode-starter/config" - "kode-starter/structures" - "kode-starter/utils" + "kode-creator/config" + "kode-creator/structures" + "kode-creator/utils" "log" "net/http" "os" @@ -71,7 +71,7 @@ func CreateProject(cmd *cobra.Command, args []string) error { req, err := http.NewRequest("POST", fmt.Sprintf("%s/%s/repos", CfgGlobal.GetUrlApiOrgs(), CfgGlobal.GetCreateCmd().Organisation), bytes.NewBuffer(jsonData)) - req.Header.Set("Authorization", "token "+CfgGlobal.GetTokenEnv()) + req.Header.Set("Authorization", "token "+CfgGlobal.GetGitTeaTokenEnv()) req.Header.Set("Content-Type", "application/json") client := &http.Client{} res, err := client.Do(req) diff --git a/cmdEnv/envVars.go b/cmdEnv/envVars.go index 94f19de..2417f38 100644 --- a/cmdEnv/envVars.go +++ b/cmdEnv/envVars.go @@ -2,10 +2,10 @@ package cmdEnv import ( "fmt" - "kode-starter/config" - "kode-starter/configFile" + "kode-creator/config" + "kode-creator/configFile" - "kode-starter/utils" + "kode-creator/utils" "os" "strconv" "strings" diff --git a/cmdLists/gitHub.go b/cmdLists/gitHub.go index e135d72..fea13ae 100644 --- a/cmdLists/gitHub.go +++ b/cmdLists/gitHub.go @@ -15,10 +15,10 @@ func ListGitHubOrganization() ([]string, error) { return orgs, nil } -func ListGitHubProjectsfromUser(username string) ([]*github.Repository, error) { +func ListGitHubProjectsfromUser(username string, token string) ([]*github.Repository, error) { // Replace with your access token - token := "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" + // token := "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" // Create an oauth2 token source with the access token tokenSource := oauth2.StaticTokenSource( diff --git a/cmdLists/gitTea.go b/cmdLists/gitTea.go index 3978b51..30cfd43 100644 --- a/cmdLists/gitTea.go +++ b/cmdLists/gitTea.go @@ -3,7 +3,7 @@ package cmdLists import ( "encoding/json" "fmt" - "kode-starter/utils" + "kode-creator/utils" "github.com/joho/godotenv" ) @@ -13,7 +13,7 @@ import ( func ListGitTeaOrganization() ([]string, error) { godotenv.Load() - body := UrlGetBody(CfgGlobal.GetUrlApiOrgs()) + body := UrlGetBody(CfgGlobal.GetUrlApiOrgs(), CfgGlobal.GetGitTeaTokenEnv()) if CfgGlobal.GetJsonFlag() { return utils.BytesToStrings(body), nil } else { @@ -44,7 +44,7 @@ func ListGitTeaOrganization() ([]string, error) { func ListGitTeaProjects(org string) ([]string, error) { godotenv.Load() - body := UrlGetBody(CfgGlobal.GetUrlApiOrgs() + "/" + org + "/repos") + body := UrlGetBody(CfgGlobal.GetUrlApiOrgs()+"/"+org+"/repos", CfgGlobal.GetGitTeaTokenEnv()) if CfgGlobal.GetJsonFlag() { return utils.BytesToStrings(body), nil } else { diff --git a/cmdLists/lists.go b/cmdLists/lists.go index c33e7ea..12864a5 100644 --- a/cmdLists/lists.go +++ b/cmdLists/lists.go @@ -3,8 +3,8 @@ package cmdLists import ( "fmt" "io" - "kode-starter/config" - "kode-starter/utils" + "kode-creator/config" + "kode-creator/utils" "net/http" "github.com/spf13/cobra" @@ -89,7 +89,7 @@ func startList(cmd *cobra.Command, args []string) { } else if CfgGlobal.GetGitFlag() { fmt.Println("\n L I S T G I T H U B P R O J E C T S F O R : " + CfgGlobal.GetListUser()) fmt.Println(utils.CreateLine(11)) - repos, err := ListGitHubProjectsfromUser(CfgGlobal.GetListUser()) + repos, err := ListGitHubProjectsfromUser(CfgGlobal.GetListUser(), CfgGlobal.GetGithubTokenEnv()) if err != nil { fmt.Println("Error:", err) return @@ -99,12 +99,12 @@ func startList(cmd *cobra.Command, args []string) { utils.PrintTreeElement(nb, *repo.Name, *repo.HTMLURL) nb++ } - fmt.Println(utils.CreateLine(11)) } else { // print help if no flag is set cmd.Help() + fmt.Println(utils.CreateLine(11)) } @@ -112,14 +112,14 @@ func startList(cmd *cobra.Command, args []string) { // This function sends a GET request to a specified URL with authorization and content-type headers, // and returns the response body as a byte array. -func UrlGetBody(url string) []byte { +func UrlGetBody(url string, token string) []byte { req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) } - req.Header.Set("Authorization", "token "+CfgGlobal.GetTokenEnv()) + req.Header.Set("Authorization", "token "+token) req.Header.Set("Content-Type", "application/json") // fmt.Println(req.Header.Get("Authorization")) resp, err := http.DefaultClient.Do(req) diff --git a/config/config.go b/config/config.go index 0acc9a3..dcb25de 100644 --- a/config/config.go +++ b/config/config.go @@ -2,7 +2,7 @@ package config import ( "fmt" - "kode-starter/utils" + "kode-creator/utils" "time" "github.com/spf13/cobra" @@ -15,6 +15,8 @@ type Config struct { ModifDate string ConfigFileYmlName string TokenEnv string + GithubTokenEnv string + GitTeaTokenEnv string VerboseFlag bool JsonFlag bool VersionFlag bool @@ -113,14 +115,24 @@ func (c *Config) SetConfigFileYmlName(value string) { c.ConfigFileYmlName = value } -// Getter for tokenEnv field -func (c *Config) GetTokenEnv() string { - return c.TokenEnv +// Getter for GithubTokenEnv field +func (c *Config) GetGithubTokenEnv() string { + return c.GithubTokenEnv } -// Setter for tokenEnv field -func (c *Config) SetTokenEnv(value string) { - c.TokenEnv = value +// Setter for GithubTokenEnv field +func (c *Config) SetGithubTokenEnv(value string) { + c.GithubTokenEnv = value +} + +// Getter for GithubTokenEnv field +func (c *Config) GetGitTeaTokenEnv() string { + return c.GitTeaTokenEnv +} + +// Setter for GithubTokenEnv field +func (c *Config) SetGitTeaTokenEnv(value string) { + c.GitTeaTokenEnv = value } // Getter for verboseFlag field @@ -443,9 +455,13 @@ func (c *Config) Init() { var configFileYmlName string = utils.GetProgramDir() + "/config.yml" c.SetConfigFileYmlName(configFileYmlName) - // set token from environment variable - var tokenEnv string = utils.GetGitTokenFromOsEnv() - c.SetTokenEnv(tokenEnv) + // set Github token from environment variable + var githubTokenEnv string = utils.GetEnvVarValueFromOsEnv("GITHUB_TOKEN") + c.SetGithubTokenEnv(githubTokenEnv) + + // set Gitea token from environment variable + var giteaTokenEnv string = utils.GetEnvVarValueFromOsEnv("GITEA_TOKEN") + c.SetGithubTokenEnv(giteaTokenEnv) // set verbose flag c.SetVerboseFlag(false) @@ -665,7 +681,8 @@ func (c *Config) printAllConfiguration() { fmt.Println("config: Author: ", c.GetAuthor()) fmt.Println("config: ModifDate: ", c.GetModifDate()) fmt.Println("config: ConfigFileYmlName: ", c.GetConfigFileYmlName()) - fmt.Println("config: TokenEnv: ", c.GetTokenEnv()) + fmt.Println("config: GithubTokenEnv: ", c.GetGithubTokenEnv()) + fmt.Println("config: GiteaTokenEnv: ", c.GetGitTeaTokenEnv()) fmt.Println("config: VerboseFlag: ", c.GetVerboseFlag()) fmt.Println("config: JsonFlag: ", c.GetJsonFlag()) fmt.Println("config: VersionFlag: ", c.GetVersionFlag()) diff --git a/configFile/config-actionyml.go b/configFile/config-actionyml.go index 7fa7265..723dbd1 100644 --- a/configFile/config-actionyml.go +++ b/configFile/config-actionyml.go @@ -2,7 +2,7 @@ package configFile import ( "fmt" - "kode-starter/config" + "kode-creator/config" "log" "os" ) diff --git a/go.mod b/go.mod index 6f8a6cb..94e2b0d 100644 --- a/go.mod +++ b/go.mod @@ -1,27 +1,24 @@ -module kode-starter +module kode-creator go 1.19 require ( + github.com/google/go-github v17.0.0+incompatible github.com/gookit/color v1.5.3 github.com/joho/godotenv v1.5.1 github.com/spf13/cobra v1.7.0 + golang.org/x/oauth2 v0.9.0 + gopkg.in/yaml.v2 v2.4.0 ) require ( github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-querystring v1.1.0 // indirect - golang.org/x/net v0.11.0 // indirect - google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.28.0 // indirect -) - -require ( - github.com/google/go-github v17.0.0+incompatible github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect - golang.org/x/oauth2 v0.9.0 + golang.org/x/net v0.11.0 // indirect golang.org/x/sys v0.9.0 // indirect - gopkg.in/yaml.v2 v2.4.0 + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.28.0 // indirect ) diff --git a/go.mod__old b/go.mod__old new file mode 100644 index 0000000..6f8a6cb --- /dev/null +++ b/go.mod__old @@ -0,0 +1,27 @@ +module kode-starter + +go 1.19 + +require ( + github.com/gookit/color v1.5.3 + github.com/joho/godotenv v1.5.1 + github.com/spf13/cobra v1.7.0 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-querystring v1.1.0 // indirect + golang.org/x/net v0.11.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.28.0 // indirect +) + +require ( + github.com/google/go-github v17.0.0+incompatible + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect + golang.org/x/oauth2 v0.9.0 + golang.org/x/sys v0.9.0 // indirect + gopkg.in/yaml.v2 v2.4.0 +) diff --git a/go.sum b/go.sum index b537d37..767cfad 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,7 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= @@ -32,8 +33,7 @@ golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/oauth2 v0.9.0 h1:BPpt2kU7oMRq3kCHAA1tbSEshXRw1LpG2ztgDwrzuAs= golang.org/x/oauth2 v0.9.0/go.mod h1:qYgFZaFiu6Wg24azG8bdV52QJXJGbZzIIsRCdVKzbLw= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/kode-starter.go b/kode-creator.go similarity index 93% rename from kode-starter.go rename to kode-creator.go index 7346da6..6beb9a7 100644 --- a/kode-starter.go +++ b/kode-creator.go @@ -1,12 +1,12 @@ package main import ( - "kode-starter/cmdCreate" - "kode-starter/cmdEnv" - "kode-starter/cmdLists" - "kode-starter/config" - "kode-starter/utils" - "kode-starter/version" + "kode-creator/cmdCreate" + "kode-creator/cmdEnv" + "kode-creator/cmdLists" + "kode-creator/config" + "kode-creator/utils" + "kode-creator/version" "github.com/spf13/cobra" ) @@ -70,16 +70,22 @@ func init() { // function to print help or version func mainProgram(cmd *cobra.Command, args []string) { + CfgGlobal.DebugPrintConfig("Function mainProgram") + + // print header if json flag is not set + if !CfgGlobal.GetJsonFlag() { + utils.PrintHeader() + } + // if version flag is set, print version and exit if CfgGlobal.GetVersionFlag() { utils.PrintVersion(version.GetFullVersion(), CfgGlobal.GetAuthor(), CfgGlobal.GetModifDate()) - return // if no flag is set, print help and exit } else { utils.PrintHelpFormated(version.GetFullVersion(), CfgGlobal.GetAuthor(), CfgGlobal.GetModifDate(), cmd) - return + } } diff --git a/readme.md b/readme.md index 22656c3..43d53c5 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,15 @@ # Project Creator -This is a simple CLI app to create a startup structure Github or Gitea project. +This is a simple CLI app to help you to do smalls things like : +- Look organizations and projects on Github and Gitea. +- Create a startup project structure base on a configuration file +- Create and push your projects into Github or Gitea. +- Look and manange environnement variable +- ## Description -The **KodeStarter** app allows you to: +The **Kode-Creator** app allows you to: - Create a Github project (repo) - Initialize a Git repository @@ -19,7 +24,7 @@ To build and run the app: ```bash go build -./kode-starter.exe +./kode-creator.exe ``` This will show the help menu. The main commands are: @@ -30,13 +35,13 @@ This will show the help menu. The main commands are: To create a project: ```bash -./kode-starter.exe create -t -o -n -d -p +./kode-creator.exe create -t -o -n -d -p ``` For example: ```bash -./kode-starter.exe create -t abc123 -o myorg -n myproject -d "A test project" -p false +./kode-creator.exe create -t abc123 -o myorg -n myproject -d "A test project" -p false ``` This will: @@ -50,13 +55,13 @@ This will: To list Github orgs and repos: ```bash -./kode-starter.exe list -t -o +./kode-creator.exe list -t -o ``` For example: ```bash -./kode-starter.exe list -t abc123 -o myorg +./kode-creator.exe list -t abc123 -o myorg ``` This will list the repos in the `myorg` organization. @@ -65,12 +70,17 @@ This will list the repos in the `myorg` organization. You can set the following environment variables: -- `GIT_TOKEN` - Your Github personal access token. This will be used instead of passing the `-t` flag. - +- `GITHUB_TOKEN` - Your Github personal access token. This will be used instead of passing the `-t` flag. +- `GITEA_TOKEN` - Your Gitea personnal access token. This will be used instead of passing the `-t` flag. *Temporaire* (Gitea Token for linux)[ af65e1b846d721e3465422c04997d69b0cfe7f18 ] (Github Token from Github)[ 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 ] +## TODO +- add fonctionnalities to .bachrc file + - show .bashrc file + - add export variables configure in your yaml config + ##License MIT License. \ No newline at end of file diff --git a/release/linux/0.0.0.29/kode-starter b/release/linux/0.0.0.29/kode-starter new file mode 100755 index 0000000..09a6501 Binary files /dev/null and b/release/linux/0.0.0.29/kode-starter differ diff --git a/kode-starter b/release/linux/0.0.0.30/kode-starter similarity index 60% rename from kode-starter rename to release/linux/0.0.0.30/kode-starter index 0fe8a1d..47912de 100755 Binary files a/kode-starter and b/release/linux/0.0.0.30/kode-starter differ diff --git a/release/linux/kode-starter b/release/linux/0.0.0.31/kode-creator similarity index 60% rename from release/linux/kode-starter rename to release/linux/0.0.0.31/kode-creator index ce9f284..93519a1 100755 Binary files a/release/linux/kode-starter and b/release/linux/0.0.0.31/kode-creator differ diff --git a/utils/utils.go b/utils/utils.go index 1108267..4ed0887 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -54,6 +54,11 @@ func BytesToStrings(bytes []byte) []string { return strings } +func GetEnvVarValueFromOsEnv(key string) string { + value := os.Getenv(key) + return value +} + func GetGitTokenFromOsEnv() string { token := os.Getenv("GIT_TOKEN") return token diff --git a/version/version-number.go b/version/version-number.go index 7529196..31ca31e 100644 --- a/version/version-number.go +++ b/version/version-number.go @@ -15,7 +15,7 @@ type Version struct { // version variable that will be set at build time by versionManager.exe // *** DO NOT EDIT *** -var versionNumber Version = Version{0, 0, 0, 28} +var versionNumber Version = Version{0, 0, 0, 32} // GetFullVersion returns the full version number as a string func GetFullVersion() string {