Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for code or text in GitLab

Tags:

search

gitlab

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.

like image 999
Viktor Avatar asked Jan 29 '16 15:01

Viktor


People also ask

Can you search code in GitLab?

GitLab has two types of searches available: basic and advanced. Both types of search are the same, except when you are searching through code.

What is GitLab 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.


2 Answers

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

like image 117
Jérôme Avatar answered Sep 21 '22 14:09

Jérôme


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

like image 23
Rubén Pozo Avatar answered Sep 18 '22 14:09

Rubén Pozo