Skip to content

Commit e46ee4b

Browse files
committed
commit: name the identifier a new GLEP 81 package allocates
A new acct-user or acct-group package got the generic "new package, add 0" summary, where the interesting part is which UID or GID it takes. Scrape it out of the ebuild and use it instead: acct-user/foo: add user 123 acct-group/foo: add group 456 Resolves: #14 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 82c3dea commit e46ee4b

2 files changed

Lines changed: 58 additions & 42 deletions

File tree

‎src/pkgdev/scripts/pkgdev_commit.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ def _populate(self, pkgs):
326326
tar.extractall(path=self.location, **extra_kwargs)
327327

328328

329+
# GLEP 81 categories, mapped to what their packages allocate
330+
_ACCT_CATEGORIES = {"acct-user": "user", "acct-group": "group"}
331+
332+
329333
def change(*statuses):
330334
"""Decorator to register change status summary methods."""
331335

@@ -461,10 +465,26 @@ def existing(self):
461465
"""Existing packages in the tree related to the package."""
462466
return tuple(self.repo.match(next(iter(self.changes)).unversioned_atom))
463467

468+
@jit_attr
469+
def account(self):
470+
"""Identifier a new GLEP 81 user or group package allocates, if any."""
471+
atom = next(iter(self.changes))
472+
if (kind := _ACCT_CATEGORIES.get(atom.category)) is None or len(self.changes) != 1:
473+
return None
474+
# a negative id asks the eclass to allocate dynamically, nothing to name
475+
id_re = re.compile(rf"""ACCT_{kind.upper()}_ID=(?P<quot>['"]?)(?P<id>\d+)(?P=quot)""")
476+
for pkg in self.repo.match(atom):
477+
for line in pkg.ebuild.text_fileobj():
478+
if mo := id_re.match(line):
479+
return f"{kind} {mo.group('id')}"
480+
return None
481+
464482
@change("A")
465483
def add(self):
466484
"""Generate summaries for add actions."""
467485
if len(self.existing) == len(self.changes):
486+
if self.account is not None:
487+
return f"add {self.account}"
468488
msg = f"new package, add {', '.join(self.versions)}"
469489
if len(self.versions) == 1 or len(msg) <= 50:
470490
return msg

‎tests/scripts/test_pkgdev_commit.py‎

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -489,24 +489,25 @@ def commit():
489489
f.write("# comment\n")
490490
assert commit() == "msg"
491491

492+
def _auto_commit(self, capsys, git_repo):
493+
with (
494+
os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
495+
patch("sys.argv", self.args + ["-a"]),
496+
pytest.raises(SystemExit) as excinfo,
497+
chdir(git_repo.path),
498+
):
499+
self.script()
500+
assert excinfo.value.code == 0
501+
out, err = capsys.readouterr()
502+
assert err == out == ""
503+
message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
504+
return message[0]
505+
492506
def test_generated_commit_summaries(self, capsys, repo, make_git_repo):
493507
git_repo = make_git_repo(repo.location)
494508
repo.create_ebuild("cat/pkg-0")
495509
git_repo.add_all("cat/pkg-0")
496-
497-
def commit():
498-
with (
499-
os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
500-
patch("sys.argv", self.args + ["-a"]),
501-
pytest.raises(SystemExit) as excinfo,
502-
chdir(git_repo.path),
503-
):
504-
self.script()
505-
assert excinfo.value.code == 0
506-
out, err = capsys.readouterr()
507-
assert err == out == ""
508-
message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
509-
return message[0]
510+
commit = partial(self._auto_commit, capsys, git_repo)
510511

511512
# initial package import
512513
repo.create_ebuild("cat/newpkg-0")
@@ -630,9 +631,31 @@ def commit():
630631
shutil.rmtree(pjoin(git_repo.path, "newcat/pkg"))
631632
assert commit() == "newcat/pkg: treeclean"
632633

634+
def test_generated_commit_summaries_acounts(self, capsys, repo, make_git_repo):
635+
git_repo = make_git_repo(repo.location)
636+
repo.create_ebuild("cat/pkg-0")
637+
git_repo.add_all("cat/pkg-0")
638+
commit = partial(self._auto_commit, capsys, git_repo)
639+
640+
# GLEP 81 accounts name the identifier they allocate
641+
repo.create_ebuild("acct-user/newuser-0", acct_user_id=123)
642+
assert commit() == "acct-user/newuser: add user 123"
643+
644+
repo.create_ebuild("acct-group/newgroup-0", acct_group_id=456)
645+
assert commit() == "acct-group/newgroup: add group 456"
646+
647+
# a dynamically allocated id has nothing to name
648+
repo.create_ebuild("acct-user/dynamic-0", acct_user_id=-1)
649+
assert commit() == "acct-user/dynamic: new package, add 0"
650+
651+
# only for a new package, not a version added to an existing one
652+
repo.create_ebuild("acct-user/newuser-1", acct_user_id=123)
653+
assert commit() == "acct-user/newuser: add 1"
654+
633655
def test_generated_commit_summaries_keywords(self, capsys, make_repo, make_git_repo):
634656
repo = make_repo(arches=["amd64", "arm64", "ia64", "x86"])
635657
git_repo = make_git_repo(repo.location)
658+
commit = partial(self._auto_commit, capsys, git_repo)
636659
pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-0"))
637660
with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
638661
f.write(
@@ -648,20 +671,6 @@ def test_generated_commit_summaries_keywords(self, capsys, make_repo, make_git_r
648671
)
649672
git_repo.add_all("cat/pkg-0")
650673

651-
def commit():
652-
with (
653-
os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
654-
patch("sys.argv", self.args + ["-a"]),
655-
pytest.raises(SystemExit) as excinfo,
656-
chdir(git_repo.path),
657-
):
658-
self.script()
659-
assert excinfo.value.code == 0
660-
out, err = capsys.readouterr()
661-
assert err == out == ""
662-
message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
663-
return message[0]
664-
665674
# keyword version
666675
repo.create_ebuild("cat/pkg-0", keywords=["~amd64"])
667676
assert commit() == "cat/pkg: keyword 0 for ~amd64"
@@ -711,6 +720,7 @@ def commit():
711720
def test_metadata_summaries(self, capsys, repo, make_git_repo):
712721
git_repo = make_git_repo(repo.location)
713722
pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-0"))
723+
commit = partial(self._auto_commit, capsys, git_repo)
714724
# stub metadata
715725
with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
716726
f.write(
@@ -729,20 +739,6 @@ def test_metadata_summaries(self, capsys, repo, make_git_repo):
729739
)
730740
git_repo.add_all("cat/pkg-0")
731741

732-
def commit():
733-
with (
734-
os_environ(GIT_EDITOR="sed -i '1s/$/summary/'"),
735-
patch("sys.argv", self.args + ["-a"]),
736-
pytest.raises(SystemExit) as excinfo,
737-
chdir(git_repo.path),
738-
):
739-
self.script()
740-
assert excinfo.value.code == 0
741-
out, err = capsys.readouterr()
742-
assert err == out == ""
743-
message = git_repo.log(["-1", "--pretty=tformat:%B", "HEAD"])
744-
return message[0]
745-
746742
# add yourself
747743
with open(pjoin(pkgdir, "metadata.xml"), "w") as f:
748744
f.write(

0 commit comments

Comments
 (0)