forked from Gitlink/gitlink-cli
fix: always include message field in wiki update request body
The gateway API requires the message field to be present (even as empty string). Previously update omitted it when --message was not provided, causing HTTP 500 errors. Also removed dead code in callWikiAPI and added a test for update without message. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
7a85c6df88
commit
7a82eef766
|
|
@ -125,11 +125,9 @@ func Shortcuts() []*common.Shortcut {
|
|||
"projectId": projectID,
|
||||
"pageName": name,
|
||||
"title": name,
|
||||
"message": ctx.Arg("message"),
|
||||
"content_base64": base64.StdEncoding.EncodeToString([]byte(content)),
|
||||
}
|
||||
if msg := ctx.Arg("message"); msg != "" {
|
||||
body["message"] = msg
|
||||
}
|
||||
return callWikiAPI(ctx, "POST", "/wiki/open/updateWiki", body, nil)
|
||||
},
|
||||
},
|
||||
|
|
@ -184,10 +182,6 @@ func callWikiAPI(ctx *common.RuntimeContext, method, path string, body interface
|
|||
return err
|
||||
}
|
||||
return ctx.Output(env)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Output(env)
|
||||
}
|
||||
|
||||
func fetchProjectID(ctx *common.RuntimeContext) (int, error) {
|
||||
|
|
|
|||
|
|
@ -142,6 +142,38 @@ func TestWikiUpdate(t *testing.T) {
|
|||
assertEqual(t, updatePayload["message"], "Update wiki page")
|
||||
}
|
||||
|
||||
func TestWikiUpdateWithoutMessage(t *testing.T) {
|
||||
var updatePayload map[string]interface{}
|
||||
server := newWikiTestServer(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case r.Method == "GET" && r.URL.Path == "/owner/repo.json":
|
||||
writeJSON(t, w, map[string]interface{}{
|
||||
"id": float64(1547460),
|
||||
"project_id": float64(1547460),
|
||||
})
|
||||
case r.Method == "POST" && r.URL.Path == "/wiki/open/updateWiki":
|
||||
updatePayload = decodeJSON(t, r)
|
||||
writeJSON(t, w, map[string]interface{}{
|
||||
"code": 200,
|
||||
})
|
||||
default:
|
||||
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
})
|
||||
defer server.Close()
|
||||
|
||||
if err := runWikiShortcut(t, server, "update", map[string]string{
|
||||
"name": "Home",
|
||||
"content": "Updated content",
|
||||
}); err != nil {
|
||||
t.Fatalf("update without message failed: %v", err)
|
||||
}
|
||||
|
||||
assertEqual(t, updatePayload["pageName"], "Home")
|
||||
// message field should be present as empty string, not omitted
|
||||
assertEqual(t, updatePayload["message"], "")
|
||||
}
|
||||
|
||||
// --- Delete ---
|
||||
|
||||
func TestWikiDelete(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue