Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ jobs:
key: commitizen-${{ github.event.pull_request.number }}-${{ github.sha }}
- name: Run E2E test
run: |
GOPATH=~/go make e2e NO_TTY=1
GOPATH=~/go make e2e
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ Options:
This option is available when using: make release
V Set to 1 enable verbose build. Default is 0.
DEBUG Whether to generate debug symbols. Default is 0.
NO_TTY Make sure that the TTY (terminal) is never used for
any output. Default is 0.
endef
export USAGE_OPTIONS

Expand Down
2 changes: 1 addition & 1 deletion cmd/cz/cz.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func New() *cobra.Command {
return err
}

msg, err := tmpl.Run(o.NoTTY)
msg, err := tmpl.Run()
if err != nil {
return err
}
Expand Down
11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module github.com/shipengqi/commitizen
go 1.22

require (
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.10.0
github.com/charmbracelet/huh v0.3.0
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.33.0
github.com/shipengqi/component-base v0.2.9
Expand All @@ -19,6 +17,10 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/bubbles v0.18.0 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/lipgloss v0.10.0 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
Expand All @@ -34,12 +36,11 @@ require (
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/huh v0.3.0 h1:CxPplWkgW2yUTDDG0Z4S5HH8SJOosWHd4LxCvi0XsKE=
github.com/charmbracelet/huh v0.3.0/go.mod h1:fujUdKX8tC45CCSaRQdw789O6uaCRwx8l2NDyKfC4jA=
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
Expand Down Expand Up @@ -41,8 +45,6 @@ github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand All @@ -57,8 +59,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
Expand All @@ -76,8 +78,6 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/shipengqi/component-base v0.2.9 h1:4XRB6PzTRgqKkkxkJwnpK8YOqDHRzXviyyis67YBhgE=
github.com/shipengqi/component-base v0.2.9/go.mod h1:LfbMJtgUW7nNPwmVIi5wJMif/066edkcIJtkDDJgEQQ=
github.com/shipengqi/golib v0.2.12 h1:/0hrev7+J8KChxEvoVdS2kbGQT8VO4C4qFAhtn6ZI8o=
Expand Down
3 changes: 1 addition & 2 deletions hack/include/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

GINKGO := $(shell go env GOPATH)/bin/ginkgo
CLI ?= $(OUTPUT_DIR)/commitizen
NO_TTY ?= 0

.PHONY: test.cover
test.cover:
Expand All @@ -25,4 +24,4 @@ test.cover:
.PHONY: test.e2e
test.e2e: tools.verify.ginkgo
@echo "===========> Run e2e test, CLI: $(CLI)"
@$(GINKGO) -v $(REPO_ROOT)/test/e2e -- -cli=$(CLI) -no-tty=$(NO_TTY)
@$(GINKGO) -v $(REPO_ROOT)/test/e2e -- -cli=$(CLI)
43 changes: 20 additions & 23 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import (
"os"
"path/filepath"

"github.com/charmbracelet/huh"
"github.com/shipengqi/golib/convutil"
"github.com/shipengqi/golib/fsutil"
"github.com/shipengqi/golib/sysutil"
"gopkg.in/yaml.v3"

"github.com/shipengqi/commitizen/internal/options"
"github.com/shipengqi/commitizen/internal/render"
"github.com/shipengqi/commitizen/internal/ui"
)

const (
RCFilename = ".git-czrc"
ReservedDefaultName = "default"
RCFilename = ".git-czrc"
ReservedDefaultName = "default"
FieldKeyTemplateSelect = "template-select"
)

type Config struct {
Expand Down Expand Up @@ -59,7 +60,7 @@ func (c *Config) initialize() error {
continue
}
if v.Name == ReservedDefaultName {
return errors.New("template name 'default' is reserved, use 'default' as the template name, default must be true")
return errors.New("template name 'default' is reserved, to override the default template, you need to set default to true")
}
if _, ok := exists[v.Name]; ok {
return fmt.Errorf("duplicate template '%s'", v.Name)
Expand Down Expand Up @@ -103,14 +104,12 @@ func (c *Config) Run(opts *options.Options) (*render.Template, error) {
}

if len(c.more) > 0 {
model := c.createTemplatesSelect("Select a template to use for this commit:")
if _, err = ui.Run(model, opts.NoTTY); err != nil {
form := c.createTemplatesSelect("Select the template of change that you're committing:")
if err = form.Run(); err != nil {
return nil, err
}
if model.Canceled() {
return nil, render.ErrCanceled
}
val := model.Value()

val := form.GetString(FieldKeyTemplateSelect)
if val == c.defaultTmpl.Name {
return c.defaultTmpl, nil
}
Expand All @@ -123,25 +122,23 @@ func (c *Config) Run(opts *options.Options) (*render.Template, error) {
return c.defaultTmpl, nil
}

func (c *Config) createTemplatesSelect(label string) *ui.SelectModel {
var choices ui.Choices
func (c *Config) createTemplatesSelect(label string) *huh.Form {
var choices []string
var all []*render.Template
all = append(all, c.more...)
all = append(all, c.defaultTmpl)
// list custom templates and default templates
for _, v := range all {
choices = append(choices, ui.Choice(v.Name))
choices = append(choices, v.Name)
}
height := 8
if len(all) > 5 {
height = 12
} else if len(all) > 3 {
height = 10
} else if len(all) > 2 {
height = 9
}
m := ui.NewSelect(label, choices).WithHeight(height)
return m

return huh.NewForm(huh.NewGroup(
huh.NewNote().Title("Commitizen").Description("Welcome to Commitizen!\nFor further configuration visit:\nhttps://github.com/shipengqi/commitizen"),
huh.NewSelect[string]().
Key(FieldKeyTemplateSelect).
Options(huh.NewOptions(choices...)...).
Title(label)),
)
}

func LoadTemplates(file string) ([]*render.Template, error) {
Expand Down
4 changes: 0 additions & 4 deletions internal/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

type Options struct {
DryRun bool
NoTTY bool
Default bool
Template string
GitOptions *git.Options
Expand All @@ -28,9 +27,6 @@ func (o *Options) Flags() (fss cliflag.NamedFlagSets) {
fs.BoolVar(&o.DryRun, "dry-run", o.DryRun, "do not create a commit, but show the message and list of paths \nthat are to be committed.")
fs.StringVarP(&o.Template, "template", "t", o.Template, "template name to use when multiple templates exist.")
fs.BoolVarP(&o.Default, "default", "d", o.Default, "use the default template, '--default' has a higher priority than '--template'.")
fs.BoolVar(&o.NoTTY, "no-tty", o.NoTTY, "make sure that the TTY (terminal) is never used for any output.")

_ = fs.MarkHidden("no-tty")

return
}
5 changes: 0 additions & 5 deletions internal/render/errors.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package render

import (
"errors"
"fmt"
)

var (
ErrCanceled = errors.New("canceled")
)

type MissingErr struct {
field string
}
Expand Down
Loading