Skip to content

Commit 07e1e73

Browse files
authored
Feat: tag & upgrade & version & fastcommit (#6)
* fix: barry quick fix, 2025-04-27 18:07:17 * fix: barry quick fix, 2025-04-27 18:08:00 * fix: barry quick fix, 2025-04-27 18:24:42 * fix: barry quick fix, 2025-04-27 23:27:36 * fix: barry quick fix, 2025-04-27 23:36:34 * fix: barry quick fix, 2025-04-27 23:38:27 * fix: barry quick fix, 2025-04-28 09:40:26 * fix: barry quick fix, 2025-04-28 13:50:47 * fix: barry quick fix, 2025-04-28 13:53:37 * fix: barry quick fix, 2025-04-28 13:54:26 * fix: barry quick fix, 2025-04-28 14:07:11 * fix: barry quick fix, 2025-04-28 20:59:28 * fix: barry quick fix, 2025-04-28 21:07:17 * refactor: move branch logging to fastcommit cmd * fix: Add newline to shell result log * refactor: improve logging format and messages * refactor: replace slog.Info with fmt.Println for shell output * feat(tagcmd): add spinner for git fetch operation * feat: add spinner for git message generation * refactor(tagcmd): remove unused imports and update tag prompt * refactor(cmds): update git message prompt text * fix: barry quick fix, 2025-04-28 21:46:36 * feat: add logging to GetAllGitTags * refactor: update logging and config handling * refactor: move config logic to separate file * refactor(fastcommit): print diff files separately * refactor: trim shell command in log output * refactor(fastcommit): replace strings.Join with log loop * refactor(utils): rename GetGitMaxTag to GetNextGitMaxTag * refactor(fastcommit): simplify UI and remove validation * refactor: move openai usage log after push * feat: add prompt to openai response log * feat: add show-prompt flag to fastcommit * refactor: Remove aliases and improve prompt formatting * fix: barry quick fix, 2025-05-06 23:29:51 * fix: barry quick fix, 2025-05-07 12:01:12 * fix: barry quick fix, 2025-05-07 13:48:37 * fix: barry quick fix, 2025-05-07 21:40:54 * fix: barry quick fix, 2025-05-08 22:48:18 * fix: barry quick fix, 2025-05-12 12:19:02 * fix: barry quick fix, 2025-05-12 12:19:48 * fix: barry quick fix, 2025-05-12 12:21:07 * fix: barry quick fix, 2025-05-12 23:09:16 * fix: barry quick fix, 2025-06-04 23:47:51 * fix: barry quick fix, 2025-06-30 11:50:07 * fix: barry quick fix, 2025-06-30 11:57:43 * fix: barry quick fix, 2025-07-15 22:50:13 * fix: barry quick fix, 2025-07-15 23:10:22 * fix: barry quick fix, 2025-07-15 23:24:19 * fix: barry quick fix, 2025-07-15 23:26:16 * fix: barry quick fix, 2025-07-16 12:05:32 * fix: barry quick fix, 2025-07-16 13:38:48 * fix: barry quick fix, 2025-07-16 13:46:16 * fix: barry quick fix, 2025-07-16 20:24:12 * fix: barry quick fix, 2025-07-16 20:24:30 * fix: barry quick fix, 2025-07-25 16:02:07 * fix: barry quick fix, 2025-07-25 16:49:15 * fix: barry quick fix, 2025-07-25 21:11:59 * fix: barry quick fix, 2025-09-06 19:07:22 * fix: barry quick fix, 2025-09-07 17:38:01 * fix: barry quick fix, 2025-09-07 18:05:13 * fix: barry quick fix, 2025-09-07 18:11:01 * fix: barry quick fix, 2025-09-07 18:29:51 * feat: add version file and tag conflict handling * feat(upgrade): add interactive version selection using tap * fix: barry quick fix, 2025-09-07 23:06:02 * fix: barry quick fix, 2025-09-07 23:16:04 * chore: update dependencies and refactor error handling * chore: update dependencies and refactor error handling * fix: barry@feat/ver123, 2025-09-11 09:57:29 * chore: @barry quick update feat/ver123\n at 2025-09-13 09:24:41 * chore: quick update feat/ver123 at 2025-09-13 10:17:36 * feat(fastcommit): set initial value for commit message * chore: quick update feat/ver123 at 2025-09-13 12:58:02
1 parent f8aa5ae commit 07e1e73

File tree

33 files changed

+3278
-399
lines changed

33 files changed

+3278
-399
lines changed

.goreleaser.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ builds:
88
- GOPROXY=https://goproxy.io
99
targets:
1010
- "darwin_amd64"
11-
- "windows_amd64"
11+
- "darwin_arm64"
12+
# - "windows_amd64"
1213
- "linux_amd64"
14+
- "linux_arm64"
1315
ldflags:
14-
- -X 'github.com/pubgo/funk/version.version={{ .Version }}'
16+
- -X 'github.com/pubgo/funk/version.version=v{{ .Version }}'
1517
- -X 'github.com/pubgo/funk/version.project=fastcommit'
1618
- -X 'github.com/pubgo/funk/version.buildTime={{ .CommitDate }}'
1719
- -X 'github.com/pubgo/funk/version.commitID={{ .ShortCommit }}'
@@ -22,8 +24,8 @@ builds:
2224
archives:
2325
- format: tar.gz
2426
name_template: >-
25-
{{ .ProjectName }}_
26-
{{- title .Os }}_
27+
{{ .ProjectName }}-{{ .Tag }}-
28+
{{- .Os }}-
2729
{{- if eq .Arch "amd64" }}x86_64
2830
{{- else if eq .Arch "386" }}i386
2931
{{- else }}{{ .Arch }}{{ end }}

.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.0.6

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Project=fastcommit
22
Base=github.com/pubgo/funk
3+
# git describe --tags --always --dirty
34
VERSION := $(shell git tag --sort=committerdate | tail -n 1)
45
GIT_COMMIT := $(shell git describe --always --abbrev=7 --dirty)
56
BUILD_TIME := $(shell date "+%F %T")

bootstrap/boot.go

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,43 @@ package bootstrap
22

33
import (
44
"log/slog"
5-
"os"
65

76
_ "github.com/adrg/xdg"
87
_ "github.com/charmbracelet/bubbletea"
98
"github.com/pubgo/dix"
10-
"github.com/pubgo/dix/dix_internal"
9+
"github.com/pubgo/funk/config"
10+
"github.com/pubgo/funk/log"
11+
"github.com/pubgo/funk/recovery"
12+
_ "github.com/sashabaranov/go-openai"
13+
14+
"github.com/pubgo/fastcommit/cmds/configcmd"
1115
"github.com/pubgo/fastcommit/cmds/envcmd"
1216
"github.com/pubgo/fastcommit/cmds/fastcommit"
17+
"github.com/pubgo/fastcommit/cmds/historycmd"
1318
"github.com/pubgo/fastcommit/cmds/tagcmd"
19+
"github.com/pubgo/fastcommit/cmds/upgradecmd"
1420
"github.com/pubgo/fastcommit/cmds/versioncmd"
1521
"github.com/pubgo/fastcommit/configs"
1622
"github.com/pubgo/fastcommit/utils"
17-
"github.com/pubgo/funk/assert"
18-
"github.com/pubgo/funk/config"
19-
"github.com/pubgo/funk/pathutil"
20-
"github.com/pubgo/funk/recovery"
21-
"github.com/pubgo/funk/typex"
22-
"github.com/rs/zerolog"
23-
_ "github.com/sashabaranov/go-openai"
24-
"gopkg.in/yaml.v3"
2523
)
2624

27-
func Main() {
25+
func Main(ver string) {
2826
defer recovery.Exit()
2927

30-
slog.Info("config path", "path", configs.GetConfigPath())
31-
typex.DoBlock(func() {
32-
if pathutil.IsNotExist(configs.GetConfigPath()) {
33-
assert.Must(os.WriteFile(configs.GetConfigPath(), configs.GetDefaultConfig(), 0644))
34-
return
35-
}
36-
37-
var cfg ConfigProvider
38-
config.LoadFromPath(&cfg, configs.GetConfigPath())
39-
40-
var defaultCfg ConfigProvider
41-
assert.Exit(yaml.Unmarshal(configs.GetDefaultConfig(), &defaultCfg))
42-
if cfg.Version == nil || cfg.Version.Name == "" || defaultCfg.Version.Name != cfg.Version.Name {
43-
assert.Exit(os.WriteFile(configs.GetConfigPath(), configs.GetDefaultConfig(), 0644))
44-
}
45-
})
28+
slog.SetDefault(slog.New(log.NewSlog(log.GetLogger("fastcommit"))))
4629

47-
config.SetConfigPath(configs.GetConfigPath())
48-
dix_internal.SetLogLevel(zerolog.InfoLevel)
30+
initConfig()
4931

5032
var di = dix.New(dix.WithValuesNull())
5133
di.Provide(versioncmd.New)
52-
di.Provide(func() *configs.Config {
53-
return &configs.Config{
54-
BranchName: configs.GetBranchName(),
55-
}
56-
})
34+
di.Provide(upgradecmd.New)
35+
di.Provide(configs.New)
5736
di.Provide(tagcmd.New)
5837
di.Provide(config.Load[ConfigProvider])
5938
di.Provide(utils.NewOpenaiClient)
6039
di.Provide(envcmd.New)
61-
di.Provide(fastcommit.New)
40+
di.Provide(historycmd.New)
41+
di.Provide(fastcommit.New(ver))
42+
di.Provide(configcmd.New)
6243
di.Inject(func(cmd *fastcommit.Command) { cmd.Run() })
6344
}

bootstrap/config.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
package bootstrap
22

33
import (
4+
"os"
5+
6+
"github.com/pubgo/dix/dixinternal"
7+
"github.com/pubgo/funk/assert"
8+
"github.com/pubgo/funk/config"
9+
"github.com/pubgo/funk/log"
10+
"github.com/pubgo/funk/pathutil"
11+
"github.com/rs/zerolog"
12+
"gopkg.in/yaml.v3"
13+
414
"github.com/pubgo/fastcommit/configs"
515
"github.com/pubgo/fastcommit/utils"
616
)
@@ -9,3 +19,32 @@ type ConfigProvider struct {
919
Version *configs.Version `yaml:"version"`
1020
OpenaiConfig *utils.OpenaiConfig `yaml:"openai"`
1121
}
22+
23+
func initConfig() {
24+
configs.InitEnv()
25+
26+
dixinternal.SetLog(func(logger log.Logger) log.Logger {
27+
if configs.IsDebug() {
28+
return logger.WithLevel(zerolog.DebugLevel)
29+
}
30+
return logger.WithLevel(zerolog.InfoLevel)
31+
})
32+
33+
configPath := configs.GetConfigPath()
34+
defaultConfigData := configs.GetDefaultConfig()
35+
if pathutil.IsNotExist(configPath) {
36+
assert.Must(os.WriteFile(configPath, defaultConfigData, 0644))
37+
return
38+
}
39+
40+
var cfg ConfigProvider
41+
config.LoadFromPath(&cfg, configPath)
42+
43+
var defaultCfg ConfigProvider
44+
assert.Must(yaml.Unmarshal(defaultConfigData, &defaultCfg))
45+
if cfg.Version == nil || cfg.Version.Name == "" || defaultCfg.Version.Name != cfg.Version.Name {
46+
assert.Must(os.WriteFile(configPath, defaultConfigData, 0644))
47+
}
48+
49+
config.SetConfigPath(configPath)
50+
}

cmds/chglogcmd/cmd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package chglogcmd
2+
3+
// https://github.com/goreleaser/chglog/blob/main/pkg/commands/format.go

cmds/cmdutils/utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cmdutils
2+
3+
import (
4+
"sync"
5+
6+
"github.com/pubgo/fastcommit/configs"
7+
"github.com/pubgo/fastcommit/utils"
8+
"github.com/pubgo/funk/log"
9+
)
10+
11+
var GetBranchName = sync.OnceValue(func() string { return utils.GetCurrentBranch().Must() })
12+
13+
func LoadConfigAndBranch() {
14+
branchName := GetBranchName()
15+
log.Info().Msg("current branch: " + branchName)
16+
log.Info().Msg("config: " + configs.GetConfigPath())
17+
}

cmds/configcmd/cmd.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package configcmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"path/filepath"
8+
9+
"github.com/bitfield/script"
10+
"github.com/pkg/browser"
11+
"github.com/pubgo/fastcommit/configs"
12+
"github.com/pubgo/funk/assert"
13+
"github.com/pubgo/funk/log"
14+
"github.com/pubgo/funk/recovery"
15+
"github.com/urfave/cli/v3"
16+
)
17+
18+
func New() *cli.Command {
19+
return &cli.Command{
20+
Name: "config",
21+
Usage: "config management",
22+
Action: func(ctx context.Context, command *cli.Command) error {
23+
defer recovery.Exit()
24+
25+
cfgPath := configs.GetConfigPath()
26+
log.Info().Msgf("config path: %s", cfgPath)
27+
28+
log.Info().Msgf("config data: \n%s", assert.Must1(os.ReadFile(cfgPath)))
29+
return nil
30+
},
31+
Commands: []*cli.Command{
32+
{
33+
Name: "edit",
34+
Usage: "fastcommit config edit [open|vim|zed|code|...]",
35+
Action: func(ctx context.Context, command *cli.Command) error {
36+
log.Info().Msgf("config path: %s", configs.GetConfigPath())
37+
38+
if command.Args().Len() == 0 {
39+
return browser.OpenFile(configs.GetConfigPath())
40+
}
41+
42+
cmd := command.Args().First()
43+
44+
path := assert.Exit1(filepath.Abs(configs.GetConfigPath()))
45+
shell := fmt.Sprintf(`%s "%s"`, cmd, path)
46+
log.Info().Msgf("edit config: %s", shell)
47+
_, err := script.Exec(shell).Stdout()
48+
return err
49+
},
50+
},
51+
},
52+
}
53+
}

cmds/envcmd/cmd.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package envcmd
22

33
import (
44
"context"
5-
6-
"github.com/pubgo/fastcommit/configs"
7-
"github.com/pubgo/funk/assert"
5+
6+
"github.com/pubgo/funk/env"
87
"github.com/pubgo/funk/pretty"
98
"github.com/pubgo/funk/recovery"
109
"github.com/samber/lo"
1110
"github.com/urfave/cli/v3"
12-
"gopkg.in/yaml.v3"
11+
12+
"github.com/pubgo/fastcommit/configs"
1313
)
1414

1515
func New() *cli.Command {
@@ -18,15 +18,17 @@ func New() *cli.Command {
1818
Usage: "show all envs",
1919
Action: func(ctx context.Context, command *cli.Command) error {
2020
defer recovery.Exit()
21-
var envData = configs.GetEnvConfig()
22-
var envMap = make(map[string]*configs.EnvConfig)
23-
assert.Must(yaml.Unmarshal(envData, &envMap))
24-
for name := range envMap {
25-
envMap[name].Name = name
21+
22+
envMap := configs.GetEnvMap()
23+
for name, cfg := range envMap {
24+
envData := env.Get(name)
25+
if envData == "" {
26+
continue
27+
}
28+
cfg.Default = envData
2629
}
2730

2831
pretty.Println(lo.Values(envMap))
29-
3032
return nil
3133
},
3234
}

0 commit comments

Comments
 (0)