Skip to content

"Commands only ..." error when submitting comment with quick action through API (/approve, /merge)

Summary

When you submit a comment with /approve through the discussions API, you'll receive Commands only Approved the current merge request error.

Steps to reproduce

  1. Go to https://gitlab.com/-/graphql-explorer

  2. Submit the following query

    mutation{
      createNote(input: { noteableId: "gid://gitlab/MergeRequest/122735862", body: "/approve" }) {
        errors
        note {
          body
        }
      }
    }
  3. See the error

    {
      "data": {
        "createNote": {
          "errors": [
            "Commands only Approved the current merge request."
          ],
          "note": null
        }
      }
    }

Additional notes

You can get the MR id by running the following curl command:

curl -H "Authorization: Bearer $TOKEN" 'https://gitlab.com/api/v4/projects/20486274/merge_requests/13' | jq

I can't submit the comment with quick action through the REST API, but my guess would be that it's got the same issue. This is the request that fails for me:

curl -X POST -H "Authorization: Bearer $TOKEN" --form 'body=/approve'  'https://gitlab.com/api/v4/projects/20486274/merge_requests/13/discussions' | jq

Example Project

https://gitlab.com/viktomas/test-project

What is the current bug behavior?

The MR gets approved, but the API request fails.

What is the expected correct behavior?

The API request succeeds

Relevant logs and/or screenshots

Output of checks

This bug happens on GitLab.com