如何使用GitLab API访问源代码文件和列表目录? [英] How to access source code files and list directories using GitLab API?

查看:3640
本文介绍了如何使用GitLab API访问源代码文件和列表目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GitLab,并按照 Gitlab中所述完成设置安装说明,我现在试图访问它的RestFul API来执行像创建/删除项目或用户这样的任务(我可以成功地完成这项工作)。



我现在必须列出主分支(或任何其他分支项目)中的所有目录并且想要访问这些目录中列出的源代码文件(例如myproject-> master-> api,src-> somefile.java等等),是否有可能使用现有的Gitlab的API来做类似的事情?



可以调用的所有API的列表被提及这里,我正在研究 Project Snippets API 并使用此API GET / projects /:id / snippets 列出所有片段,但它会返回一个em pty数组,我在我的项目中有文件,但结果是空的。



我假设项目片段引用源代码文件或项目中的任何其他文件,如果我错了,请纠正我的错误,因为Gitlab API的作者未能解释snippets一词的用法背后的术语,所以我很困惑。

我可以访问完整的目录结构并获取需要使用API​​的文件吗?

解决方案


该项目片段引用源代码文件或项目中的任何其他文件


不,您可以在GitLab演示项目中看到片段: diaspora snippets

它们位于单独的标签中文件选项卡。

它们相当于 GitHub要点



查看存储库API ,例如:
$ b

列表存储库树




获取存储库文件和目录列表一个项目。



  GET / projects /:id / repository / tree 



原始Blob内容




获取文件的原始文件内容。




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

astratto 提及新的API(6.x)要求文件路径是附加:

$ $ p $ code> GET / projects /:id / repository / blobs /:sha?filepath =:filepath
code>


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?

解决方案

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

这篇关于如何使用GitLab API访问源代码文件和列表目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆