Skip to content

Commit 583cfa8

Browse files
committed
patchwork: allow setting user-agent from config
Konstantin suggests using "kdevops-ci/{version} ([email protected])" for "good bots". Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7be90b2 commit 583cfa8

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

mailbot.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
auto_changes_requested = set()
3333
auto_awaiting_upstream = set()
3434
delay_actions = [] # contains tuples of (datetime, email)
35+
http_headers = None
3536

3637

3738
pw_act_active = {
@@ -189,7 +190,8 @@ def load_section(self, location, name):
189190

190191
self.loc_map[name] = location
191192

192-
r = requests.get(f'https://www.kernel.org/doc/html/next/{location}.html')
193+
r = requests.get(f'https://www.kernel.org/doc/html/next/{location}.html',
194+
headers=http_headers)
193195
data = r.content.decode('utf-8')
194196

195197
offs = 0
@@ -208,7 +210,7 @@ def load_section(self, location, name):
208210

209211
# Now populate the plain text contents
210212
url = f'https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/plain/Documentation/{location}.rst'
211-
r = requests.get(url)
213+
r = requests.get(url, headers=http_headers)
212214
data = r.content.decode('utf-8')
213215
lines = data.split('\n')
214216

@@ -379,7 +381,8 @@ def _resolve_thread(self, pw):
379381

380382
self._series_id = pw_obj[0]['series'][0]['id']
381383

382-
r = requests.get(f'https://lore.kernel.org/all/{mid}/raw')
384+
r = requests.get(f'https://lore.kernel.org/all/{mid}/raw',
385+
headers=http_headers)
383386
data = r.content.decode('utf-8')
384387
msg = email.message_from_string(data, policy=default)
385388
self._series_author = msg.get('From')
@@ -709,6 +712,11 @@ def main():
709712
signal.signal(signal.SIGTERM, handler)
710713
signal.signal(signal.SIGINT, handler)
711714

715+
global http_headers
716+
ua = config.get('patchwork', 'user-agent', fallback='')
717+
if ua:
718+
http_headers = {"user-agent":ua}
719+
712720
global authorized_users
713721
users = config.get('mailbot', 'authorized')
714722
authorized_users.update(set(users.split(',')))

pw/patchwork.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def __init__(self, config):
4242
self._token = config.get('patchwork', 'token', fallback='')
4343
self._user = config.get('patchwork', 'user', fallback='')
4444

45+
ua = config.get('patchwork', 'user-agent', fallback='')
46+
if ua:
47+
self._session.headers.update({"user-agent":ua})
48+
4549
config_project = config.get('patchwork', 'project')
4650
pw_project = self.get_project(config_project)
4751
if pw_project:

0 commit comments

Comments
 (0)