Skip to content

Commit 4ff4788

Browse files
committed
Add "adopt a module" message
1 parent 947b688 commit 4ff4788

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

environment.sample

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# broker URI to use for the celery task queue
77
#BROKER_URI=redis://queue
88

9+
# Maintainer role page URL, used in "adopt a module" message.
10+
# Set this empty to disable the message
11+
#MAINTAINER_ROLE_PAGE=https://odoo-community.org/page/maintainer-role
12+
913
#HTTP_HOST=0.0.0.0
1014
#HTTP_PORT=8080
1115

src/oca_github_bot/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def func_wrapper(*args, **kwargs):
4747

4848
BROKER_URI = os.environ.get("BROKER_URI", os.environ.get("REDIS_URI", "redis://queue"))
4949

50+
MAINTAINER_ROLE_PAGE = os.environ.get(
51+
"MAINTAINER_ROLE_PAGE", "https://odoo-community.org/page/maintainer-role"
52+
)
53+
5054
SENTRY_DSN = os.environ.get("SENTRY_DSN")
5155

5256
DRY_RUN = os.environ.get("DRY_RUN", "").lower() in ("1", "true", "yes")

src/oca_github_bot/tasks/mention_maintainer.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from celery.task import task
66

7-
from .. import github
7+
from .. import config, github
88
from ..config import switchable
99
from ..manifest import (
1010
addon_dirs_in,
@@ -50,8 +50,11 @@ def mention_maintainer(org, repo, pr, dry_run=False):
5050
modified_addons_maintainers.update(addon_maintainers)
5151

5252
pr_opener = gh_pr.user.login
53-
modified_addons_maintainers.discard(pr_opener)
54-
all_mentions_comment = get_mention(modified_addons_maintainers)
53+
if not modified_addons_maintainers:
54+
all_mentions_comment = get_adopt_mention(pr_opener)
55+
else:
56+
modified_addons_maintainers.discard(pr_opener)
57+
all_mentions_comment = get_mention(modified_addons_maintainers)
5558

5659
if not all_mentions_comment:
5760
return False
@@ -75,6 +78,19 @@ def get_mention(maintainers):
7578
return mentions_comment
7679

7780

81+
def get_adopt_mention(pr_opener):
82+
"""Get a comment inviting to adopt the module."""
83+
if config.MAINTAINER_ROLE_PAGE:
84+
return (
85+
"Hi @" + pr_opener + ",\n"
86+
"the module you are changing has no declared maintainer.\n"
87+
"Would you like to adopt it? (See %s)\n"
88+
"Just add your GitHub name to `maintainers` key of `__manifest__.py`"
89+
" file!"
90+
) % config.MAINTAINER_ROLE_PAGE
91+
return ""
92+
93+
7894
def get_maintainers(addon_dirs):
7995
"""Get maintainer for each addon in `addon_dirs`.
8096

tests/test_mention_maintainer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_pr_by_maintainer_no_mention(git_clone, mocker):
113113

114114

115115
@pytest.mark.vcr()
116-
def test_no_maintainer_no_mention(git_clone, mocker):
116+
def test_no_maintainer_adopt_module(git_clone, mocker):
117117
github_mock = mocker.patch("oca_github_bot.tasks.mention_maintainer.github")
118118
github_mock.temporary_clone.return_value.__enter__.return_value = str(git_clone)
119119

@@ -127,4 +127,4 @@ def test_no_maintainer_no_mention(git_clone, mocker):
127127
mocker.patch("oca_github_bot.tasks.mention_maintainer.check_call")
128128
mention_maintainer("org", "repo", "pr")
129129

130-
github_mock.gh_call.assert_not_called()
130+
github_mock.gh_call.assert_called_once()

0 commit comments

Comments
 (0)