Skip to content

Commit

Permalink
Merge pull request #17 from AllanCapistrano/feat/first-commit
Browse files Browse the repository at this point in the history
Feat/first commit
  • Loading branch information
AllanCapistrano authored Jul 20, 2023
2 parents 00dd74f + 38ec0cc commit e3e6bf5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
30 changes: 22 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd
import (
"fmt"
"log"
"os"
"os/exec"

"github.com/kyokomi/emoji/v2"
Expand Down Expand Up @@ -77,13 +76,20 @@ simple way to write commits following the Conventional Commits
emoji.Sprintf("%sPerformance Improvement", gbcEmojis.Perf),
"perf",
)
commitTypeMenu.AddItem(
emoji.Sprintf("%sFirst Commit", gbcEmojis.FirstCommit),
"first_commit",
)

commitType := commitTypeMenu.Display()

if commitType == "" {
os.Exit(0)
log.Fatal("Could not possible get the menu option.")
}

var commitMessage string
var commandString string

if enableEmojis {
var commitTypeEmoji string

Expand All @@ -108,6 +114,8 @@ simple way to write commits following the Conventional Commits
commitTypeEmoji = gbcEmojis.Ci
case "perf":
commitTypeEmoji = gbcEmojis.Perf
case "first_commit":
commitMessage = emoji.Sprintf("%s", gbcEmojis.FirstCommit)
}

commitType = emoji.Sprintf(
Expand All @@ -117,11 +125,17 @@ simple way to write commits following the Conventional Commits
)
}

commitMessage := userinput.GetUserInput("What commit message do you want? ", true)

commandString := fmt.Sprintf(
`git commit -m "%s: %s"`, commitType, commitMessage,
)
if commitType == "first_commit" {
commitMessage += "First commit"
commandString = fmt.Sprintf(
`git commit -m "%s"`, commitMessage,
)
} else {
commitMessage = userinput.GetUserInput("What commit message do you want? ", true)
commandString = fmt.Sprintf(
`git commit -m "%s: %s"`, commitType, commitMessage,
)
}

command := exec.Command("/bin/bash", "-c", commandString)

Expand All @@ -138,7 +152,7 @@ simple way to write commits following the Conventional Commits
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
log.Fatal("Unable to execute root command")
}
}

Expand Down
3 changes: 2 additions & 1 deletion config/gbc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ emojis = {
"style": ":sparkles:",
"build": ":construction:",
"ci": ":factory:",
"perf": ":chart_with_upwards_trend:"
"perf": ":chart_with_upwards_trend:",
"first_commit": ":1st_place_medal:"
}

# If you want to commit messages with emojis, change to 'true'.
Expand Down
42 changes: 22 additions & 20 deletions config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import (
)

type Emoji struct {
Feat string `json:"feat"`
Fix string `json:"fix"`
Chore string `json:"chore"`
Refactor string `json:"refactor"`
Test string `json:"test"`
Docs string `json:"docs"`
Style string `json:"style"`
Build string `json:"build"`
Ci string `json:"ci"`
Perf string `json:"perf"`
Feat string `json:"feat"`
Fix string `json:"fix"`
Chore string `json:"chore"`
Refactor string `json:"refactor"`
Test string `json:"test"`
Docs string `json:"docs"`
Style string `json:"style"`
Build string `json:"build"`
Ci string `json:"ci"`
Perf string `json:"perf"`
FirstCommit string `json:"first_commit"`
}

func GetEmojis(fileName string, debug bool) Emoji {
Expand Down Expand Up @@ -100,16 +101,17 @@ func GetEmojis(fileName string, debug bool) Emoji {
}

return Emoji{
Feat: ":rocket:",
Fix: ":bug:",
Chore: ":white_check_mark:",
Refactor: ":hammer:",
Test: ":memo:",
Docs: ":books:",
Style: ":sparkles:",
Build: ":construction:",
Ci: ":factory:",
Perf: ":chart_with_upwards_trend:",
Feat: ":rocket:",
Fix: ":bug:",
Chore: ":white_check_mark:",
Refactor: ":hammer:",
Test: ":memo:",
Docs: ":books:",
Style: ":sparkles:",
Build: ":construction:",
Ci: ":factory:",
Perf: ":chart_with_upwards_trend:",
FirstCommit: ":1st_place_medal:",
}
}

Expand Down

0 comments on commit e3e6bf5

Please sign in to comment.