Skip to content

Commit

Permalink
Add option to set minimum supported branch
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jul 30, 2023
1 parent c054255 commit df58804
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ combine_as_imports=True
use_parentheses=True
line_length=88
known_first_party=oca_github_bot
known_third_party = aiohttp,appdirs,celery,gidgethub,github3,lxml,odoorpc,pytest,requests,setuptools
known_third_party = aiohttp,appdirs,celery,gidgethub,github3,lxml,odoorpc,packaging,pytest,requests,setuptools
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pytest-mock==3.9.0
pytest-vcr==1.0.2
PyYAML==6.0
vcrpy==4.2.1
wrapt==1.15.0
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ click-plugins==1.1.1
click-repl==0.2.0
commonmark==0.9.1
cryptography==41.0.2
Deprecated==1.2.13
docutils==0.19
flower==1.2.0
frozenlist==1.3.1
Expand All @@ -34,14 +33,13 @@ lxml==4.9.1
more-itertools==8.14.0
multidict==6.0.2
OdooRPC==0.8.0
packaging==21.3
packaging==23.1
pkginfo==1.8.3
prometheus-client==0.14.1
prompt-toolkit==3.0.31
pycparser==2.21
Pygments==2.15.0
PyJWT==2.5.0
pyparsing==3.0.9
python-dateutil==2.8.2
pytz==2022.4
raven==6.10.0
Expand All @@ -65,6 +63,5 @@ urllib3==1.26.12
vine==5.0.0
wcwidth==0.2.5
webencodings==0.5.1
wrapt==1.14.1
yarl==1.8.1
zipp==3.8.1
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"lxml",
# for setuptools-odoo-make-default
"setuptools-odoo",
# packaging
"packaging>=22",
],
extras_require={
"test": [
Expand Down
2 changes: 2 additions & 0 deletions src/oca_github_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,5 @@ def func_wrapper(*args, **kwargs):
"WHEEL_BUILD_TOOLS",
"build,pip,setuptools<58,wheel,setuptools-odoo,whool",
).split(",")

MAIN_BRANCH_BOT_MIN_VERSION = os.environ.get("MAIN_BRANCH_BOT_MIN_VERSION", "8.0")
11 changes: 8 additions & 3 deletions src/oca_github_bot/version_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import re

from packaging import version

from . import config

ODOO_VERSION_RE = re.compile(r"^(?P<major>\d+)\.(?P<minor>\d+)$")
MERGE_BOT_BRANCH_RE = re.compile(
r"(?P<target_branch>\S+)"
Expand All @@ -14,10 +18,11 @@


def is_main_branch_bot_branch(branch_name):
mo = ODOO_VERSION_RE.match(branch_name)
if not mo:
if not ODOO_VERSION_RE.match(branch_name):
return False
return int(mo.group("major")) >= 8
return version.parse(branch_name) >= version.parse(
config.MAIN_BRANCH_BOT_MIN_VERSION
)


def is_protected_branch(branch_name):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_version_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
search_merge_bot_branch,
)

from .common import set_config


def test_is_main_branch_bot_branch():
assert not is_main_branch_bot_branch("6.1")
assert not is_main_branch_bot_branch("7.0")
assert is_main_branch_bot_branch("8.0")
assert is_main_branch_bot_branch("12.0")
assert not is_main_branch_bot_branch("10.0-something")
with set_config(MAIN_BRANCH_BOT_MIN_VERSION="10.0"):
assert is_main_branch_bot_branch("10.0")
assert is_main_branch_bot_branch("12.0")
assert not is_main_branch_bot_branch("7.0")


def test_is_protected_branch():
Expand Down

0 comments on commit df58804

Please sign in to comment.