Skip to content

Commit

Permalink
Fix #16 icon emoji ordering @lucemia (#17)
Browse files Browse the repository at this point in the history
* fix #16 order emoji with it's type Impact

* fix
  • Loading branch information
lucemia authored Jun 20, 2024
1 parent a0e77d8 commit 3adba59
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/pr_lint/formatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re
from typing import Iterable

from github.Label import Label
from github.PullRequest import PullRequest

emoji_pattern = re.compile(
Expand All @@ -26,16 +28,24 @@ def format(pr: PullRequest) -> None:
pr: The pull request to format
"""

labels = pr.get_labels()
labels: Iterable[Label] = pr.get_labels()
# remove all emojis from the left of title
cleaned_title = pr.title.lstrip("".join(emoji_pattern.findall(pr.title))).strip()

emojis = set()
# Sort the labels in the following order
# any label with "Impact:"
# any label with "Type:"
# other labels
labels = sorted(labels, key=lambda label: ("Impact:" in label.name, "Type:" in label.name), reverse=True)

emojis = []
for label in labels:
if _emjojis := emoji_pattern.findall(label.name):
emojis.update(_emjojis)
for _emjoin in _emjojis:
if _emjoin not in emojis:
emojis.append(_emjoin)

new_title = f"{''.join(emojis)} {cleaned_title}"
if new_title != pr.title:
pr.edit(title=new_title)
print(f"Updated PR title: {pr.title} -> {new_title}")
pr.edit(title=new_title)

0 comments on commit 3adba59

Please sign in to comment.