Repository navigation
fix: align CLI request fields with Forgejo API wire names - #32
Merged
Merged
Conversation
The generic buildBody function used json struct tags as API body keys, but several Forgejo endpoints expect different wire names than the user-facing parameter names. This caused 422 errors (e.g. merge_pull_request sending "style" instead of "Do") and silent data loss (fields sent under unrecognized keys). Changes to the request builder (client/client.go): - Add apiname struct tag: when present, buildBody uses it as the body key instead of the json tag. This decouples the user-facing parameter name from the API wire name. - Add body:"json" mode: unmarshals a string field into json.RawMessage before embedding, so JSON-typed parameters (workflow inputs, review comments) arrive as objects instead of quoted strings. - Send body on DELETE when body fields exist: Execute previously sent no body for DELETE methods. Tools like delete_review_requests need a body to specify which reviewers to remove. Field fixes across tool structs: - merge_pull_request: style->Do, title->MergeTitleField, message->MergeMessageField - create_branch: branch->new_branch_name, old_branch->old_branch_name - create/update/delete_file: branch_name->branch, new_branch_name->new_branch - create_pull_review, submit_pull_review: state->event - create_pull_review comments: string->JSON array (body:"json") - dispatch_workflow inputs: string->JSON object (body:"json") - create/delete_review_requests: reviewers, team_reviewers now body:"csv" - add_issue_labels: labels now body:"csv" - update_issue: assignees now body:"csv", milestone changed from string to int - remove_issue_labels: fixed routing from clear-all to per-label DELETE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The generic
buildBodyfunction usedjsonstruct tags as API body keys, but several Forgejo endpoints expect different wire names than the user-facing parameter names. This caused 422 errors and silent data loss across ~12 CLI tools.Request builder changes (
client/client.go):apinamestruct tag: overrides the json tag as the body key, decoupling user-facing names from API wire namesbody:"json"mode: unmarshals string fields intojson.RawMessageso JSON-typed parameters arrive as objectsExecutenow sends a body for DELETE when body fields existField fixes (24 issues across 12 tools):
merge_pull_request: style->Do, title->MergeTitleField, message->MergeMessageFieldcreate_branch: branch->new_branch_name, old_branch->old_branch_namecreate/update/delete_file: branch_name->branch, new_branch_name->new_branchcreate_pull_review,submit_pull_review: state->eventcreate_pull_reviewcomments,dispatch_workflowinputs: string->JSON (body:"json")create/delete_review_requests: reviewers, team_reviewers now body:"csv"add_issue_labels: labels now body:"csv"update_issue: assignees now body:"csv", milestone string->intremove_issue_labels: fixed routing from clear-all to per-label DELETETest plan
apiname,body:"json", DELETE-with-body inclient/client_test.gogo test ./...)