-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
518 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) ACSONE SA/NV 2024 | ||
# Distributed under the MIT License (http://opensource.org/licenses/MIT). | ||
|
||
from .. import github | ||
from ..config import switchable | ||
from ..manifest import git_modified_addons | ||
from ..process import check_call | ||
from ..queue import task | ||
from ..version_branch import is_main_branch_bot_branch | ||
|
||
|
||
def _label_modified_addons(gh, org, repo, pr, dry_run): | ||
gh_pr = gh.pull_request(org, repo, pr) | ||
target_branch = gh_pr.base.ref | ||
pr_branch = f"tmp-pr-{pr}" | ||
with github.temporary_clone(org, repo, target_branch) as clone_dir: | ||
check_call( | ||
["git", "fetch", "origin", f"pull/{pr}/head:{pr_branch}"], | ||
cwd=clone_dir, | ||
) | ||
check_call(["git", "checkout", pr_branch], cwd=clone_dir) | ||
modified_addons, _ = git_modified_addons(clone_dir, target_branch) | ||
if not modified_addons: | ||
return | ||
gh_issue = github.gh_call(gh_pr.issue) | ||
new_labels = {f"addon:{modified_addon}" for modified_addon in modified_addons} | ||
if is_main_branch_bot_branch(target_branch): | ||
new_labels.add(f"series:{target_branch}") | ||
new_labels = new_labels - {label.name for label in gh_issue.labels()} | ||
if new_labels and not dry_run: | ||
for new_label in new_labels: | ||
github.gh_call(gh_issue.add_labels, new_label) | ||
|
||
|
||
@task() | ||
@switchable("label_modified_addons") | ||
def label_modified_addons(org, repo, pr, dry_run): | ||
with github.login() as gh: | ||
_label_modified_addons(gh, org, repo, pr, dry_run) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/oca_github_bot/webhooks/on_pr_label_modified_addons.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) ACSONE SA/NV 2024 | ||
# Distributed under the MIT License (http://opensource.org/licenses/MIT). | ||
|
||
import logging | ||
|
||
from ..router import router | ||
from ..tasks.label_modified_addons import label_modified_addons | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
@router.register("pull_request", action="opened") | ||
@router.register("pull_request", action="reopened") | ||
@router.register("pull_request", action="synchronize") | ||
async def on_pr_label_modified_addons(event, *args, **kwargs): | ||
""" | ||
Whenever a PR is opened, add labels based on modified addons. | ||
""" | ||
org, repo = event.data["repository"]["full_name"].split("/") | ||
pr = event.data["pull_request"]["number"] | ||
label_modified_addons.delay(org, repo, pr) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright ACSONE SA/NV 2024 | ||
# Distributed under the MIT License (http://opensource.org/licenses/MIT). | ||
import pytest | ||
|
||
from oca_github_bot.tasks.label_modified_addons import _label_modified_addons | ||
|
||
|
||
@pytest.mark.vcr() | ||
def test_label_modified_addons(gh): | ||
_label_modified_addons(gh, "OCA", "mis-builder", "610", dry_run=False) |