Home > Mobile >  How does the GitLab API approve merge requests?
How does the GitLab API approve merge requests?

Time:11-16

I tried using POST /projects/xx/merge_requests/xx/approve requests. After requesting the request, returned "message": "401 Unauthorized",I also added the request header PRIVATE-TOKEN

CodePudding user response:

First, make sure (as documented in GitLab Merge Requests Approvals) that:

  • you have "Developer" or greater permissions to approve merge requests
  • the project does not have defined specific rules, like a list of users who act as code owners for specific files: only members of that list would have the right to approve a PR.
  • you have checked if the project require password to approve, which means you need to pass the approval_password parameter

Second, the curl call would be of the form (GitLab API)

curl -XPOST "https://gitlab.com/api/v4/projects/$CI_MERGE_REQUEST_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes" \
      -H "PRIVATE-TOKEN: $MR_TOKEN" \
      -H "Content-Type: application/x-www-form-urlencoded" \
      --data-urlencode 'sha=<sha>&approval_password=<password>'
                                  ^^^^^^^^^^^^^^^^^
                          (only if the project requires it)

With sha matching the current HEAD of the merge request for the approval to be added.

  • Related