Home > Enterprise >  Git log - show merge request ID
Git log - show merge request ID

Time:10-14

How do I find the merge request ID based on the commit ID or the last merge request? I want to include merge request ID in the CURL request but I'm unable to find the ID using the git log command.

http://10.10.10.10/api/v4/projects/9/merge_requests/67/notes 

CodePudding user response:

You might need first to list merge requests, possibly filtering them by state, and take the first one (using jq: | jq '.[0]).
See List project merge requests:

GET /projects/:id/merge_requests?state=opened
curl --header "Private-Token: askljdhakjdlsa" "http://10.10.10.10/api/v4/projects/9/merge_requests?state=opened"

CodePudding user response:

Gitlab stores, next to branches and tags, extra merge-requests/... references that point at Merge Request commits. You can view these running git ls-remote :

$ git ls-remote origin
ed228a67a...    HEAD
7215f3432...    refs/heads/cache
4ed228a67...    refs/heads/master
...
d2cc93ae3...    refs/merge-requests/1023/head    # current commit for MR #1023
a888aabaf...    refs/merge-requests/1023/merge
...

You can pull these references to your local repo, for example by updating the refspec in your config (adapted from this gist) :

[remote "origin"]
    url = [email protected]:joyent/node.git
    fetch =  refs/heads/*:refs/remotes/origin/*
    fetch =  refs/merge-requests/*/head:refs/remotes/origin/mr/*   # <- add this line

then run git fetch.

You should now see origin/mr/{xxx} references in the output of git log, and use these names in other commands.

You can for example check if a commit is a pull request :

git for-each-ref refs/remotes/origin/mr --points-at <commit-ish>
  • Related