[IMP] runbot_merge: style fixes

- replace manual token_urlsafe by actual token_urlsafe
- make conditional right side up and more readable
- replace match by fullmatch, should not change anything since we end
  with a greedy universal match but is slightly more explicit
This commit is contained in:
Xavier Morel 2024-10-22 10:51:47 +02:00
parent d9e6d39448
commit ed1f084c4f

View File

@ -1,10 +1,8 @@
from __future__ import annotations
import base64
import contextlib
import logging
import os
import re
import secrets
from collections import defaultdict
from collections.abc import Iterator
@ -323,9 +321,7 @@ class Batch(models.Model):
new_branch = '%s-%s-%s-fw' % (
target.name,
base.refname,
# avoid collisions between fp branches (labels can be reused
# or conflict especially as we're chopping off the owner)
base64.urlsafe_b64encode(os.urandom(3)).decode()
secrets.token_urlsafe(3),
)
conflicts = {}
for pr in prs:
@ -352,11 +348,11 @@ class Batch(models.Model):
for p in root | source
)
title, body = re.match(r'(?P<title>[^\n]+)\n*(?P<body>.*)', message, flags=re.DOTALL).groups()
title, body = re.fullmatch(r'(?P<title>[^\n]+)\n*(?P<body>.*)', message, flags=re.DOTALL).groups()
r = gh.post(f'https://api.github.com/repos/{pr.repository.name}/pulls', json={
'base': target.name,
'head': f'{owner}:{new_branch}',
'title': '[FW]' + (' ' if title[0] != '[' else '') + title,
'title': '[FW]' + ('' if title[0] == '[' else ' ') + title,
'body': body
})
if not r.ok: