Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitLab API - How to GET the repository/project files and metadata?

I am new to GitLab and using API calls and am confused on how to make a call to get the repository/project files and metadata. My current API call is as follows:

https://gitlab.com/api/v3/projects?private_token=privateToken

privateToken at the end of the line above is replaced with my private token which I have taken out for obvious security reasons.

This will return to me the json that describes all of the projects I have, but I want to drill down deeper and see the specific information about the files that are stored within each project/repository. On the GitLab API documentation website, it lists this:

GET /projects/:id/repository/files/:file_path

However, since I am new to GitLab and API calls in general I am confused as to how to edit my first link to retrieve this information.

Ideally, I would like to be able to drill down to the project/repository files and metadata within python and not have to edit the first link above, but I am not sure if that is possible. How does GitLab return the json? As a hash table of hash tables, if so, how do I navigate through it?

Any clarification on how to parse through the json and drilling deeper within it would be greatly appreciated!

I am using Python 3.6.1.

Thanks!

like image 727
Doug Andres Avatar asked Jun 23 '17 22:06

Doug Andres


People also ask

Is project and repository same in GitLab?

In GitHub, repositories contain the Git/SVN repository, and the project assets such as issues, contribution metrics, etc. However users often refer to repos as projects interchangeably. So in GitLab, we call that container a Project. That includes the Git repository, issues, merge requests, milestones, and much more.


1 Answers

Python solution Very useful information about gitlab api.

python-gitlab.readthedocs.io

import gitlab
# private token or personal token authentication
gl = gitlab.Gitlab('https://gitlab.company.be', private_token='dklsfjksldjfkdsjf', api_version=4)
gl.auth()

project = gl.projects.get('path/to/project')
items = project.repository_tree()

print(items)
like image 125
Shwans Avatar answered Sep 19 '22 23:09

Shwans