.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
gitlab.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Engine to search in collaborative software platforms based on GitLab_ with
3the `GitLab REST API`_.
4
5.. _GitLab: https://about.gitlab.com/install/
6.. _GitLab REST API: https://docs.gitlab.com/ee/api/
7
8Configuration
9=============
10
11The engine has the following mandatory setting:
12
13- :py:obj:`base_url`
14
15Optional settings are:
16
17- :py:obj:`api_path`
18
19.. code:: yaml
20
21 - name: gitlab
22 engine: gitlab
23 base_url: https://gitlab.com
24 shortcut: gl
25 about:
26 website: https://gitlab.com/
27 wikidata_id: Q16639197
28
29 - name: gnome
30 engine: gitlab
31 base_url: https://gitlab.gnome.org
32 shortcut: gn
33 about:
34 website: https://gitlab.gnome.org
35 wikidata_id: Q44316
36
37Implementations
38===============
39
40"""
41
42from urllib.parse import urlencode
43from dateutil import parser
44
45about = {
46 "website": None,
47 "wikidata_id": None,
48 "official_api_documentation": "https://docs.gitlab.com/ee/api/",
49 "use_official_api": True,
50 "require_api_key": False,
51 "results": "JSON",
52}
53
54categories = ['it', 'repos']
55paging = True
56
57base_url: str = ""
58"""Base URL of the GitLab host."""
59
60api_path: str = 'api/v4/projects'
61"""The path the `project API <https://docs.gitlab.com/ee/api/projects.html>`_.
62
63The default path should work fine usually.
64"""
65
66
67def request(query, params):
68 args = {'search': query, 'page': params['pageno']}
69 params['url'] = f"{base_url}/{api_path}?{urlencode(args)}"
70
71 return params
72
73
74def response(resp):
75 results = []
76
77 for item in resp.json():
78 results.append(
79 {
80 'template': 'packages.html',
81 'url': item.get('web_url'),
82 'title': item.get('name'),
83 'content': item.get('description'),
84 'thumbnail': item.get('avatar_url'),
85 'package_name': item.get('name'),
86 'maintainer': item.get('namespace', {}).get('name'),
87 'publishedDate': parser.parse(item.get('last_activity_at') or item.get("created_at")),
88 'tags': item.get('tag_list', []),
89 'popularity': item.get('star_count'),
90 'homepage': item.get('readme_url'),
91 'source_code_url': item.get('http_url_to_repo'),
92 }
93 )
94
95 return results
request(query, params)
Definition gitlab.py:67