Skip to content

Commit

Permalink
Feat/tpye scope list (#32)
Browse files Browse the repository at this point in the history
* fix: 🐛 (#26) issue with .gitmojirc not found error

issue was simply a viper.WatchConfig when no config was available

* feat(types): ✨ (#19) add prompt with list to select commit type

* docs: 📝 (#19) update the documentation
  • Loading branch information
AndreasAugustin committed Aug 18, 2023
1 parent 01106c5 commit 29accbc
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 31 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,17 @@ go-gitmoji-cli --version

```bash
# list the available gitmojis
go-gitmoji-cli list
go-gitmoji-cli list gitmojis
```

![list](docs/assets/list.gif)
![list](docs/assets/list_gitmojis.gif)

```bash
# list the available commit types
go-gitmoji-cli list commit-types
```

![list](docs/assets/list_commit_types.gif)

### Commit

Expand Down
10 changes: 7 additions & 3 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ var CommitCmd = &cobra.Command{
log.Fatalf("get current config issue, %s", err)
}
gitmojis := pkg.GetGitmojis(config)

defaultTypes := pkg.DefaultCommitTypes()
initialCommitValues := pkg.BuildInitialCommitValues(_type, scope, desc, body, commitMsg)
listSettings := ui.ListSettings{IsShowStatusBar: true, IsFilteringEnabled: true, Title: "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(listSettings, gitmojis.Gitmojis)
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
34 changes: 30 additions & 4 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@ import (
"github.com/spf13/cobra"
)

// ListCmd represents the list command
var ListCmd = &cobra.Command{
Use: "list",
var ListCommitTypesCmd = &cobra.Command{
Use: "commit-types",
Short: "List all the available commit types",
Long: "The list from conventional commits is used",
Run: func(cmd *cobra.Command, args []string) {
log.Debug("list commit-types called")
spin := ui.NewSpinner()
spin.Run()
defaultTypes := pkg.DefaultCommitTypes()
spin.Stop()
listSettings := ui.ListSettings{Title: "Commit types", IsShowStatusBar: true, IsFilteringEnabled: true}
selectedDefaultType := ui.ListRun(listSettings, defaultTypes)
log.Debugf("selected %s", selectedDefaultType)
},
}

var ListGitmojisCmd = &cobra.Command{
Use: "gitmojis",
Short: "List all the available gitmojis",
Long: fmt.Sprintf(`The list is queried from the api %s.`, pkg.DefaultGitmojiApiUrl),
Run: func(cmd *cobra.Command, args []string) {
log.Debug("list called")
log.Debug("list gitmojis called")
spin := ui.NewSpinner()
spin.Run()
config, err := pkg.GetCurrentConfig()
Expand All @@ -29,6 +44,17 @@ var ListCmd = &cobra.Command{
},
}

var ListCmd = &cobra.Command{
Use: "list",
Short: "List all the available gitmojis",
Long: fmt.Sprintf(`The list is queried from the api %s.`, pkg.DefaultGitmojiApiUrl),
Run: func(cmd *cobra.Command, args []string) {
log.Debug("list called")
},
}

func init() {
RootCmd.AddCommand(ListCmd)
ListCmd.AddCommand(ListGitmojisCmd)
ListCmd.AddCommand(ListCommitTypesCmd)
}
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SHELL := /bin/bash
# VARIABLES
###########################

TAPES := commit.tape config.tape help.tape list.tape version.tape
TAPES := commit.tape config.tape help.tape list_commit_types.tape list_gitmojis.tape version.tape

###########################
# MAPPINGS
Expand Down
4 changes: 2 additions & 2 deletions docs/assets/commit.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions docs/assets/list.gif

This file was deleted.

3 changes: 3 additions & 0 deletions docs/assets/list_commit_types.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/assets/list_gitmojis.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions docs/commit.tape
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ Sleep 500ms
Type "go-gitmoji-cli commit --dry-run"
Sleep 500ms
Enter
# gitmojis
Sleep 1s
Enter
# commit types
Sleep 1s
Type "feat"
Sleep 500ms
# Type "feat"
Enter
# type and feat prompt
Enter
Type "this is an example"
Sleep 500ms
Expand Down
80 changes: 80 additions & 0 deletions docs/list_commit_types.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# VHS documentation
#
# Output:
# Output <path>.gif Create a GIF output at the given <path>
# Output <path>.mp4 Create an MP4 output at the given <path>
# Output <path>.webm Create a WebM output at the given <path>
#
# Require:
# Require <string> Ensure a program is on the $PATH to proceed
#
# Settings:
# Set FontSize <number> Set the font size of the terminal
# Set FontFamily <string> Set the font family of the terminal
# Set Height <number> Set the height of the terminal
# Set Width <number> Set the width of the terminal
# Set LetterSpacing <float> Set the font letter spacing (tracking)
# Set LineHeight <float> Set the font line height
# Set LoopOffset <float>% Set the starting frame offset for the GIF loop
# Set Theme <json|string> Set the theme of the terminal
# Set Padding <number> Set the padding of the terminal
# Set Framerate <number> Set the framerate of the recording
# Set PlaybackSpeed <float> Set the playback speed of the recording
# Set MarginFill <file|#000000> Set the file or color the margin will be filled with.
# Set Margin <number> Set the size of the margin. Has no effect if MarginFill isn't set.
# Set BorderRadius <number> Set terminal border radius, in pixels.
# Set WindowBar <string> Set window bar type. (one of: Rings, RingsRight, Colorful, ColorfulRight)
# Set WindowBarSize <number> Set window bar size, in pixels. Default is 40.
# Set TypingSpeed <time> Set the typing speed of the terminal. Default is 50ms.
#
# Sleep:
# Sleep <time> Sleep for a set amount of <time> in seconds
#
# Type:
# Type[@<time>] "<characters>" Type <characters> into the terminal with a
# <time> delay between each character
#
# Keys:
# Backspace[@<time>] [number] Press the Backspace key
# Down[@<time>] [number] Press the Down key
# Enter[@<time>] [number] Press the Enter key
# Space[@<time>] [number] Press the Space key
# Tab[@<time>] [number] Press the Tab key
# Left[@<time>] [number] Press the Left Arrow key
# Right[@<time>] [number] Press the Right Arrow key
# Up[@<time>] [number] Press the Up Arrow key
# Down[@<time>] [number] Press the Down Arrow key
# PageUp[@<time>] [number] Press the Page Up key
# PageDown[@<time>] [number] Press the Page Down key
# Ctrl+<key> Press the Control key + <key> (e.g. Ctrl+C)
#
# Display:
# Hide Hide the subsequent commands from the output
# Show Show the subsequent commands in the output

Output assets/list_commit_types.gif

Require go-gitmoji-cli

Set Shell "zsh"
# Set FontSize 32
# Set Width 1200
# Set Height 600

Sleep 500ms
Type "go-gitmoji-cli list commit-types"
Sleep 500ms
Enter
Type "[B"
Type "[B"
Type "[B"
Type "[B"
Type "[A"
Type "[A"
Sleep 500ms
Type "/"
Sleep 1.5s
Type "test"
Sleep 500ms
Enter
Sleep 2s
4 changes: 2 additions & 2 deletions docs/list.tape → docs/list_gitmojis.tape
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# Hide Hide the subsequent commands from the output
# Show Show the subsequent commands in the output

Output assets/list.gif
Output assets/list_gitmojis.gif

Require go-gitmoji-cli

Expand All @@ -62,7 +62,7 @@ Set Shell "zsh"
# Set Height 600

Sleep 500ms
Type "go-gitmoji-cli list"
Type "go-gitmoji-cli list gitmojis"
Sleep 500ms
Enter
Type "[B"
Expand Down
6 changes: 3 additions & 3 deletions pkg/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type TextInputRes struct {
type CommitFlagName string

const (
SCOPE CommitFlagName = "scope"
DESC CommitFlagName = "desc"
SCOPE CommitFlagName = "Scope"
DESC CommitFlagName = "Desc"
TYPE CommitFlagName = "type"
BODY CommitFlagName = "body"
IS_BREAKING CommitFlagName = "is-breaking"
Expand Down Expand Up @@ -214,7 +214,7 @@ func (i InitialCommitValues) BuildTextInputsData(config Config) []TextInputData
var textInputsData = []TextInputData{{Placeholder: "type", Charlimit: 64, Label: string(TYPE), InitialValue: i.Type}}

if config.ScopePrompt {
textInputsData = append(textInputsData, TextInputData{Placeholder: "scope", Charlimit: 64, Label: string(SCOPE), InitialValue: i.Scope})
textInputsData = append(textInputsData, TextInputData{Placeholder: "Scope", Charlimit: 64, Label: string(SCOPE), InitialValue: i.Scope})
}

textInputsData = append(textInputsData, TextInputData{Placeholder: "description", Charlimit: 64, Label: string(DESC), InitialValue: i.Desc})
Expand Down
30 changes: 24 additions & 6 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"path"
)

var configIsInit = false
var ConfigIsInit = false

const ProgramName = "go-gitmoji-cli"

Expand All @@ -32,7 +32,7 @@ func ProgramNameFigure() {
}

func InitConfig() {
if configIsInit {
if ConfigIsInit {
return
}

Expand All @@ -45,7 +45,7 @@ func InitConfig() {
fmt.Println("Error:", err)
os.Exit(1)
}
configIsInit = true
ConfigIsInit = true
}

func getGlobalConfigPath() (string, error) {
Expand Down Expand Up @@ -73,13 +73,14 @@ func LoadConfig(configPaths []string) (err error) {

viper.SetConfigName(configName)
if expErr := viper.ReadInConfig(); expErr != nil {
// It's okay if there isn't a config file
log.Debug("issue reading config")
var configFileNotFoundError viper.ConfigFileNotFoundError
if !errors.As(expErr, &configFileNotFoundError) {
return
}
} else {
viper.WatchConfig()
}
viper.WatchConfig()
}

viper.AutomaticEnv()
Expand All @@ -89,7 +90,7 @@ func LoadConfig(configPaths []string) (err error) {

func GetCurrentConfig() (config Config, err error) {
log.Debug("Get current config")
if !configIsInit {
if !ConfigIsInit {
InitConfig()
}
err = viper.Unmarshal(&config)
Expand All @@ -99,6 +100,7 @@ func GetCurrentConfig() (config Config, err error) {

func UpdateConfig(config Config, isGlobalConfig bool) {
viper.Set(string(AUTO_ADD), config.AutoAdd)
viper.Set(string(AUTO_SIGN), config.AutoSign)
viper.Set(string(EMOJI_FORMAT), string(config.EmojiFormat))
viper.Set(string(SCOPE_PROMPT), config.ScopePrompt)
viper.Set(string(BODY_PROMPT), config.BodyPrompt)
Expand Down Expand Up @@ -127,3 +129,19 @@ func configFilePath(isGlobalConfig bool) string {
return path.Join(configPath, name)
}
}

func DefaultCommitTypes() []CommitType {
return []CommitType{
{Type: "feat", Desc: "A new feature"},
{Type: "fix", Desc: "A bug fix"},
{Type: "docs", Desc: "Documentation only changes"},
{Type: "style", Desc: "Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)"},
{Type: "refactor", Desc: "A code change that neither fixes a bug nor adds a feature"},
{Type: "perf", Desc: "A code change that improves performance"},
{Type: "test", Desc: "Adding missing tests or correcting existing tests"},
{Type: "build", Desc: "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)"},
{Type: "ci", Desc: "Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)"},
{Type: "chore", Desc: "Other changes that don't modify src or test files"},
{Type: "revert", Desc: "Reverts a previous commit"},
}
}
Loading

0 comments on commit 29accbc

Please sign in to comment.