[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 ast
import base64 import base64
import collections
import contextlib import contextlib
import datetime import datetime
import itertools import itertools
@ -421,7 +420,7 @@ class PullRequests(models.Model):
limit = next(tokens, None) limit = next(tokens, None)
ping = True ping = True
if not self._pr_acl(author).is_author: 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: elif not limit:
msg = "please provide a branch to forward-port to." msg = "please provide a branch to forward-port to."
else: else:

View File

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

View File

@ -71,7 +71,7 @@ class GH(object):
""" """
req = response.request req = response.request
url = werkzeug.urls.url_parse(req.url) url = werkzeug.urls.url_parse(req.url)
if url.netloc is not 'api.github.com': if url.netloc != 'api.github.com':
return return
body = '' if not req.body else ('\n' + pprint.pformat(json.loads(req.body.decode()), indent=4)) 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): def migrate(cr, version):
""" Status overrides: o2m -> m2m """ Status overrides: o2m -> m2m
""" """

View File

@ -1682,7 +1682,6 @@ class FeedbackTemplate(models.Model):
except Exception: except Exception:
_logger.exception("Failed to render template %s", self.get_external_id()) _logger.exception("Failed to render template %s", self.get_external_id())
raise raise
return None
class Commit(models.Model): class Commit(models.Model):
"""Represents a commit onto which statuses might be posted, """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.addons.base.models.ir_cron import ir_cron
from odoo.http import WebRequest from odoo.http import WebRequest
from .exceptions import FastForwardError, Mismatch, MergeError, Unmergeable from .exceptions import FastForwardError, MergeError, Unmergeable
def delegate(self, attr): def delegate(self, attr):

View File

@ -7,7 +7,7 @@ from unittest import mock
import pytest import pytest
import requests import requests
from lxml import html, etree from lxml import html
import odoo import odoo
from utils import _simple_init, seen, re_matches, get_partner, Commit, pr_page, to_pr, part_of 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: with repo:
root = repo.make_commits(None, Commit("root", tree={'a': 'a'}), ref='heads/master') 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', 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', 'legal/cla')
repo.post_status(pr.head, 'success', 'ci/runbot') repo.post_status(pr.head, 'success', 'ci/runbot')
pr.post_comment('hansen r+ merge', config['role_reviewer']['token']) 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: with repo:
root = repo.make_commits(None, Commit("root", tree={'a': 'a'}), ref='heads/master') 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="""\ pr = repo.make_pr(title="title", body="""\
Title Title
--- ---
@ -1818,7 +1818,7 @@ This is more text
*** ***
removed removed
""", """,
target='master', head=f'change') target='master', head='change')
repo.post_status(pr.head, 'success', 'legal/cla') repo.post_status(pr.head, 'success', 'legal/cla')
repo.post_status(pr.head, 'success', 'ci/runbot') repo.post_status(pr.head, 'success', 'ci/runbot')
pr.post_comment('hansen r+ merge', config['role_reviewer']['token']) pr.post_comment('hansen r+ merge', config['role_reviewer']['token'])
@ -1853,8 +1853,8 @@ removed
with repo: with repo:
root = repo.make_commits(None, Commit("root", tree={'a': 'a'}), ref='heads/master') 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') repo.make_commits(root, Commit('Commit\n\nfirst\n***\nsecond', tree={'a': 'b'}), ref='heads/change')
pr = repo.make_pr(title="PR", body=f'first\n***\nsecond', pr = repo.make_pr(title="PR", body='first\n***\nsecond',
target='master', head='change') target='master', head='change')
repo.post_status(pr.head, 'success', 'legal/cla') repo.post_status(pr.head, 'success', 'legal/cla')
repo.post_status(pr.head, 'success', 'ci/runbot') 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 assert log_to_node(repo.log('heads/master')), expected
def test_squash_merge(self, repo, env, config, users): 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'], 'Authorization': 'token %s' % config['role_other']['token'],
}).json() }).json()
other_user = { 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 # FIXME: should probably get the token from the project to be sure it's
# the bot user # 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 = { current_user = {
'name': current_user['name'] or current_user['login'], 'name': current_user['name'] or current_user['login'],
# FIXME: not guaranteed # 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 not branch_id.active_staging_id
assert staging_id.state == 'cancelled', \ assert staging_id.state == 'cancelled', \
"closing the PRs should have canceled the staging" "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) p = pr_page(page, pr)
target = dict(zip( target = dict(zip(

View File

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

View File

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