How to access source code files and list directories using GitLab API?

百般思念 提交于 2020-01-01 01:14:26

问题


I am using GitLab and I completed setup as described in Gitlab installation instructions, I am now trying to access its RestFul API to perform tasks like create/delete Projects or Users(I am able to do this successfully).

I now have to list out all the directories within the master branch (or any other branch the project has) and want to access source code files listed in those directories(e.g. myproject->master->api, src->somefile.java etc), is it possible to do something like that using the existing Gitlab's API?

The whole list of API's that can be called are mentioned here and I was looking into Project Snippets API and used this API GET /projects/:id/snippets to list all snippets but it returns an empty array, I do have files in my project but the result is empty.

I am assuming that project snippets refer to source code files or any other files within the project, please correct me if I am wrong, I am confused here as the authors of the Gitlab API failed to explain the terminology behind the usage of the word 'snippets'.

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


回答1:


I am assuming that project snippets refer to source code files or any other files within the project

No, you can see snippets in the GitLab demo project: diaspora snippets.
They are in a separate tabs than the "Files" tab.
They would be the equivalent of GitHub gist.

Have a look at the repository API, like:

List repository tree

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

GET /projects/:id/repository/tree

Raw blob content

Get the raw file contents for a file.

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

astratto mentions that the new API (6.x) requires that a filepath is appended:

GET /projects/:id/repository/blobs/:sha?filepath=:filepath


来源:https://stackoverflow.com/questions/17063630/how-to-access-source-code-files-and-list-directories-using-gitlab-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!