diff --git a/shortcuts/wiki/wiki.go b/shortcuts/wiki/wiki.go index 1ad8951..ad39fd6 100644 --- a/shortcuts/wiki/wiki.go +++ b/shortcuts/wiki/wiki.go @@ -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) { diff --git a/shortcuts/wiki/wiki_test.go b/shortcuts/wiki/wiki_test.go index c791c38..e635b26 100644 --- a/shortcuts/wiki/wiki_test.go +++ b/shortcuts/wiki/wiki_test.go @@ -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) {