Skip to content

Commit c9fd1bb

Browse files
committed
revert git.InitSimple(ctx), make internal request use "body" if it exists, omit empty response field
1 parent 66a0671 commit c9fd1bb

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

cmd/serv.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func setup(ctx context.Context, debug bool) {
7979
return
8080
}
8181

82-
if err := git.InitSimple(ctx); err != nil {
82+
if err := git.InitSimple(context.Background()); err != nil {
8383
_ = fail(ctx, "Failed to init git", "Failed to init git, err: %v", err)
8484
}
8585
}

modules/private/internal.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222

2323
// Response is used for internal request response (for user message and error message)
2424
type Response struct {
25-
Err string `json:"err"` // server-side error log message, it won't be exposed to end users
26-
UserMsg string `json:"user_msg"` // meaningful error message for end users, it will be shown in git client's output.
25+
Err string `json:"err,omitempty"` // server-side error log message, it won't be exposed to end users
26+
UserMsg string `json:"user_msg,omitempty"` // meaningful error message for end users, it will be shown in git client's output.
2727
}
2828

2929
func getClientIP() string {
@@ -34,7 +34,7 @@ func getClientIP() string {
3434
return strings.Fields(sshConnEnv)[0]
3535
}
3636

37-
func newInternalRequest(ctx context.Context, url, method string, postBody ...any) *httplib.Request {
37+
func newInternalRequest(ctx context.Context, url, method string, body ...any) *httplib.Request {
3838
if setting.InternalToken == "" {
3939
log.Fatal(`The INTERNAL_TOKEN setting is missing from the configuration file: %q.
4040
Ensure you are running in the correct environment or set the correct configuration file with -c.`, setting.CustomConf)
@@ -83,14 +83,12 @@ Ensure you are running in the correct environment or set the correct configurati
8383
})
8484
}
8585

86-
if method == "POST" {
86+
if len(body) == 1 {
8787
req.Header("Content-Type", "application/json")
88-
if len(postBody) == 1 {
89-
jsonBytes, _ := json.Marshal(postBody[0])
90-
req.Body(jsonBytes)
91-
} else if len(postBody) > 1 {
92-
log.Fatal("Too many arguments for newInternalRequest")
93-
}
88+
jsonBytes, _ := json.Marshal(body[0])
89+
req.Body(jsonBytes)
90+
} else if len(body) > 1 {
91+
log.Fatal("Too many arguments for newInternalRequest")
9492
}
9593

9694
req.SetTimeout(10*time.Second, 60*time.Second)

0 commit comments

Comments
 (0)