fix: parse approve/unapprove response with correct schema#368
Open
millerchou wants to merge 1 commit intozereight:mainfrom
Open
fix: parse approve/unapprove response with correct schema#368millerchou wants to merge 1 commit intozereight:mainfrom
millerchou wants to merge 1 commit intozereight:mainfrom
Conversation
The POST /approve and POST /unapprove endpoints return the approvals
format where approved_by contains nested { user: {...} } objects.
However, approveMergeRequest() and unapproveMergeRequest() were
parsing the response directly with GitLabMergeRequestApprovalStateSchema,
which expects flat user objects in approved_by.
This worked before v2.0.32 because the schema didn't include
approved_by field. After bfc49de added approved_by to the schema,
Zod validation fails because it finds { user: { username, ... } }
instead of { username, ... } at the array item level.
Fix by extracting a shared parseApprovalsResponse() that correctly
parses the nested format and converts to the flat format, consistent
with getMergeRequestApprovalsFallback().
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.
Problem
approve_merge_requestandunapprove_merge_requestfail with:Root Cause
The GitLab
POST /approveandPOST /unapproveendpoints return the approvals format whereapproved_bycontains nested objects:{ "approved_by": [{ "user": { "username": "X", "name": "Y", ... } }] }But
approveMergeRequest()andunapproveMergeRequest()parse the response withGitLabMergeRequestApprovalStateSchema, which expects flat user objects:{ "approved_by": [{ "username": "X", "name": "Y", ... }] }This worked before because the schema didn't include
approved_by. After bfc49de addedapproved_byto the schema, Zod validation fails on the nested structure.Fix
Extract a shared
parseApprovalsResponse()helper that:GitLabMergeRequestApprovalsResponseSchema(correct nested format){ user: {...} }to{...}GitLabMergeRequestApprovalStateformatThis is the same conversion that
getMergeRequestApprovalsFallback()already does correctly — the fix reuses it forapproveMergeRequest(),unapproveMergeRequest(), and the fallback itself.Changes
index.ts: 3 call sites updated, 1 new helper function, net +13/-5 lines