@@ -65,6 +65,14 @@ def run(self) -> bool:
65
65
return False
66
66
67
67
68
+ def human_readable_size (size , decimal_places = 2 ):
69
+ for unit in ["B" , "KiB" , "MiB" , "GiB" , "TiB" , "PiB" ]:
70
+ if size < 1024.0 or unit == "PiB" :
71
+ break
72
+ size /= 1024.0
73
+ return f"{ size :.{decimal_places }f} { unit } "
74
+
75
+
68
76
class PRSubscriber :
69
77
@property
70
78
def team_name (self ) -> str :
@@ -77,23 +85,62 @@ def __init__(self, token: str, repo: str, pr_number: int, label_name: str):
77
85
self ._team_name = "pr-subscribers-{}" .format (label_name ).lower ()
78
86
79
87
def run (self ) -> bool :
80
- for team in self .org .get_teams ():
81
- if self .team_name != team .name .lower ():
82
- continue
83
- try :
84
- # GitHub limits comments to 65,536 characters, let's limit our comments to 20,000.
85
- patch = requests .get (self .pr .diff_url ).text [0 :20000 ]
86
- except :
87
- patch = ""
88
- comment = (
89
- "@llvm/{}" .format (team .slug )
90
- + "\n \n <details><summary>Changes</summary><pre>\n "
91
- + patch
92
- + "\n </pre></details>"
93
- )
94
- self .pr .as_issue ().create_comment (comment )
88
+ patch = None
89
+ team = self ._get_curent_team ()
90
+ if not team :
91
+ print (f"couldn't find team named { self .team_name } " )
92
+ return False
93
+
94
+ # Get statistics for each file
95
+ diff_stats = f"{ self .pr .changed_files } Files Affected:\n \n "
96
+ for file in self .pr .get_files ():
97
+ diff_stats += f"- ({ file .status } ) { file .filename } ("
98
+ if file .additions :
99
+ diff_stats += f"+{ file .additions } "
100
+ if file .deletions :
101
+ diff_stats += f"-{ file .deletions } "
102
+ diff_stats += ") "
103
+ if file .status == "renamed" :
104
+ print (f"(from { file .previous_filename } )" )
105
+ diff_stats += "\n "
106
+ diff_stats += "\n "
107
+
108
+ # Get the diff
109
+ try :
110
+ patch = requests .get (self .pr .diff_url ).text
111
+ except :
112
+ patch = ""
113
+ diff_stats += "\n <pre>\n " + patch
114
+
115
+ # GitHub limits comments to 65,536 characters, let's limit the diff to 20kB.
116
+ DIFF_LIMIT = 20 * 1024
117
+ patch_link = f"Full diff: { self .pr .diff_url } \n "
118
+ if len (patch ) > DIFF_LIMIT :
119
+ patch_link = f"\n Patch is { human_readable_size (len (patch ))} , truncated to { human_readable_size (DIFF_LIMIT )} below, full version: { self .pr .diff_url } \n "
120
+ diff_stats = diff_stats [0 :DIFF_LIMIT ] + "...\n <truncated>\n "
121
+ diff_stats += "</pre>"
122
+
123
+ body = self .pr .body
124
+ comment = (
125
+ "@llvm/{}" .format (team .slug )
126
+ + "\n \n <details>\n "
127
+ + f"<summary>Changes</summary>\n \n "
128
+ + f"{ body } \n --\n "
129
+ + patch_link
130
+ + "\n "
131
+ + f"{ diff_stats } \n \n "
132
+ + "</details>"
133
+ )
134
+
135
+ self .pr .as_issue ().create_comment (comment )
95
136
return True
96
137
138
+ def _get_curent_team (self ) -> Optional [github .Team .Team ]:
139
+ for team in self .org .get_teams ():
140
+ if self .team_name == team .name .lower ():
141
+ return team
142
+ return None
143
+
97
144
98
145
def setup_llvmbot_git (git_dir = "." ):
99
146
"""
@@ -199,7 +246,6 @@ def extract_commit_hash(arg: str):
199
246
200
247
201
248
class ReleaseWorkflow :
202
-
203
249
CHERRY_PICK_FAILED_LABEL = "release:cherry-pick-failed"
204
250
205
251
"""
0 commit comments