@@ -3,7 +3,6 @@ package fastcommit
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "github.com/yarlson/tap"
7
6
"os"
8
7
"sort"
9
8
"strconv"
@@ -20,6 +19,7 @@ import (
20
19
"github.com/pubgo/funk/v2/result"
21
20
"github.com/sashabaranov/go-openai"
22
21
"github.com/urfave/cli/v3"
22
+ "github.com/yarlson/tap"
23
23
24
24
"github.com/pubgo/fastcommit/cmds/cmdutils"
25
25
"github.com/pubgo/fastcommit/configs"
@@ -77,14 +77,13 @@ func New(version string) func(params Params) *Command {
77
77
if errors .Is (err , context .Canceled ) {
78
78
return nil
79
79
}
80
- return err
81
- })
82
80
83
- defer func () {
84
- if errors .Is (gErr , context .Canceled ) {
85
- gErr = nil
81
+ if err .Error () == "signal: interrupt" {
82
+ return nil
86
83
}
87
- }()
84
+
85
+ return err
86
+ })
88
87
89
88
if command .Args ().Len () > 0 {
90
89
log .Error (ctx ).Msgf ("unknown command:%v" , command .Args ().Slice ())
@@ -99,37 +98,44 @@ func New(version string) func(params Params) *Command {
99
98
100
99
cmdutils .LoadConfigAndBranch ()
101
100
102
- allTags := utils .GetAllGitTags ()
101
+ allTags := utils .GetAllGitTags (ctx )
103
102
tagName := "v0.0.1"
104
103
if len (allTags ) > 0 {
105
104
ver := utils .GetNextReleaseTag (allTags )
106
105
tagName = "v" + strings .TrimPrefix (ver .Original (), "v" )
107
106
}
108
107
assert .Exit (os .WriteFile (".version" , []byte (tagName ), 0644 ))
109
108
110
- repoPath := assert .Must1 (utils .AssertGitRepo ())
109
+ repoPath := assert .Must1 (utils .AssertGitRepo (ctx ))
111
110
log .Info ().Msg ("git repo: " + repoPath )
112
111
113
112
//username := strings.TrimSpace(assert.Must1(utils.RunOutput("git", "config", "get", "user.name")))
114
113
115
114
if flags .fastCommit {
116
- preMsg := strings .TrimSpace (assert .Must1 (utils .RunOutput ("git" , "log" , "-1" , "--pretty=%B" )))
115
+ preMsg := strings .TrimSpace (assert .Must1 (utils .RunOutput (ctx , "git" , "log" , "-1" , "--pretty=%B" )))
117
116
prefixMsg := fmt .Sprintf ("chore: quick update %s" , cmdutils .GetBranchName ())
118
117
msg := fmt .Sprintf ("%s at %s" , prefixMsg , time .Now ().Format (time .DateTime ))
119
118
120
- assert .Must (utils .RunShell ("git" , "add" , "-A" ))
119
+ assert .Must (utils .RunShell (ctx , "git" , "add" , "-A" ))
121
120
if strings .Contains (preMsg , prefixMsg ) {
122
- assert .Must (utils .RunShell ("git" , "commit" , "--amend" , "--no-edit" , "-m" , strconv .Quote (msg )))
121
+ assert .Must (utils .RunShell (ctx , "git" , "commit" , "--amend" , "--no-edit" , "-m" , strconv .Quote (msg )))
123
122
} else {
124
- assert .Must (utils .RunShell ("git" , "commit" , "-m" , strconv .Quote (msg )))
123
+ assert .Must (utils .RunShell (ctx , "git" , "commit" , "-m" , strconv .Quote (msg )))
125
124
}
126
- assert .Must (utils .RunShell ("git" , "push" , "--force-with-lease" , "origin" , cmdutils .GetBranchName ()))
125
+
126
+ s := spinner .New (spinner .CharSets [35 ], 100 * time .Millisecond , func (s * spinner.Spinner ) {
127
+ s .Prefix = "push git message: "
128
+ })
129
+ s .Start ()
130
+ result .ErrOf (utils .RunShell (ctx , "git" , "push" , "--force-with-lease" , "origin" , cmdutils .GetBranchName ())).
131
+ Log ().Must ()
132
+ s .Stop ()
127
133
return
128
134
}
129
135
130
- assert .Must (utils .RunShell ("git" , "add" , "--update" ))
136
+ assert .Must (utils .RunShell (ctx , "git" , "add" , "--update" ))
131
137
132
- diff := assert .Must1 (utils .GetStagedDiff (nil ))
138
+ diff := assert .Must1 (utils .GetStagedDiff (ctx ))
133
139
if diff == nil || len (diff .Files ) == 0 {
134
140
return nil
135
141
}
@@ -172,31 +178,24 @@ func New(version string) func(params Params) *Command {
172
178
}
173
179
174
180
msg := resp .Choices [0 ].Message .Content
175
- msg = tap .Text (ctx , tap.TextOptions {
176
- Message : "git message(update or enter) >> " ,
181
+ msg = strings . TrimSpace ( tap .Text (ctx , tap.TextOptions {
182
+ Message : "git message(update or enter): " ,
177
183
InitialValue : msg ,
178
184
DefaultValue : msg ,
179
185
Placeholder : "update or enter" ,
180
- })
186
+ }))
181
187
182
188
if msg == "" {
183
189
return
184
190
}
185
191
186
- //var p1 = tea.NewProgram(initialTextInputModel(msg))
187
- //mm := assert.Must1(p1.Run()).(model2)
188
- //if mm.isExit() {
189
- // return nil
190
- //}
191
-
192
- //msg = mm.Value()
193
- assert .Must (utils .RunShell ("git" , "commit" , "-m" , strconv .Quote (msg )))
194
- assert .Must (utils .RunShell ("git" , "push" , "origin" , cmdutils .GetBranchName ()))
192
+ assert .Must (utils .RunShell (ctx , "git" , "commit" , "-m" , strconv .Quote (msg )))
193
+ assert .Must (utils .RunShell (ctx , "git" , "push" , "origin" , cmdutils .GetBranchName ()))
195
194
if flags .showPrompt {
196
195
fmt .Println ("\n " + generatePrompt + "\n " )
197
196
}
198
197
log .Info ().Any ("usage" , resp .Usage ).Msg ("openai response usage" )
199
- return nil
198
+ return
200
199
},
201
200
}
202
201
0 commit comments