Skip to content

fix: align CLI request fields with Forgejo API wire names - #32

Merged
simonnordberg merged 1 commit into
mainfrom
fix/api-field-alignment
Oct 13, 2026
Merged

simonnordberg merged 1 commit into
mainfrom
fix/api-field-alignment

Conversation

@simonnordberg

Copy link
Copy Markdown
Contributor

Summary

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 and silent data loss across ~12 CLI tools.

Request builder changes (client/client.go):

  • apiname struct tag: overrides the json tag as the body key, decoupling user-facing names from API wire names
  • body:"json" mode: unmarshals string fields into json.RawMessage so JSON-typed parameters arrive as objects
  • DELETE-with-body: Execute now sends a body for DELETE when body fields exist

Field fixes (24 issues across 12 tools):

  • 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, dispatch_workflow inputs: 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->int
  • remove_issue_labels: fixed routing from clear-all to per-label DELETE

Test plan

  • Unit tests for apiname, body:"json", DELETE-with-body in client/client_test.go
  • All existing tests pass (go test ./...)
  • Integration tested against codebahn.net: create_branch, create_file, merge (squash), create_pull_review, add/remove_issue_labels

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
@simonnordberg
simonnordberg merged commit eb1d6e3 into main Oct 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant