Skip to content

Commit

Permalink
feat: draft commit-type selector
Browse files Browse the repository at this point in the history
  • Loading branch information
SKalt committed Oct 21, 2020
1 parent 9ff453c commit 291f660
Show file tree
Hide file tree
Showing 6 changed files with 481 additions and 100 deletions.
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
# git-cc
> a git extension to help write [conventional commits][cc-standard]
## install
## Installation

<details open><summary>With Go</summary>

```sh
go install github.com/skalt/git-cc
```

</details>

<!-- TODO: with npm -->
<!-- TODO: with yarn -->
<!-- TODO: with pnpm -->

<!-- TODO: with pip -->
<!-- TODO: with pipenv -->
<!-- TODO: with poetry -->
<!-- TODO: with conda -->

<!-- TODO: with cargo? -->

git cc feat added conventional commits
# --> "feat: added conventional commits"
git cc feat: added conventional commits
# --> "feat: added conventional commits"
git cc fix something: an error
# --> "fix(something): an error"

git cc feat
# interactively write a conventional commit from the description onward
git cc
# interactively write a conventional commit!
<!-- TODO: with apt -->
<!-- TODO: with rpm -->
<!-- TODO: with brew -->
<!-- TODO: with git -->


## Usage

```sh
# interactively write a conventional commit
git cc # in its entirety
git cc feat # from the commit-type onwards
git cc 'feat(scope)' # from the scope onwards

# or validate your conventional commit
git cc feat: added conventional commits # ok! creates a commit
git cc feat add a typo # starts interaction at the scope
```

<!--
## Why Conventional Commits?
The cool kids are doing it.
Expand Down
87 changes: 87 additions & 0 deletions cmd/git-cc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"fmt"
"log"

tea "github.com/charmbracelet/bubbletea"
input "github.com/skalt/git-cc/pkg/tui_single_select"
)

// TODO: move to cfg
var commitTypes = [...]string{ // ordered in terms of frequency ?
"feat",
"fix",
"docs",
"chore",
"style",
"refactor",
"perf",
"test",
"build",
"ci",
"revert",
}
var commitTypePrompts = map[string]string{
// see https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#type
// see https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js#L23
"feat": "adds a new feature",
"fix": "fixes a bug",
"docs": "changes only the documentation",
"style": "changes the style but not the meaning of the code (such as formatting)",
"perf": "improves performance",
"test": "adds or corrects tests",
"build": "changes the build system or external dependencies",
"chore": "changes outside the code, docs, or tests",
"ci": "changes to the Continuous Inegration (CI) system",
"refactor": "changes the code without changing behavior",
"revert": "reverts prior changes",
}

type model struct {
choice chan<- string
textInput input.Model
}

func (m model) Init() tea.Cmd {
return nil
}

func main() {
choice := make(chan string, 1)
ui := tea.NewProgram(initialModel(choice))
if err := ui.Start(); err != nil {
log.Fatal(err)
}

if r := <-choice; r != "" {
fmt.Printf("\n---\nYou chose %s!\n", r)
}
}

// Pass a channel to the model to listen to the result value. This is a
// function that returns the initialize function and is typically how you would
// pass arguments to a tea.Init function.
func initialModel(choice chan string) model {
hints := []string{}
options := []string{}
for _, commitType := range commitTypes {
options = append(options, commitType)
hint := commitTypePrompts[commitType]
hints = append(hints, hint)
}
textModel := input.NewModel(" ", options, hints, choice)
return model{
textInput: textModel,
}
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
m.textInput, cmd = input.Update(msg, m.textInput)
return m, cmd
}

func (m model) View() string {
return m.textInput.View()
}
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ module github.com/skalt/git-cc
go 1.14

require (
github.com/charmbracelet/bubbletea v0.11.1 // indirect
github.com/go-git/go-git/v5 v5.0.0 // indirect
github.com/manifoldco/promptui v0.7.0
github.com/spf13/cobra v1.0.0 // indirect
github.com/charmbracelet/bubbles v0.7.0
github.com/charmbracelet/bubbletea v0.12.0
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776
github.com/lucasb-eyer/go-colorful v1.0.3
github.com/muesli/reflow v0.1.0
github.com/muesli/termenv v0.7.4
github.com/spf13/viper v1.7.1
)
Loading

0 comments on commit 291f660

Please # to comment.