Skip to content

Commit

Permalink
Merge pull request #26 from muandane/fix/clustered-root
Browse files Browse the repository at this point in the history
fix 🐛: unclustered root.go
  • Loading branch information
muandane authored Nov 18, 2023
2 parents e9e0e16 + 5eb16a2 commit dac574a
Show file tree
Hide file tree
Showing 402 changed files with 19,661 additions and 7,080 deletions.
78 changes: 0 additions & 78 deletions .goji.json

This file was deleted.

2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ universal_binaries:

archives:
- name_template: >-
{{- .ProjectName }}_ {{- title .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}v{{ .Arm }}{{ end -}}
{{- .ProjectName }}_ {{- .Version }}_ {{- title .Os }}_ {{- if eq .Arch "amd64" }}x86_64 {{- else if eq .Arch "386" }}i386 {{- else }}{{ .Arch }}{{ end }} {{- if .Arm }}v{{ .Arm }}{{ end -}}
format_overrides:
- goos: windows
format: zip
Expand Down
87 changes: 9 additions & 78 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package cmd

import (
"encoding/json"
"fmt"

"log"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/muandane/goji/pkg/config"
"github.com/muandane/goji/pkg/utils"
Expand Down Expand Up @@ -37,29 +34,21 @@ var rootCmd = &cobra.Command{
color.Unset()
return
}
color.Set(color.FgGreen)
fmt.Printf("Goji v%s is a cli tool to generate conventional commits with emojis.\n", version)
color.Unset()

if initFlag {
gitmojis := AddCustomCommitTypes([]Gitmoji{})
config := initConfig{
Types: gitmojis,
Scopes: []string{"home", "accounts", "ci"},
Symbol: true,
SkipQuestions: []string{},
SubjectMaxLength: 50,
}
err := SaveGitmojisToFile(config, ".goji.json")
color.Set(color.FgYellow)
err := config.InitRepoConfig()
if err != nil {
fmt.Printf("Error saving gitmojis to file: %v\n", err)
os.Exit(1)
fmt.Printf("Failed to initialize repository configuration: %v\n", err)
return
}

fmt.Println("Gitmojis saved to .goji.json 🎊")
color.Unset()
return
}

color.Set(color.FgGreen)
fmt.Printf("Goji v%s is a cli tool to generate conventional commits with emojis.\n", version)
color.Unset()

if typeFlag != "" && messageFlag != "" {
config, err := config.LoadConfig(".goji.json")
if err != nil {
Expand Down Expand Up @@ -134,64 +123,6 @@ func init() {
rootCmd.Flags().StringVarP(&messageFlag, "message", "m", "", "Specify a commit message")
}

type Gitmoji struct {
Emoji string `json:"emoji"`
Code string `json:"code"`
Description string `json:"description"`
Name string `json:"name"`
}
type initConfig struct {
Types []Gitmoji `json:"Types"`
Scopes []string `json:"Scopes"`
Symbol bool `json:"Symbol"`
SkipQuestions []string `json:"SkipQuestions"`
SubjectMaxLength int `json:"SubjectMaxLength"`
}

func AddCustomCommitTypes(gitmojis []Gitmoji) []Gitmoji {
customGitmojis := []Gitmoji{
{Emoji: "✨", Code: ":sparkles:", Description: "Introduce new features.", Name: "feat"},
{Emoji: "🐛", Code: ":bug:", Description: "Fix a bug.", Name: "fix"},
{Emoji: "📚", Code: ":books:", Description: "Documentation change.", Name: "docs"},
{Emoji: "🎨", Code: ":art:", Description: "Improve structure/format of the code.", Name: "refactor"},
{Emoji: "🧹", Code: ":broom:", Description: "A chore change.", Name: "chore"},
{Emoji: "🧪", Code: ":test_tube:", Description: "Add a test.", Name: "test"},
{Emoji: "🚑️", Code: ":ambulance:", Description: "Critical hotfix.", Name: "hotfix"},
{Emoji: "⚰️", Code: ":coffin:", Description: "Remove dead code.", Name: "deprecate"},
{Emoji: "⚡️", Code: ":zap:", Description: "Improve performance.", Name: "perf"},
{Emoji: "🚧", Code: ":construction:", Description: "Work in progress.", Name: "wip"},
{Emoji: "📦", Code: ":package:", Description: "Add or update compiled files or packages.", Name: "package"},
}

return append(gitmojis, customGitmojis...)
}

func GetGitRootDir() (string, error) {
gitRoot := exec.Command("git", "rev-parse", "--show-toplevel")
gitDirBytes, err := gitRoot.Output()
if err != nil {
return "", fmt.Errorf("error finding git root directory: %v", err)
}
gitDir := string(gitDirBytes)
gitDir = strings.TrimSpace(gitDir) // Remove newline character at the end

return gitDir, nil
}

func SaveGitmojisToFile(config initConfig, filename string) error {
gitDir, err := GetGitRootDir()
if err != nil {
return err
}

configFile := filepath.Join(gitDir, filename)
data, err := json.MarshalIndent(config, "", " ")
if err != nil {
return err
}

return os.WriteFile(configFile, data, 0644)
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ go 1.21.3

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/fatih/color v1.15.0
github.com/fatih/color v1.16.0
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.6.1
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.4.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
31 changes: 21 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand All @@ -21,21 +21,29 @@ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxec
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
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/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0=
github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0=
github.com/stretchr/testify v1.6.1/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=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand All @@ -52,16 +60,19 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down
76 changes: 76 additions & 0 deletions pkg/config/configInit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package config

import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)

func AddCustomCommitTypes(gitmojis []Gitmoji) []Gitmoji {
customGitmojis := []Gitmoji{
{Emoji: "✨", Code: ":sparkles:", Description: "Introduce new features.", Name: "feat"},
{Emoji: "🐛", Code: ":bug:", Description: "Fix a bug.", Name: "fix"},
{Emoji: "📚", Code: ":books:", Description: "Documentation change.", Name: "docs"},
{Emoji: "🎨", Code: ":art:", Description: "Improve structure/format of the code.", Name: "refactor"},
{Emoji: "🧹", Code: ":broom:", Description: "A chore change.", Name: "chore"},
{Emoji: "🧪", Code: ":test_tube:", Description: "Add a test.", Name: "test"},
{Emoji: "🚑️", Code: ":ambulance:", Description: "Critical hotfix.", Name: "hotfix"},
{Emoji: "⚰️", Code: ":coffin:", Description: "Remove dead code.", Name: "deprecate"},
{Emoji: "⚡️", Code: ":zap:", Description: "Improve performance.", Name: "perf"},
{Emoji: "🚧", Code: ":construction:", Description: "Work in progress.", Name: "wip"},
{Emoji: "📦", Code: ":package:", Description: "Add or update compiled files or packages.", Name: "package"},
}

return append(gitmojis, customGitmojis...)
}
func GetGitRootDir() (string, error) {
gitRoot := exec.Command("git", "rev-parse", "--show-toplevel")
gitDirBytes, err := gitRoot.Output()
if err != nil {
return "", fmt.Errorf("error finding git root directory: %v", err)
}
gitDir := string(gitDirBytes)
gitDir = strings.TrimSpace(gitDir) // Remove newline character at the end

return gitDir, nil
}

func SaveGitmojisToFile(config initConfig, filename string) error {
gitDir, err := GetGitRootDir()

if err != nil {
return err
}

configFile := filepath.Join(gitDir, filename)
data, err := json.MarshalIndent(config, "", " ")
if err != nil {
return err
}

return os.WriteFile(configFile, data, 0644)
}

func InitRepoConfig() error {
gitmojis := AddCustomCommitTypes([]Gitmoji{})
config := initConfig{
Types: gitmojis,
Scopes: []string{"home", "accounts", "ci"},
Symbol: true,
SkipQuestions: []string{},
SubjectMaxLength: 50,
}

err := SaveGitmojisToFile(config, ".goji.json")

if err != nil {
return fmt.Errorf("error saving gitmojis to file: %v", err)
} else {
fmt.Println("Gitmojis saved to .goji.json 🎊")
}

return nil
}
Loading

0 comments on commit dac574a

Please sign in to comment.