Skip to content

Commit

Permalink
revert git.InitSimple(ctx), make internal request use "body" if it ex…
Browse files Browse the repository at this point in the history
…ists, omit empty response field
  • Loading branch information
wxiaoguang committed Mar 26, 2023
1 parent 66a0671 commit c9fd1bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func setup(ctx context.Context, debug bool) {
return
}

if err := git.InitSimple(ctx); err != nil {
if err := git.InitSimple(context.Background()); err != nil {
_ = fail(ctx, "Failed to init git", "Failed to init git, err: %v", err)
}
}
Expand Down
18 changes: 8 additions & 10 deletions modules/private/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (

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

func getClientIP() string {
Expand All @@ -34,7 +34,7 @@ func getClientIP() string {
return strings.Fields(sshConnEnv)[0]
}

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

if method == "POST" {
if len(body) == 1 {
req.Header("Content-Type", "application/json")
if len(postBody) == 1 {
jsonBytes, _ := json.Marshal(postBody[0])
req.Body(jsonBytes)
} else if len(postBody) > 1 {
log.Fatal("Too many arguments for newInternalRequest")
}
jsonBytes, _ := json.Marshal(body[0])
req.Body(jsonBytes)
} else if len(body) > 1 {
log.Fatal("Too many arguments for newInternalRequest")
}

req.SetTimeout(10*time.Second, 60*time.Second)
Expand Down

0 comments on commit c9fd1bb

Please sign in to comment.