-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
87 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import re | ||
|
||
from github.PullRequest import PullRequest | ||
|
||
emoji_pattern = re.compile( | ||
"[" | ||
"\U0001F600-\U0001F64F" # Emoticons | ||
"\U0001F300-\U0001F5FF" # Symbols & pictographs | ||
"\U0001F680-\U0001F6FF" # Transport & map symbols | ||
"\U0001F1E0-\U0001F1FF" # Flags (iOS) | ||
"\U0001F900-\U0001F9FF" # Supplemental Symbols and Pictographs | ||
"\U0001FA70-\U0001FAFF" # Symbols and Pictographs Extended-A | ||
"\u2600-\u26FF" # Miscellaneous Symbols | ||
"\u2700-\u27BF" # Dingbats | ||
"]" | ||
) | ||
|
||
|
||
def format(pr: PullRequest) -> None: | ||
""" | ||
Format a pull request: | ||
1. Extract emojis from labels and insert them to the PR title | ||
Args: | ||
pr: The pull request to format | ||
""" | ||
|
||
labels = 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() | ||
for label in labels: | ||
if _emjojis := emoji_pattern.findall(label.name): | ||
emojis.update(_emjojis) | ||
|
||
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import re | ||
|
||
from github.Label import Label | ||
from github.PullRequest import PullRequest | ||
|
||
|
||
def lint(pr: PullRequest) -> None: | ||
""" | ||
Lint a pull request: | ||
1. checks if the PR title ends with a username (owner) | ||
2. The username must be a collaborator | ||
3. checks if there is exactly one Type label | ||
4. checks if there is exactly one Impact label | ||
Args: | ||
pr: The pull request to lint | ||
""" | ||
|
||
title = pr.title | ||
repo = pr.base.repo | ||
|
||
pr_owners = re.findall(r"(@[\w]+)$", title) | ||
assert pr_owners, "PR title should end with a GitHub username" | ||
pr_owner = pr_owners[0][1:] | ||
assert repo.has_in_collaborators(pr_owner), f"{pr_owner} is not a collaborator" | ||
|
||
labels = pr.get_labels() | ||
|
||
type_labels: list[Label] = [] | ||
impact_labels: list[Label] = [] | ||
|
||
for label in labels: | ||
if "Type:" in label.name: | ||
type_labels.append(label) | ||
elif "Impact:" in label.name: | ||
impact_labels.append(label) | ||
|
||
assert len(type_labels) == 1, "There should be exactly one Type label" | ||
assert len(impact_labels) == 1, "There should be exactly one Impact label" | ||
|
||
# TODO: check if the PR title is in the correct format (e.g. commitlint convention) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
1 change: 0 additions & 1 deletion
1
...napshots__/test_main/test_clean_title[U0001f34eupdate(v2.0) version updateU0001f34e].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...t/tests/__snapshots__/test_main/test_clean_title[U0001f41bfix correct typoU0001f41b].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
.../__snapshots__/test_main/test_clean_title[U0001f41bu4feeu590d correct typoU0001f41b].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...s__/test_main/test_clean_title[U0001f680feature(add-new) add a new featureU0001f680].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/pr_lint/tests/__snapshots__/test_main/test_clean_title[bug fix issue U0001f41e].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...t/tests/__snapshots__/test_main/test_clean_title[feature(add-new) add a new feature].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/pr_lint/tests/__snapshots__/test_main/test_clean_title[fix correct typo].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/pr_lint/tests/__snapshots__/test_main/test_clean_title[no type].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...shots__/test_main/test_clean_title[not an emoji prefix but contains U0001f680 emoji].json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
.../test_clean_title[u4feeu590duff1au66f4u6b63u767bu5f55u65b9u6cd5u4e2du7684u9519u5b57].json
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.