1
votes

I can't seem to find how the repository size for a merge request can be acquired using the GitLab API. Here is the GitLab Merge Request API page: https://docs.gitlab.com/ee/api/merge_requests.html

I can see that to get the repository size for a project is available through the Projects API https://docs.gitlab.com/ee/api/projects.html, but don't see how it can be applied to a branch or merge request.

(I would also like to know the access level of the user that made the merge request, but unless I am mistaken, access level information is available to admins of the repo only?)

Thanks

1

1 Answers

1
votes

There isn't an API for that because the "project size" isn't the size of the files tracked in the main or master branch, but rather the total size of the project including tracked files, the ENTIRE git history (everything in the .git directory), etc. So for example, if you were to download 5k images from FontAwesome and commit them to your git repo then remove them later, your projects size would still reflect them since they’re in the git history. You can see this reflected on the Project Overview page for your project. Under the project name you'll see things like the number of commits, branches, tags, and then two attributes called Files and Storage. The Files value is the raw file size of the individual files tracked by git for your main/master branch. Storage is the total size of the project including git history, commit messages, etc.

To get the size of the files in any branch, you can:

#1: check out that branch
git checkout my_feature_branch

# get the file size
du -sh $(pwd)

The du command (for disk usage) shows you the disk usage of the given file or directory and each subdirectory, in bytes. The -s flag tells du to only show the total disk usage for the (s)pecified directory. The -h flag tells du to give the result in a (h)uman readable format (KB, MB, GB, TB, etc. instead of bytes).