是否可以在文件内的GitLab中搜索代码或文本?我可以搜索文件,问题,里程碑等,但找不到搜索源文件中的代码或文档中的代码的方法,即.doc文件。
答案 0 :(得分:1)
答案 1 :(得分:1)
或者,您可以使用 python-gitlab 库在您需要的项目中搜索文本:
import gitlab
def search(gitlab_server, token, file_filter, text, group=None, project_filter=None):
return_value = []
gl = gitlab.Gitlab(gitlab_server, private_token=token)
if (project_filter == '') and (group == ''):
projects = gl.projects.list(all=True)
else:
group_object = gl.groups.get(group)
group_projects = group_object.projects.list(search=project_filter)
projects = []
for group_project in group_projects:
projects.append(gl.projects.get(group_project.id))
for project in projects:
files = []
try:
files = project.repository_tree(recursive=True, all=True)
except Exception as e:
print(str(e), "Error getting tree in project:", project.name)
for file in files:
if file_filter == file['name']:
file_content = project.files.raw(file_path=file['path'], ref='master')
if text in str(file_content):
return_value.append({
"project": project.name,
"file": file['path']
})
return return_value
可以在此处找到完整示例:gitlab-search
答案 2 :(得分:0)
要在 GitLab 上搜索文件,请点击 URL https://gitlab.com/search?utf8=%E2%9C%93&search_code=true&repository_ref={BranchName}
从下拉列表中选择相应的组和项目。
输入要搜索的文本并点击“搜索”按钮。