Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: 🐛 (#44) issue with hook #45

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/release_go.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: goreleaser

on:
push:
# run only against tags
tags:
- v*.*.*
# push:
# # run only against tags
# tags:
# - v*.*.*
release:
types: [ published ]

permissions:
contents: write
Expand Down
8 changes: 7 additions & 1 deletion cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ var CommitCmd = &cobra.Command{
}
gitmojis := pkg.GetGitmojis(config)
defaultTypes := pkg.DefaultCommitTypes()
initialCommitValues := pkg.BuildInitialCommitValues(_type, scope, desc, body, commitMsg)
initialCommitValues := pkg.BuildInitialCommitValues(
_type,
scope,
desc,
body,
commitMsg,
)
listSettingsGitmojis := ui.ListSettings{IsShowStatusBar: true, IsFilteringEnabled: true, Title: "Gitmojis"}
listSettingsCommitTypes := ui.ListSettings{Title: "Commit types", IsShowStatusBar: true, IsFilteringEnabled: true}
spin.Stop()
Expand Down
34 changes: 27 additions & 7 deletions cmd/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,18 @@ var HooksCmd = &cobra.Command{
log.Debug("hooks called")
log.Debugf("run: %v", args)
if hook {
if len(args) == 0 {
log.Fatalf("len(args) must not be 0 when using pre-commit-message hook https://git-scm.com/docs/githooks#_prepare_commit_msg")
}
hookCommitMessageFile := args[0]
log.Debugf("hook commit message file %s", hookCommitMessageFile)
hookCommit(hookCommitMessageFile)
} else {
err := cmd.Help()
if err != nil {
log.Fatalf("issue with the help command %s", err)
return
}
}
},
}
Expand All @@ -71,6 +81,7 @@ func hookCommit(commitMsgFile string) {
log.Debug(commitMsg)
spin := ui.NewSpinner()
spin.Run()
defer func() { spin.Stop() }()
existentHookFiles, err := pkg.HookFilesExistent()
if err != nil {
log.Fatalf("Error checking if hook files existent")
Expand All @@ -81,25 +92,34 @@ func hookCommit(commitMsgFile string) {
spin.Stop()
return
}
parsedMessages, err := pkg.ReadAndParseCommitEditMsg(commitMsgFile)
if err != nil {
log.Fatalf("issue reading and parsing the commit msg file %s", err)
}
config, err := pkg.GetCurrentConfig()
if err != nil {
log.Fatalf("get current config issue, %s", err)
}
parsedMessages, err := pkg.ReadAndParseCommitEditMsg(commitMsgFile)
if err != nil {
log.Fatalf("issue reading and parsing the commit msg file %s", err)
}

gitmojis := pkg.GetGitmojis(config)
spin.Stop()
defaultTypes := pkg.DefaultCommitTypes()

initialCommitValues := pkg.InitialCommitValues{
Type: parsedMessages.Type,
Scope: parsedMessages.Scope,
Desc: parsedMessages.Desc,
Body: parsedMessages.Body,
}
listSettings := ui.ListSettings{IsShowStatusBar: true, IsFilteringEnabled: true, Title: "Gitmojis"}
selectedGitmoji := ui.ListRun(listSettings, gitmojis.Gitmojis)
listSettingsGitmojis := ui.ListSettings{IsShowStatusBar: true, IsFilteringEnabled: true, Title: "Gitmojis"}
listSettingsCommitTypes := ui.ListSettings{Title: "Commit types", IsShowStatusBar: true, IsFilteringEnabled: true}

spin.Stop()

selectedGitmoji := ui.ListRun(listSettingsGitmojis, gitmojis.Gitmojis)
log.Debugf("selected gitmoji %s", selectedGitmoji)
selectedDefaultType := ui.ListRun(listSettingsCommitTypes, defaultTypes)
log.Debugf("selected %s", selectedDefaultType)
initialCommitValues.Type = selectedDefaultType.Type
textInputsData := initialCommitValues.BuildTextInputsData(config)
inputsRes := ui.TextInputsRun("please add", textInputsData)

Expand Down
2 changes: 1 addition & 1 deletion pkg/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hookName=` + "`basename \"$0\"`" + `
gitParams="$*"

if command -v go-gitmoji-cli >/dev/null 2>&1; then
go-gitmoji-cli hooks --hook "$gitParams"
go-gitmoji-cli hooks --hook $gitParams
else
echo "Can't find go-gitmoji-cli, skipping $hookName hook"
echo "You can reinstall it using 'go get -u github.com/AndreasAugustin/go-gitmoji-cli' or delete this hook"
Expand Down
2 changes: 1 addition & 1 deletion pkg/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ hookName=` + "`basename \"$0\"`" + `
gitParams="$*"

if command -v go-gitmoji-cli >/dev/null 2>&1; then
go-gitmoji-cli hooks --hook "$gitParams"
go-gitmoji-cli hooks --hook $gitParams
else
echo "Can't find go-gitmoji-cli, skipping $hookName hook"
echo "You can reinstall it using 'go get -u github.com/AndreasAugustin/go-gitmoji-cli' or delete this hook"
Expand Down