In my organization, we are using a free version of GitLab - I wanted to know If there is a way to export GitLab Merge requests + comments in a CSV file
Looking for help!!
In my organization, we are using a free version of GitLab - I wanted to know If there is a way to export GitLab Merge requests + comments in a CSV file
Looking for help!!
Since gitlab 13.6 you can export your merge-requests from the gui to a csv file.
In the left side bar of your project you need to select merge-requests and there you have the "Export as CSV" button which will send a cvs file containing all merge-requests to your configured email address.
For lower gitlab versions you can take a look at the merge-requests api and try something like this
GET /merge_requests?scope=all
The previous answers work for single projects, but I wanted to export all of my MRs across my org's GitLab instance.
I asked ChatGPT-4 to do this for me, and I used it successfully, it worked perfectly the first time. I hope this answer is acceptable because I fully tested it; I also had to augment it to use an environment variable with my token, vs its original suggestion of hardcoding it.
It's in python:
import requests
import csv
import json
import os
# Set your GitLab instance URL, Personal Access Token, and username
gitlab_url = "https://gitlab.myorg.com"
token = os.environ["MY_GITLAB_TOKEN"]
username = "your username"
# Set the API endpoint to get MRs
api_url = f"{gitlab_url}/api/v4/merge_requests?scope=all&state=all&author_username={username}&per_page=100"
# Add your Personal Access Token to the request headers
headers = {"Private-Token": token}
# Send the API request and get the response
response = requests.get(api_url, headers=headers)
merge_requests = response.json()
# Write the Merge Requests to a CSV file
with open("merge_requests.csv", mode="w", newline="", encoding="utf-8") as csvfile:
fieldnames = ["id", "title", "state", "created_at", "updated_at", "web_url"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for mr in merge_requests:
writer.writerow({k: mr[k] for k in fieldnames})
This creates a file called merge_requests.csv
in the directory you run the script in. I didn't try, but you could most likely play with the fieldnames to get exactly the data you want.