.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
gitea.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 Gitea_ or Forgejo_.
3
4.. _Gitea: https://about.gitea.com/
5.. _Forgejo: https://forgejo.org/
6
7Configuration
8=============
9
10The engine has the following mandatory setting:
11
12- :py:obj:`base_url`
13
14Optional settings are:
15
16- :py:obj:`sort`
17- :py:obj:`order`
18- :py:obj:`page_size`
19
20.. code:: yaml
21
22 - name: gitea.com
23 engine: gitea
24 base_url: https://gitea.com
25 shortcut: gitea
26
27 - name: forgejo.com
28 engine: gitea
29 base_url: https://code.forgejo.org
30 shortcut: forgejo
31
32If you would like to use additional instances, just configure new engines in the
33:ref:`settings <settings engine>` and set the ``base_url``.
34
35
36Implementation
37==============
38
39"""
40
41from urllib.parse import urlencode
42from dateutil import parser
43
44about = {
45 "website": 'https://about.gitea.com',
46 "wikidata_id": None,
47 "official_api_documentation": 'https://docs.gitea.com/next/development/api-usage',
48 "use_official_api": True,
49 "require_api_key": False,
50 "results": 'JSON',
51}
52
53categories = ['it', 'repos']
54paging = True
55
56base_url: str = ''
57"""URL of the Gitea_ instance."""
58
59sort: str = "updated"
60"""Sort criteria, possible values:
61
62- ``updated`` (default)
63- ``alpha``
64- ``created``
65- ``size``
66- ``id``
67"""
68
69order = "desc"
70"""Sort order, possible values:
71
72- ``desc`` (default)
73- ``asc``
74"""
75
76page_size: int = 10
77"""Maximum number of results per page (default 10)."""
78
79
80def init(_):
81 if not base_url:
82 raise ValueError('gitea engine: base_url is unset')
83
84
85def request(query, params):
86 args = {'q': query, 'limit': page_size, 'sort': sort, 'order': order, 'page': params['pageno']}
87 params['url'] = f"{base_url}/api/v1/repos/search?{urlencode(args)}"
88
89 return params
90
91
92def response(resp):
93 results = []
94
95 for item in resp.json().get('data', []):
96 content = [item.get(i) for i in ['language', 'description'] if item.get(i)]
97
98 results.append(
99 {
100 'template': 'packages.html',
101 'url': item.get('html_url'),
102 'title': item.get('full_name'),
103 'content': ' / '.join(content),
104 # Use Repository Avatar and fall back to Owner Avatar if not set.
105 'thumbnail': item.get('avatar_url') or item.get('owner', {}).get('avatar_url'),
106 'package_name': item.get('name'),
107 'maintainer': item.get('owner', {}).get('username'),
108 'publishedDate': parser.parse(item.get("updated_at") or item.get("created_at")),
109 'tags': item.get('topics', []),
110 'popularity': item.get('stars_count'),
111 'homepage': item.get('website'),
112 'source_code_url': item.get('clone_url'),
113 }
114 )
115
116 return results
request(query, params)
Definition gitea.py:85