Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ repos:
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
rev: v0.17.5
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]
- id: ruff-format
2 changes: 1 addition & 1 deletion src/oca_github_bot/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def delay(self, org, repo, pr, username, dry_run=False):

class BotCommandMerge(BotCommand):
bumpversion_mode = None
bumpversion_mode_list = ["major", "minor", "patch", "nobump"]
bumpversion_mode_list = ("major", "minor", "patch", "nobump")

def parse_options(self, options):
if not options:
Expand Down
2 changes: 1 addition & 1 deletion src/oca_github_bot/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"task": "oca_github_bot.tasks.main_branch_bot."
"main_branch_bot_all_repos",
"args": (org,),
"kwargs": dict(build_wheels=True),
"kwargs": {"build_wheels": True},
"schedule": crontab(hour="2", minute="30"),
},
"tag_ready_to_merge": {
Expand Down
4 changes: 2 additions & 2 deletions src/oca_github_bot/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ def _get_manifest_from_api(gh_repo, addon, branch, manifest_file):
path = f"{addon}/{manifest_file}"
try:
file_contents = gh_repo.file_contents(path, ref=branch)
except Exception as e:
except Exception as e: # noqa: BLE001
_logger.debug("Could not read %s@%s via GitHub API: %s", path, branch, e)
return None
if file_contents is None:
return None
try:
return parse_manifest(file_contents.decoded)
except Exception as e:
except Exception as e: # noqa: BLE001
_logger.warning(
"Failed to parse manifest %s@%s from GitHub API: %s", path, branch, e
)
Expand Down
2 changes: 2 additions & 0 deletions src/oca_github_bot/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def check_call(cmd, cwd, log_error=True, extra_cmd_args=False, env=None):
cmd += extra_cmd_args
cp = subprocess.run(
cmd,
check=False,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
Expand All @@ -34,6 +35,7 @@ def check_call(cmd, cwd, log_error=True, extra_cmd_args=False, env=None):
def check_output(cmd, cwd, log_error=True):
cp = subprocess.run(
cmd,
check=False,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
Expand Down
4 changes: 1 addition & 3 deletions src/oca_github_bot/tasks/label_modified_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def _label_modified_addons(gh, org, repo, pr, dry_run):
if is_main_branch_bot_branch(target_branch):
new_labels.add(f"series:{target_branch}")
new_labels |= {
x
for x in issue_label_names
if not (x.startswith("mod:") or x.startswith("series:"))
x for x in issue_label_names if not (x.startswith(("mod:", "series:")))
}

if not dry_run and new_labels != set(issue_label_names):
Expand Down
6 changes: 3 additions & 3 deletions src/oca_github_bot/tasks/mention_maintainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def mention_maintainer(org, repo, pr, dry_run=False):

modified_addons_maintainers = set()
for modified_addon in modified_addon_dirs:
addon_maintainers = maintainers_dict.get(modified_addon, list())
addon_maintainers = maintainers_dict.get(modified_addon, [])
modified_addons_maintainers.update(addon_maintainers)

pr_opener = gh_pr.user.login
Expand All @@ -67,7 +67,7 @@ def mention_maintainer(org, repo, pr, dry_run=False):

def get_mention(maintainers):
"""Get a comment mentioning all the `maintainers`."""
maintainers_mentions = list(map(lambda m: "@" + m, maintainers))
maintainers_mentions = ["@" + m for m in maintainers]
mentions_comment = ""
if maintainers_mentions:
mentions_comment = (
Expand All @@ -90,7 +90,7 @@ def get_maintainers(addon_dirs):

:return: Dictionary {'addon_dir': <list of addon's maintainers>}
"""
addon_maintainers_dict = dict()
addon_maintainers_dict = {}
for addon_dir in addon_dirs:
maintainers = get_manifest(addon_dir).get("maintainers", [])
addon_maintainers_dict.setdefault(addon_dir, maintainers)
Expand Down
2 changes: 1 addition & 1 deletion src/oca_github_bot/tasks/merge_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def _get_commit_success(org, repo, pr, gh_commit):
@task()
@switchable("merge_bot")
def merge_bot_status(org, repo, merge_bot_branch, sha):
with contextlib.suppress(github.BranchNotFoundError):
with contextlib.suppress(github.BranchNotFoundError): # noqa: SIM117
with github.temporary_clone(org, repo, merge_bot_branch) as clone_dir:
head_sha = github.git_get_head_sha(cwd=clone_dir)
if head_sha != sha:
Expand Down
7 changes: 3 additions & 4 deletions src/oca_github_bot/tasks/tag_ready_to_merge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) ACSONE SA/NV 2018
# Distributed under the MIT License (http://opensource.org/licenses/MIT).

from datetime import datetime, timedelta
from datetime import UTC, datetime, timedelta

from .. import github
from ..config import MIN_PR_AGE, switchable
Expand All @@ -26,7 +26,7 @@
def tag_ready_to_merge(org, repo=None, dry_run=False):
"""Add the ``ready to merge`` tag to all PRs where conditions are met."""
with github.login() as gh:
max_created = datetime.utcnow() - timedelta(days=MIN_PR_AGE)
max_created = datetime.now(tz=UTC) - timedelta(days=MIN_PR_AGE)
query = [
"type:pr",
"state:open",
Expand All @@ -42,8 +42,7 @@ def tag_ready_to_merge(org, repo=None, dry_run=False):
for issue in gh.search_issues(" ".join(query)):
if dry_run:
_logger.info(
f"DRY-RUN add {LABEL_READY_TO_MERGE} "
f"label to PR {issue.html_url}"
f"DRY-RUN add {LABEL_READY_TO_MERGE} label to PR {issue.html_url}"
)
else:
_logger.info(f"add {LABEL_READY_TO_MERGE} label to PR {issue.html_url}")
Expand Down
2 changes: 1 addition & 1 deletion src/oca_github_bot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def compute_module_label_name(module_name: str) -> str:
if len(label_name) > _MAX_LABEL_SIZE:
module_hash = hashlib.sha256(bytes(module_name, "utf-8")).hexdigest()
label_name = (
f"{label_name[:(_MAX_LABEL_SIZE - (_HASH_SIZE + 1))]}"
f"{label_name[: (_MAX_LABEL_SIZE - (_HASH_SIZE + 1))]}"
f" {module_hash[:_HASH_SIZE]}"
)
return label_name
4 changes: 1 addition & 3 deletions src/oca_github_bot/version_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def is_supported_main_branch(branch_name, min_version=None):
if not ODOO_VERSION_RE.match(branch_name):
return False
branch_version = version.parse(branch_name)
if min_version and branch_version < version.parse(min_version):
return False
return True
return not (min_version and branch_version < version.parse(min_version))


def is_main_branch_bot_branch(branch_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ async def on_pr_open_label_new_contributor(event, gh, *args, **kwargs):
if the author has less than 4 commits in OCA repositories.
"""
# TODO
pass
4 changes: 2 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def commit_addon(git_clone, addon_name):
@contextmanager
def set_config(**kwargs):
saved = {}
for key in kwargs:
for key, value in kwargs.items():
saved[key] = getattr(config, key)
setattr(config, key, kwargs[key])
setattr(config, key, value)
try:
yield
finally:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_git_modified_addons_merge_base(git_clone):
subprocess.check_call(["git", "commit", "-m", "[BOT] add addon2"], cwd=git_clone)
assert git_modified_addons(git_clone, "origin/master") == ({"addon2"}, False)
# create addon1 on a new branch
subprocess.check_call(["git", "checkout", "-b" "addon1"], cwd=git_clone)
subprocess.check_call(["git", "checkout", "-b", "addon1"], cwd=git_clone)
addon1_dir = git_clone / "addon1"
addon1_dir.mkdir()
(addon1_dir / "__manifest__.py").write_text("{'name': 'addon1'}")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mention_maintainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_multi_maintainer_one_mention(git_clone, mocker):
github_mock = mocker.patch("oca_github_bot.tasks.mention_maintainer.github")
github_mock.temporary_clone.return_value.__enter__.return_value = str(git_clone)

addon_dirs = list()
addon_dirs = []
addon_names = ["addon1", "addon2"]
themaintainer = "themaintainer"
for addon_name in addon_names:
Expand All @@ -96,7 +96,7 @@ def test_pr_by_maintainer_no_mention(git_clone, mocker, pr_opener):
pr_mock = github_mock.login.return_value.__enter__.return_value.pull_request
pr_mock.return_value.user.login = pr_opener

addon_dirs = list()
addon_dirs = []
addon_names = ["addon1", "addon2"]
for addon_name in addon_names:
addon_dir = make_addon(git_clone, addon_name, maintainers=["themaintainer"])
Expand Down
56 changes: 35 additions & 21 deletions tests/test_migration_issue_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,48 @@ def test_set_lines_issue(gh):

body_transformation = [
(
"Issue with list but not the module\n"
"- [ ] a_module_1 - By @legalsylvain - #1\n"
"- [ ] z_module_1 - By @pedrobaeza - #2",
f"Issue with list but not the module\n"
f"- [ ] a_module_1 - By @legalsylvain - #1\n"
f"- [ ] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2",
(
"Issue with list but not the module\n"
"- [ ] a_module_1 - By @legalsylvain - #1\n"
"- [ ] z_module_1 - By @pedrobaeza - #2"
),
(
f"Issue with list but not the module\n"
f"- [ ] a_module_1 - By @legalsylvain - #1\n"
f"- [ ] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2"
),
),
(
f"Issue with list containing the module\n"
f"- [x] {module} - By @legalsylvain - #1\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2",
f"Issue with list containing the module\n"
f"- [x] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2",
(
f"Issue with list containing the module\n"
f"- [x] {module} - By @legalsylvain - #1\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2"
),
(
f"Issue with list containing the module\n"
f"- [x] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2"
),
),
(
f"Issue with list containing the module with no PR\n"
f"- [x] {module}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2",
f"Issue with list containing the module with no PR\n"
f"- [x] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2",
(
f"Issue with list containing the module with no PR\n"
f"- [x] {module}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2"
),
(
f"Issue with list containing the module with no PR\n"
f"- [x] {module} - By @{gh_pr_user_login} - #{gh_pr_number}\n"
f"- [ ] z_module_1 - By @pedrobaeza - #2"
),
),
(
"Issue with no list",
f"Issue with no list\n"
f"- [ ] {module} - By @{gh_pr_user_login} - #{gh_pr_number}",
(
f"Issue with no list\n"
f"- [ ] {module} - By @{gh_pr_user_login} - #{gh_pr_number}"
),
),
]
for old_body, new_body_expected in body_transformation:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_retry_on_exception_raise_match():
def func_that_raises():
nonlocal counter
counter += 1
raise Exception("something")
raise Exception("something") # noqa: TRY002

max_retries = 2
sleep_time = 0.1
Expand All @@ -45,7 +45,7 @@ def func_that_raises():
max_retries=max_retries,
sleep_time=sleep_time,
)
except Exception as e:
except Exception as e: # noqa: BLE001
assert "something" in str(e)
assert counter == max_retries + 1

Expand All @@ -56,7 +56,7 @@ def test_retry_on_exception_raise_no_match():
def func_that_raises():
nonlocal counter
counter += 1
raise Exception("somestuff")
raise Exception("somestuff") # noqa: TRY002

max_retries = 2
sleep_time = 0.1
Expand All @@ -68,7 +68,7 @@ def func_that_raises():
max_retries=max_retries,
sleep_time=sleep_time,
)
except Exception as e:
except Exception as e: # noqa: BLE001
assert "somestuff" in str(e)
assert counter == 1

Expand Down
Loading