How to access source code files and directory listing using GitLab API?

I use GitLab, and I completed the setup as described in the Gitlab Installation Instructions , now I am trying to access its RestFul API to perform tasks such as creating / deleting projects or users (I can do this successfully).

Now I have to list all the directories in the main branch (or any other branch the project has), and want to access the source files listed in these directories (for example, myproject-> master-> api, src-> somefile.java etc.), is it possible to do something similar using the existing Gitlab API?

The entire list of APIs that can be called is mentioned here , and I searched for the API projects API and used this API GET /projects/:id/snippets to display all fragments, but it returns an empty array, I have files in my project, but the result is empty.

I assume that the project fragments refer to source code files or to any other files in the project, please correct me, if I am mistaken, I am confused here, because the authors of the Gitlab API could not explain the terminology underlying the use of the word "fragments".

How can I access the full directory structure and get the files I need using the API?

+4
source share
1 answer

I assume that project fragments refer to source code files or to any other files within the project

No, you can see fragments in the GitLab demo project: fragments of the diaspora .
They are on separate tabs than the Files tab.
They would be equivalent to a github gist .

Check out the repository API , for example:

Repository Tree List

Get a list of files and directories of the repository in the project.

 GET /projects/:id/repository/tree 

Raw Blob Content

Get the original file contents for the file.

 GET /projects/:id/repository/commits/:sha/blob 

astratto mentions that the new API (6.x) requires the addition of a file file

 GET /projects/:id/repository/blobs/:sha?filepath=:filepath 
+4
source

Source: https://habr.com/ru/post/1485782/


All Articles