From 036ae3a8eee57f81984890a1767d7bea7b18e426 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 10 Oct 2019 11:36:14 +0200 Subject: [PATCH] [IMP] forwardbot: reduce length of fw branch name * shorten the postfix, forwardbot is now a bigram! * shorten the uniquifier: go from 5 to 3 bytes, and use urlsafe base64 that way we only have a 4-char uniquifier instead of 8 * while at it, fix deprecated calls to logging.warn (should be logging.warning) Fixes #226 --- forwardport/models/forwardport.py | 2 +- forwardport/models/project.py | 10 +++++----- forwardport/tests/utils.py | 4 ++-- runbot_merge/github.py | 2 +- runbot_merge/models/pull_requests.py | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/forwardport/models/forwardport.py b/forwardport/models/forwardport.py index b6a7f8b3..e908dafc 100644 --- a/forwardport/models/forwardport.py +++ b/forwardport/models/forwardport.py @@ -39,7 +39,7 @@ class BatchQueue(models.Model, Queue): # only some prs of the batch have a parent, that's weird with_parent = batch.prs.filtered(lambda p: p.parent_id) if with_parent and with_parent != batch.prs: - _logger.warn("Found a subset of batch %s (%s) with parents: %s, should probably investigate (normally either they're all parented or none are)", batch, batch.prs, with_parent) + _logger.warning("Found a subset of batch %s (%s) with parents: %s, should probably investigate (normally either they're all parented or none are)", batch, batch.prs, with_parent) newbatch = batch.prs._port_forward() if newbatch: diff --git a/forwardport/models/project.py b/forwardport/models/project.py index cf3f0c20..7f7dba84 100644 --- a/forwardport/models/project.py +++ b/forwardport/models/project.py @@ -66,7 +66,7 @@ class Project(models.Model): 'Authorization': 'token %s' % project.fp_github_token }) if not (r0.ok and r1.ok): - _logger.warn("Failed to fetch bot information for project %s: %s", project.name, (r0.text or r0.content) if not r0.ok else (r1.text or r1.content)) + _logger.warning("Failed to fetch bot information for project %s: %s", project.name, (r0.text or r0.content) if not r0.ok else (r1.text or r1.content)) continue project.fp_github_name = r0.json()['login'] project.fp_github_email = next(( @@ -424,7 +424,7 @@ class PullRequests(models.Model): proj = self.mapped('target.project_id') if not proj.fp_github_token: - _logger.warn( + _logger.warning( "Can not forward-port %s#%s: no token on project %s", ref.repository.name, ref.number, proj.name @@ -433,19 +433,19 @@ class PullRequests(models.Model): notarget = [p.repository.name for p in self if not p.repository.fp_remote_target] if notarget: - _logger.warn( + _logger.warning( "Can not forward-port %s: repos %s don't have a remote configured", self, ', '.join(notarget) ) return # take only the branch bit - new_branch = '%s-%s-%s-forwardport' % ( + 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.b32encode(os.urandom(5)).decode() + base64.urlsafe_b64encode(os.urandom(3)).decode() ) # TODO: send outputs to logging? conflicts = {} diff --git a/forwardport/tests/utils.py b/forwardport/tests/utils.py index fbe527e2..5da2c2d3 100644 --- a/forwardport/tests/utils.py +++ b/forwardport/tests/utils.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -# target branch '-' source branch '-' base32 unique '-forwardport' import itertools import re @@ -8,7 +7,8 @@ MESSAGE_TEMPLATE = """{message} closes {repo}#{number} {headers}Signed-off-by: {name} <{login}@users.noreply.github.com>""" -REF_PATTERN = r'{target}-{source}-\w{{8}}-forwardport' +# target branch '-' source branch '-' base64 unique '-fw' +REF_PATTERN = r'{target}-{source}-[a-zA-Z0-9_-]{{4}}-fw' class Commit: def __init__(self, message, *, author=None, committer=None, tree, reset=False): diff --git a/runbot_merge/github.py b/runbot_merge/github.py index d22fbd6f..0a073233 100644 --- a/runbot_merge/github.py +++ b/runbot_merge/github.py @@ -89,7 +89,7 @@ class GH(object): if _is_json(r.response): body = r.response.json() if any(e.message == 'User is blocked' for e in (body.get('errors') or [])): - _logger.warn("comment(%s:%s) failed: user likely blocked", self._repo, pr) + _logger.warning("comment(%s:%s) failed: user likely blocked", self._repo, pr) return raise _logger.debug('comment(%s, %s, %s)', self._repo, pr, shorten(message)) diff --git a/runbot_merge/models/pull_requests.py b/runbot_merge/models/pull_requests.py index b3994924..6c151588 100644 --- a/runbot_merge/models/pull_requests.py +++ b/runbot_merge/models/pull_requests.py @@ -415,7 +415,7 @@ class Branch(models.Model): i, len(WAIT_FOR_VISIBILITY) ) break - _logger.warn( + _logger.warning( "[repo] updated %s:%s to %s: failed (at %d/%d)", r.name, refname, staging_head, i, len(WAIT_FOR_VISIBILITY) @@ -1123,7 +1123,7 @@ class PullRequests(models.Model): """ split_batches = self.with_context(active_test=False).mapped('batch_ids').filtered('split_id') if len(split_batches) > 1: - _logger.warn("Found a PR linked with more than one split batch: %s (%s)", self, split_batches) + _logger.warning("Found a PR linked with more than one split batch: %s (%s)", self, split_batches) for b in split_batches: if len(b.split_id.batch_ids) == 1: # only the batch of this PR -> delete split