Skip to content

Commit 1b54799

Browse files
committed
refactor: Simplify trace JSON marshaling
The trace JSON marshaling logic in `cmd/root.go` was unnecessarily verbose. This commit simplifies it by directly marshaling the `TraceWrapper` struct without creating intermediate variables. This change improves code readability and maintainability without altering the functionality. --- {"auto-commit-msg":{"language":"rust","version":"0.4.0-dev","model":"gemini-2.5-flash-lite","response_time":1.46,"execution_time":1.49}}
1 parent 15727d0 commit 1b54799

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

cmd/root.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,20 @@ var rootCmd = &cobra.Command{
148148
commitMsg := res.Choices[0].Message.Content
149149
if config.Trace {
150150
executionDuration := time.Since(executionTime)
151-
trace := Trace{
152-
Language: "go",
153-
Model: model,
154-
Version: strings.TrimSpace(cmd.Version),
155-
ResponseTime: math.Round(responseDuration.Seconds()*100) / 100,
156-
ExecutionTime: math.Round(executionDuration.Seconds()*100) / 100,
157-
}
158-
traceWrapper := TraceWrapper{Trace: trace}
159-
160-
traceJSON, err := json.Marshal(traceWrapper)
151+
trace, err := json.Marshal(TraceWrapper{
152+
Trace: Trace{
153+
Language: "go",
154+
Model: model,
155+
Version: strings.TrimSpace(cmd.Version),
156+
ResponseTime: math.Round(responseDuration.Seconds()*100) / 100,
157+
ExecutionTime: math.Round(executionDuration.Seconds()*100) / 100,
158+
},
159+
})
161160
if err != nil {
162161
return err
163162
}
164163

165-
commitMsg = fmt.Sprintf("%s\n---\n%s", commitMsg, traceJSON)
164+
commitMsg = fmt.Sprintf("%s\n---\n%s", commitMsg, trace)
166165
}
167166

168167
if commitMsgFile == "" {

0 commit comments

Comments
 (0)