Stefan
Stefan

Reputation: 3869

How do I get the merge request information in the pre-receive hook?

I need to catch the pushes and merges in GitLab on the server side and reject them if they do not have one of two labels.

To do this I intend using the API to check the merge request's details.

The pre-receive hook has the SHA1s of the file changes and the branch name but how do I get the project and merge request numbers so I can check the labels using the APIs?

Upvotes: 0

Views: 865

Answers (1)

LeGEC
LeGEC

Reputation: 52196

If you have the branch name, you can use Gitlab API to check if a Merge Request is linked to that branch :

GET /merge_requests?source_branch={branch_name}

Merge Requests API doc here : https://docs.gitlab.com/ee/api/merge_requests.html#list-merge-requests

You can then parse the response to get the other information you need (MR ID, current SHA ... )

Upvotes: 1

Related Questions