Generate list of all Merge Requests merged between two tags with all informations in csv file

Viewed 667

I'm trying to do a csv file with all informations about merge requests merged between two tags. I'm trying to get this kind of information for each merge request:

UID; ID; TITLE OF MR; REPOSITORIES; STATUS; MILESTONE; ASSIGNED; CREATION-DATE; MERGED-DATE; LABEL; URL.

For now I have a command that get all merge requests merged between two tags with some informations and put it in csv file:

git log --merges --first-parent master --pretty=format:"%aD;%an;%H;%s;%b" TagA..TagB --shortstat >> MRList.csv

How can I get the other informations? I saw in the git log api only options in my command but I can't find others.

Thank you for your help !

2 Answers

I've written a small Python script to do this. Usage:

git log --pretty="format:%H" <start>..<end> | python collect.py

Script:

#!/usr/bin/env python

import sys
import requests

endpoint = 'https://gitlab.com'
project_id = '4242'

mrs = set()
for line in sys.stdin:
    hash = line.rstrip('\n')
    r = requests.get(endpoint + '/api/v4/projects/' + project_id + '/repository/commits/' + hash + '/merge_requests')
    for mr in r.json():
        if mr['id'] in mrs:
            continue
        mrs.add(mr['id'])

        print('!{} {} ({})'.format(mr['iid'], mr['title'], mr['web_url']))

For now, this is not yet between two tags, but you have, with GitLab 13.6 (November 2020):

Export merge requests as a CSV

Many organizations are required to document changes (merge requests) and the data surrounding those transactions such as who authored the MR, who approved it, and when that change was merged into production. Although not an exhaustive list, it highlights the recurring theme of traceability and the need to export this data from GitLab to serve an audit or other regulatory requirement.

Previously, you would need to use GitLab’s merge requests API to compile this data using custom tooling. Now, you can click one button and receive a CSV file that contains the necessary chain of custody information you need.

https://about.gitlab.com/images/13_6/export_mr_csv.png -- Export merge requests as a CSV

See Documentation and Issue.

Related