-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from muandane/fix/clustered-root
fix 🐛: unclustered root.go
- Loading branch information
Showing
402 changed files
with
19,661 additions
and
7,080 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.