[IMP] runbot_merge, forwardport: minor cleanups

Remove unused imports, unnecessary f-strings, dead code, fix
less-than-ideal operators.
This commit is contained in:
Xavier Morel 2023-08-10 13:21:21 +02:00
parent a692163f6e
commit cdffa83191
10 changed files with 16 additions and 25 deletions

View File

@ -13,7 +13,6 @@ it up), ...
"""
import ast
import base64
import collections
import contextlib
import datetime
import itertools
@ -421,7 +420,7 @@ class PullRequests(models.Model):
limit = next(tokens, None)
ping = True
if not self._pr_acl(author).is_author:
msg = "you can't set a forward-port limit.".format(login)
msg = "you can't set a forward-port limit."
elif not limit:
msg = "please provide a branch to forward-port to."
else:

View File

@ -1,8 +1,4 @@
# -*- coding: utf-8 -*-
import collections
import time
import pytest
from utils import seen, Commit, make_basic

View File

@ -71,7 +71,7 @@ class GH(object):
"""
req = response.request
url = werkzeug.urls.url_parse(req.url)
if url.netloc is not 'api.github.com':
if url.netloc != 'api.github.com':
return
body = '' if not req.body else ('\n' + pprint.pformat(json.loads(req.body.decode()), indent=4))

View File

@ -1,6 +1,3 @@
import collections
def migrate(cr, version):
""" Status overrides: o2m -> m2m
"""

View File

@ -1682,7 +1682,6 @@ class FeedbackTemplate(models.Model):
except Exception:
_logger.exception("Failed to render template %s", self.get_external_id())
raise
return None
class Commit(models.Model):
"""Represents a commit onto which statuses might be posted,

View File

@ -9,7 +9,7 @@ from odoo import http
from odoo.addons.base.models.ir_cron import ir_cron
from odoo.http import WebRequest
from .exceptions import FastForwardError, Mismatch, MergeError, Unmergeable
from .exceptions import FastForwardError, MergeError, Unmergeable
def delegate(self, attr):

View File

@ -7,7 +7,7 @@ from unittest import mock
import pytest
import requests
from lxml import html, etree
from lxml import html
import odoo
from utils import _simple_init, seen, re_matches, get_partner, Commit, pr_page, to_pr, part_of
@ -1776,9 +1776,9 @@ commits, I need to know how to merge it:
with repo:
root = repo.make_commits(None, Commit("root", tree={'a': 'a'}), ref='heads/master')
repo.make_commits(root, Commit('C', tree={'a': 'b'}), ref=f'heads/change')
repo.make_commits(root, Commit('C', tree={'a': 'b'}), ref='heads/change')
pr = repo.make_pr(title="title", body=f'first\n{separator}\nsecond',
target='master', head=f'change')
target='master', head='change')
repo.post_status(pr.head, 'success', 'legal/cla')
repo.post_status(pr.head, 'success', 'ci/runbot')
pr.post_comment('hansen r+ merge', config['role_reviewer']['token'])
@ -1806,7 +1806,7 @@ commits, I need to know how to merge it:
with repo:
root = repo.make_commits(None, Commit("root", tree={'a': 'a'}), ref='heads/master')
repo.make_commits(root, Commit('C', tree={'a': 'b'}), ref=f'heads/change')
repo.make_commits(root, Commit('C', tree={'a': 'b'}), ref='heads/change')
pr = repo.make_pr(title="title", body="""\
Title
---
@ -1818,7 +1818,7 @@ This is more text
***
removed
""",
target='master', head=f'change')
target='master', head='change')
repo.post_status(pr.head, 'success', 'legal/cla')
repo.post_status(pr.head, 'success', 'ci/runbot')
pr.post_comment('hansen r+ merge', config['role_reviewer']['token'])
@ -1853,8 +1853,8 @@ removed
with repo:
root = repo.make_commits(None, Commit("root", tree={'a': 'a'}), ref='heads/master')
repo.make_commits(root, Commit('Commit\n\nfirst\n***\nsecond', tree={'a': 'b'}), ref=f'heads/change')
pr = repo.make_pr(title="PR", body=f'first\n***\nsecond',
repo.make_commits(root, Commit('Commit\n\nfirst\n***\nsecond', tree={'a': 'b'}), ref='heads/change')
pr = repo.make_pr(title="PR", body='first\n***\nsecond',
target='master', head='change')
repo.post_status(pr.head, 'success', 'legal/cla')
repo.post_status(pr.head, 'success', 'ci/runbot')
@ -2007,7 +2007,7 @@ Part-of: {pr_id.display_name}"""
assert log_to_node(repo.log('heads/master')), expected
def test_squash_merge(self, repo, env, config, users):
other_user = requests.get(f'https://api.github.com/user', headers={
other_user = requests.get('https://api.github.com/user', headers={
'Authorization': 'token %s' % config['role_other']['token'],
}).json()
other_user = {
@ -2089,7 +2089,7 @@ Signed-off-by: {get_partner(env, users["reviewer"]).formatted_email}\
# FIXME: should probably get the token from the project to be sure it's
# the bot user
current_user = repo._session.get(f'https://api.github.com/user').json()
current_user = repo._session.get('https://api.github.com/user').json()
current_user = {
'name': current_user['name'] or current_user['login'],
# FIXME: not guaranteed

View File

@ -50,7 +50,7 @@ def test_existing_pr_disabled_branch(env, project, make_repo, setreviewers, conf
assert not branch_id.active_staging_id
assert staging_id.state == 'cancelled', \
"closing the PRs should have canceled the staging"
assert staging_id.reason == f"Target branch deactivated by 'admin'."
assert staging_id.reason == "Target branch deactivated by 'admin'."
p = pr_page(page, pr)
target = dict(zip(

View File

@ -1,6 +1,6 @@
import requests
from utils import Commit, to_pr, seen
from utils import Commit, to_pr
def test_partner_merge(env):

View File

@ -179,7 +179,7 @@ def test_bulk_ops(env, port):
'email': "coc@example.org",
'active': False,
}])
assert a.active == b.active == False
assert a.active is b.active is False
assert provision_user(port, [
{'email': 'bob@example.org', 'github_login': 'xyz'},
@ -187,7 +187,7 @@ def test_bulk_ops(env, port):
]) == [2, 0]
assert a.users_id
assert b.users_id
assert a.active == b.active == True
assert a.active is b.active is True
def provision_user(port, users):
r = requests.post(f'http://localhost:{port}/runbot_merge/provision', json={