Is it possible to search for code or text in GitLab inside of files? I can search for files, issues, milestones, etc., but could not find a way to search for code in source files or text in the documentation i.e .doc files.
GitLab has two types of searches available: basic and advanced. Both types of search are the same, except when you are searching through code.
GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more. Self-host GitLab on your own servers, in a container, or on a cloud provider.
It was announced in 5.2:
https://about.gitlab.com/2013/05/22/gitlab-5-dot-2-released/
And I can confirm code search is working with 8.4
Alternatively you can use the python-gitlab library to search text in the projects that you need:
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
Complete example can be found here: gitlab-search
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With