-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Improve the pull-request subcription notification format by adding the description and files statistics #65828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -65,6 +65,14 @@ def run(self) -> bool: | |
return False | ||
|
||
|
||
def human_readable_size(size, decimal_places=2): | ||
for unit in ["B", "KiB", "MiB", "GiB", "TiB", "PiB"]: | ||
if size < 1024.0 or unit == "PiB": | ||
break | ||
size /= 1024.0 | ||
return f"{size:.{decimal_places}f} {unit}" | ||
|
||
|
||
class PRSubscriber: | ||
@property | ||
def team_name(self) -> str: | ||
|
@@ -77,23 +85,62 @@ def __init__(self, token: str, repo: str, pr_number: int, label_name: str): | |
self._team_name = "pr-subscribers-{}".format(label_name).lower() | ||
|
||
def run(self) -> bool: | ||
for team in self.org.get_teams(): | ||
if self.team_name != team.name.lower(): | ||
continue | ||
try: | ||
# GitHub limits comments to 65,536 characters, let's limit our comments to 20,000. | ||
patch = requests.get(self.pr.diff_url).text[0:20000] | ||
except: | ||
patch = "" | ||
comment = ( | ||
"@llvm/{}".format(team.slug) | ||
+ "\n\n<details><summary>Changes</summary><pre>\n" | ||
+ patch | ||
+ "\n</pre></details>" | ||
) | ||
self.pr.as_issue().create_comment(comment) | ||
patch = None | ||
team = self._get_curent_team() | ||
if not team: | ||
print(f"couldn't find team named {self.team_name}") | ||
return False | ||
|
||
# Get statistics for each file | ||
diff_stats = f"{self.pr.changed_files} Files Affected:\n\n" | ||
for file in self.pr.get_files(): | ||
diff_stats += f"- ({file.status}) {file.filename} (" | ||
if file.additions: | ||
diff_stats += f"+{file.additions}" | ||
if file.deletions: | ||
diff_stats += f"-{file.deletions}" | ||
diff_stats += ") " | ||
if file.status == "renamed": | ||
print(f"(from {file.previous_filename})") | ||
diff_stats += "\n" | ||
diff_stats += "\n" | ||
|
||
# Get the diff | ||
try: | ||
patch = requests.get(self.pr.diff_url).text | ||
except: | ||
patch = "" | ||
diff_stats += "\n<pre>\n" + patch | ||
|
||
# GitHub limits comments to 65,536 characters, let's limit the diff to 20kB. | ||
DIFF_LIMIT = 20 * 1024 | ||
patch_link = f"Full diff: {self.pr.diff_url}\n" | ||
if len(patch) > DIFF_LIMIT: | ||
patch_link = f"\nPatch is {human_readable_size(len(patch))}, truncated to {human_readable_size(DIFF_LIMIT)} below, full version: {self.pr.diff_url}\n" | ||
diff_stats = diff_stats[0:DIFF_LIMIT] + "...\n<truncated>\n" | ||
diff_stats += "</pre>" | ||
|
||
body = self.pr.body | ||
comment = ( | ||
"@llvm/{}".format(team.slug) | ||
+ "\n\n<details>\n" | ||
+ f"<summary>Changes</summary>\n\n" | ||
+ f"{body}\n--\n" | ||
+ patch_link | ||
+ "\n" | ||
+ f"{diff_stats}\n\n" | ||
+ "</details>" | ||
) | ||
|
||
self.pr.as_issue().create_comment(comment) | ||
return True | ||
|
||
def _get_curent_team(self) -> Optional[github.Team.Team]: | ||
for team in self.org.get_teams(): | ||
if self.team_name == team.name.lower(): | ||
return team | ||
return None | ||
|
||
|
||
def setup_llvmbot_git(git_dir="."): | ||
""" | ||
|
@@ -199,7 +246,6 @@ def extract_commit_hash(arg: str): | |
|
||
|
||
class ReleaseWorkflow: | ||
|
||
CHERRY_PICK_FAILED_LABEL = "release:cherry-pick-failed" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stray whitespace change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is black formatting! |
||
|
||
""" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I'm seeing this
<pre>
getting escaped to<pre>
, so it no longer has the desired effect and the diff looks horrible in the github web UI. Example: #66188 (comment)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was changed in #66037 , I'm not totally sure why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing in #66322