Skip to content

Commit

Permalink
Keep label description below 100 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Nov 12, 2024
1 parent 45ab4fa commit 8b5ae75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/labels-extra.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
{
"name": "🖥 platform: Linux",
"color": "#bfd4f2",
"description": "ALT Linux, Amazon Linux, Android, Arch Linux, Buildroot, CentOS, CloudLinux OS, Debian, Exherbo Linux, Fedora, Gentoo Linux, Guix System, IBM PowerKVM, KVM for IBM z Systems, Linux Mint, Mageia, Mandriva Linux, openSUSE, Oracle Linux, Parallels, Pidora, Raspbian, RedHat Enterprise Linux, Rocky Linux, Scientific Linux, Slackware, SUSE Linux Enterprise Server, Tuxedo OS, Ubuntu, Unknown Linux, Windows Subsystem for Linux v1, Windows Subsystem for Linux v2, XenServer"
"description": "ALT Linux, Amazon Linux, Android, Arch Linux, Buildroot, CentOS, CloudLinux OS, Debian, "
},
{
"name": "🖥 platform: macOS",
Expand Down
16 changes: 12 additions & 4 deletions meta_package_manager/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def generate_labels(
) -> dict[str, str]:
"""Generate labels.
A dedocated label is produced for each entry of the ``all_labels`` parameter,
A dedicated label is produced for each entry of the ``all_labels`` parameter,
unless it is part of a ``group``. In which case a dedicated label for that group
will be created.
"""
Expand All @@ -83,10 +83,18 @@ def generate_labels(
assert label_name not in all_labels
for label_id in label_ids:
label_map[label_id] = label_name
# Build a description that is less than 100 characters.
description = ""
truncation_mark = ", …"
for item_id in sorted(label_ids, key=str.casefold):
new_item = f", {item_id}" if description else item_id
if len(description) + len(new_item) <= 100 - len(truncation_mark):
description += new_item
else:
description += truncation_mark
break
# Register label to the global registry.
LABELS.append(
(label_name, color, ", ".join(sorted(label_ids, key=str.casefold))),
)
LABELS.append((label_name, color, description))

# Sort label_map by their name.
return dict(sorted(label_map.items(), key=lambda i: str.casefold(i[1])))
Expand Down
10 changes: 9 additions & 1 deletion tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from meta_package_manager.cli import encoding_args
from meta_package_manager.inventory import MAIN_PLATFORMS
from meta_package_manager.labels import MANAGER_PREFIX, PLATFORM_PREFIX
from meta_package_manager.labels import LABELS, MANAGER_PREFIX, PLATFORM_PREFIX
from meta_package_manager.pool import pool

""" Test all non-code artifacts depending on manager definitions.
Expand Down Expand Up @@ -123,6 +123,14 @@ def test_changelog():
)


def test_labels():
for name, color, description in LABELS:
assert name
assert color
assert color.startswith("#")
assert len(description) <= 100


def test_new_package_manager_issue_template():
"""Check all platforms groups are referenced in the issue template."""
content = PROJECT_ROOT.joinpath(
Expand Down

0 comments on commit 8b5ae75

Please sign in to comment.