diff --git a/docs/dev/engines/online/gitlab.rst b/docs/dev/engines/online/gitlab.rst new file mode 100644 index 000000000..5f0d3e3d1 --- /dev/null +++ b/docs/dev/engines/online/gitlab.rst @@ -0,0 +1,8 @@ +.. _gitlab engine: + +====== +GitLab +====== + +.. automodule:: searx.engines.gitlab + :members: diff --git a/searx/engines/gitlab.py b/searx/engines/gitlab.py new file mode 100644 index 000000000..b5ab7df2a --- /dev/null +++ b/searx/engines/gitlab.py @@ -0,0 +1,95 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Engine to search in collaborative software platforms based on GitLab_ with +the `GitLab REST API`_. + +.. _GitLab: https://about.gitlab.com/install/ +.. _GitLab REST API: https://docs.gitlab.com/ee/api/ + +Configuration +============= + +The engine has the following mandatory setting: + +- :py:obj:`base_url` + +Optional settings are: + +- :py:obj:`api_path` + +.. code:: yaml + + - name: gitlab + engine: gitlab + base_url: https://gitlab.com + shortcut: gl + about: + website: https://gitlab.com/ + wikidata_id: Q16639197 + + - name: gnome + engine: gitlab + base_url: https://gitlab.gnome.org + shortcut: gn + about: + website: https://gitlab.gnome.org + wikidata_id: Q44316 + +Implementations +=============== + +""" + +from urllib.parse import urlencode +from dateutil import parser + +about = { + "website": None, + "wikidata_id": None, + "official_api_documentation": "https://docs.gitlab.com/ee/api/", + "use_official_api": True, + "require_api_key": False, + "results": "JSON", +} + +categories = ['it', 'repos'] +paging = True + +base_url: str = "" +"""Base URL of the GitLab host.""" + +api_path: str = 'api/v4/projects' +"""The path the `project API `_. + +The default path should work fine usually. +""" + + +def request(query, params): + args = {'search': query, 'page': params['pageno']} + params['url'] = f"{base_url}/{api_path}?{urlencode(args)}" + + return params + + +def response(resp): + results = [] + + for item in resp.json(): + results.append( + { + 'template': 'packages.html', + 'url': item.get('web_url'), + 'title': item.get('name'), + 'content': item.get('description'), + 'thumbnail': item.get('avatar_url'), + 'package_name': item.get('name'), + 'maintainer': item.get('namespace', {}).get('name'), + 'publishedDate': parser.parse(item.get('last_activity_at') or item.get("created_at")), + 'tags': item.get('tag_list', []), + 'popularity': item.get('star_count'), + 'homepage': item.get('readme_url'), + 'source_code_url': item.get('http_url_to_repo'), + } + ) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 4417485bc..2e18baaff 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -807,24 +807,21 @@ engines: timeout: 10 - name: gitlab - engine: json_engine - paging: true - search_url: https://gitlab.com/api/v4/projects?search={query}&page={pageno} - url_query: web_url - title_query: name_with_namespace - content_query: description - page_size: 20 - categories: [it, repos] + engine: gitlab + base_url: https://gitlab.com shortcut: gl - timeout: 10.0 disabled: true about: - website: https://about.gitlab.com/ + website: https://gitlab.com/ wikidata_id: Q16639197 - official_api_documentation: https://docs.gitlab.com/ee/api/ - use_official_api: false - require_api_key: false - results: JSON + + # - name: gnome + # engine: gitlab + # base_url: https://gitlab.gnome.org + # shortcut: gn + # about: + # website: https://gitlab.gnome.org + # wikidata_id: Q44316 - name: github engine: github