Skip to content

Commit 5babcc4

Browse files
committed
pkgdev mask: offer to send email to gentoo-dev ML
Resolves: #36 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 594f48d commit 5babcc4

5 files changed

Lines changed: 78 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
pytest --cov --cov-report=term --cov-report=xml -v
6565
6666
- name: Submit code coverage to codecov
67+
if: ${{ matrix.os == 'ubuntu-latest' }}
6768
uses: codecov/codecov-action@v1
6869
with:
6970
file: ./coverage.xml

completion/bash/pkgdev

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,12 @@ _pkgdev() {
113113
mask)
114114
subcmd_options="
115115
-r --rites
116+
-b --bugs
117+
--email
116118
"
117119

118120
case "${prev}" in
119-
-r | --rites)
121+
-[rb] | --rites | --bugs)
120122
COMPREPLY=()
121123
;;
122124
*)

completion/zsh/_pkgdev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ case $state in
6565
_arguments -C -A '-*' \
6666
$base_options \
6767
{'(--rites)-r','(-r)--rites'}'[mark for last rites]' \
68+
{'(--bugs)-b','(-b)--bugs'}'[reference bug in the mask comment]' \
69+
'--email[spawn email composer with prepared email for sending to mailing lists]' \
6870
&& ret=0
6971
;;
7072
(push)

src/pkgdev/scripts/pkgdev_mask.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,27 @@
5151
Add a reference to a bug in the mask comment. May be specified multiple
5252
times to reference multiple bugs.
5353
""")
54+
mask_opts.add_argument(
55+
'--email', action='store_true',
56+
help='spawn email composer with prepared email for sending to mailing lists',
57+
docs="""
58+
Spawn user's preferred email composer with a prepared email for
59+
sending a last rites message to Gentoo's mailing list (``gentoo-dev``
60+
and ``gentoo-dev-announce``). The user should manually set the Reply-to
61+
field for the message to be accepted by ``gentoo-dev-announce``.
62+
63+
For spawning the preferred email composer, the ``xdg-email`` tool from
64+
``x11-misc/xdg-utils`` package.
65+
""")
5466

5567

5668
@mask.bind_final_check
5769
def _mask_validate(parser, namespace):
5870
atoms = []
5971

72+
if namespace.email and not namespace.rites:
73+
mask.error('last rites required for email support')
74+
6075
if namespace.targets:
6176
for x in namespace.targets:
6277
if os.path.exists(x) and x.endswith('.ebuild'):
@@ -223,6 +238,20 @@ def get_comment(bugs):
223238
return comment
224239

225240

241+
def send_last_rites_email(m: Mask, subject_prefix: str):
242+
try:
243+
atoms = ', '.join(map(str, m.atoms))
244+
subprocess.run(args=[
245+
'xdg-email', '--utf8',
246+
'--cc', 'gentoo-dev@lists.gentoo.org',
247+
'--subject', f'{subject_prefix}: {atoms}',
248+
'--body', str(m),
249+
'gentoo-dev-announce@lists.gentoo.org'
250+
], check=True)
251+
except subprocess.CalledProcessError:
252+
mask.error('failed opening email composer')
253+
254+
226255
@mask.bind_main_func
227256
def _mask(options, out, err):
228257
mask_file = MaskFile(pjoin(options.repo.location, 'profiles/package.mask'))
@@ -248,7 +277,11 @@ def _mask(options, out, err):
248277
removal = removal_date.strftime('%Y-%m-%d')
249278
mask_args['comment'].append(f'Removal: {removal}')
250279

251-
mask_file.add(Mask(**mask_args))
280+
m = Mask(**mask_args)
281+
mask_file.add(m)
252282
mask_file.write()
253283

284+
if options.email:
285+
send_last_rites_email(m, 'Last rites')
286+
254287
return 0

tests/scripts/test_pkgdev_mask.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import textwrap
34
from datetime import datetime, timedelta, timezone
45
from functools import partial
@@ -83,6 +84,18 @@ def test_targets(self, repo, make_git_repo, capsys, tool):
8384
options, _ = tool.parse_args(['mask', 'cat/pkg'])
8485
assert options.atoms == [atom_cls('cat/pkg')]
8586

87+
def test_email_not_rites(self, repo, make_git_repo, capsys, tool):
88+
git_repo = make_git_repo(repo.location)
89+
90+
# masked pkg
91+
repo.create_ebuild('cat/pkg-0')
92+
git_repo.add_all('cat/pkg-0')
93+
with pytest.raises(SystemExit), \
94+
chdir(repo.location):
95+
tool.parse_args(['mask', '--email', 'cat/pkg'])
96+
_, err = capsys.readouterr()
97+
assert err.strip() == "pkgdev mask: error: last rites required for email support"
98+
8699

87100
class TestPkgdevMask:
88101

@@ -202,6 +215,31 @@ def test_last_rites(self):
202215
""")
203216
self.masks_path.write_text("") # Reset the contents of package.mask
204217

218+
@pytest.mark.skipif(sys.platform == "darwin", reason="no xdg-email on mac os")
219+
def test_last_rites_with_email(self, tmp_path):
220+
output_file = tmp_path / 'mail.txt'
221+
for rflag in ('-r', '--rites'):
222+
with os_environ(EDITOR="sed -i '1s/$/mask comment/'", MAILER=f"> {output_file} echo"), \
223+
patch('sys.argv', self.args + ['cat/pkg', rflag, '--email']), \
224+
pytest.raises(SystemExit), \
225+
chdir(pjoin(self.repo.path)):
226+
self.script()
227+
out = output_file.read_text()
228+
assert 'mailto:gentoo-dev-announce@lists.gentoo.org' in out
229+
230+
self.masks_path.write_text("") # Reset the contents of package.mask
231+
232+
@pytest.mark.skipif(sys.platform == "darwin", reason="no xdg-email on mac os")
233+
def test_last_email_bad_mailer(self, capsys):
234+
for rflag in ('-r', '--rites'):
235+
with os_environ(EDITOR="sed -i '1s/$/mask comment/'", MAILER="false"), \
236+
patch('sys.argv', self.args + ['cat/pkg', rflag, '--email']), \
237+
pytest.raises(SystemExit), \
238+
chdir(pjoin(self.repo.path)):
239+
self.script()
240+
_, err = capsys.readouterr()
241+
assert err.strip() == "pkgdev mask: error: failed opening email composer"
242+
205243
def test_mask_bugs(self):
206244
removal_date = self.today + timedelta(days=30)
207245
today = self.today.strftime('%Y-%m-%d')

0 commit comments

Comments
 (0)