Is there a way to get a list of files and directories in the gitlab repo using python? So if I use the gitlab repository url as my source, can I traverse and get a list of all files and directories/ sub-directories within the repo? Like using os.walk
but for a web url.
Asked
Active
Viewed 1,311 times
0

py_noob
- 433
- 2
- 8
- 17
-
This above use case would be for hundreds of repositories so using something like subprocess is out of the question. – py_noob Feb 21 '20 at 19:53
1 Answers
1
Can you try python-gitlab?
Use repository_tree
method can do it for you.
Here is the code
import gitlab
gl = gitlab.Gitlab.from_config()
# Get a project by ID
project_id = 851
project = gl.projects.get(project_id)
branch = {your branch}
directory = {your directory ref to root directory of the repository}
project.repository_tree(direcotry, ref=branch)
For more details, please visit python-gitlab

findmyway
- 66
- 4