从 GitLab 查询存储库文件内容
Query repository file contents from GitLab
我想通过 Invantive SQL 检索文件 readmeTest.txt
的提交 ID,如下所示:
select * from repository_files(29, file-path, 'master')
但要实现这一点,我需要 project-id
、file-path
和 ref
.
我知道我的 project-id
(我从 select * from projects
得到它)和我的 ref
(master
分支)但我不知道在哪里可以找到我要检索其信息的文件的路径。
那么我在哪里可以找到 file-path
和 ref
的值呢?
这是我的存储库目录树,我可以在其中看到存在的文件:
您需要在 GitLab 中加入多个实体才能获取您需要的信息。
您的 repository_files
table 函数中的字段及其含义:
project-id
可以在 projects
实体中找到 id
,如您所知;
ref-name
可以在 repositories
; 中找到 name
ref
是分支、标记或提交的名称,因此假设您现在需要 master
。
根据此信息,您需要以下查询来获取项目中的所有存储库文件及其内容(我现在将其缩小为单个项目):
select pjt.name project_name
, rpe.name repository_name
, rpf.content file
from projects pjt
join repositories(pjt.id) rpe
on 1=1
and rpe.name like '%.%'
join repository_files(pjt.id, rpe.name, 'master') rpf
on 1=1
where pjt.id = 1
我想通过 Invantive SQL 检索文件 readmeTest.txt
的提交 ID,如下所示:
select * from repository_files(29, file-path, 'master')
但要实现这一点,我需要 project-id
、file-path
和 ref
.
我知道我的 project-id
(我从 select * from projects
得到它)和我的 ref
(master
分支)但我不知道在哪里可以找到我要检索其信息的文件的路径。
那么我在哪里可以找到 file-path
和 ref
的值呢?
这是我的存储库目录树,我可以在其中看到存在的文件:
您需要在 GitLab 中加入多个实体才能获取您需要的信息。
您的 repository_files
table 函数中的字段及其含义:
project-id
可以在projects
实体中找到id
,如您所知;ref-name
可以在repositories
; 中找到 ref
是分支、标记或提交的名称,因此假设您现在需要master
。
name
根据此信息,您需要以下查询来获取项目中的所有存储库文件及其内容(我现在将其缩小为单个项目):
select pjt.name project_name
, rpe.name repository_name
, rpf.content file
from projects pjt
join repositories(pjt.id) rpe
on 1=1
and rpe.name like '%.%'
join repository_files(pjt.id, rpe.name, 'master') rpf
on 1=1
where pjt.id = 1