1
1
#!/usr/bin/env python3
2
2
import argparse
3
3
import dataclasses
4
+ import datetime
4
5
import os
5
6
import re
6
7
import json
12
13
from typing import List , Optional , Dict
13
14
from jinja2 import Environment , FileSystemLoader , StrictUndefined
14
15
from junit_utils import get_property_value , iter_xml_files
16
+ from gh_status import update_pr_comment_text
15
17
16
18
17
19
class TestStatus (Enum ):
@@ -155,7 +157,7 @@ def render(self, add_footnote=False):
155
157
github_srv = os .environ .get ("GITHUB_SERVER_URL" , "https://github.com" )
156
158
repo = os .environ .get ("GITHUB_REPOSITORY" , "ydb-platform/ydb" )
157
159
158
- footnote_url = f"{ github_srv } /{ repo } /tree/main/.github/config"
160
+ footnote_url = f"{ github_srv } /{ repo } /tree/main/.github/config/muted_ya.txt "
159
161
160
162
footnote = "[^1]" if add_footnote else f'<sup>[?]({ footnote_url } "All mute rules are defined here")</sup>'
161
163
@@ -287,18 +289,20 @@ def gen_summary(summary_url_prefix, summary_out_folder, paths):
287
289
return summary
288
290
289
291
290
- def get_comment_text (pr : PullRequest , summary : TestSummary , build_preset : str , test_history_url : str ):
292
+ def get_comment_text (pr : PullRequest , summary : TestSummary , test_history_url : str ):
291
293
if summary .is_empty :
292
294
return [
293
- f":red_circle: ** { build_preset } **: Test run completed, no test results found for commit { pr .head .sha } . "
295
+ f"Test run completed, no test results found for commit { pr .head .sha } . "
294
296
f"Please check build logs."
295
297
]
296
298
elif summary .is_failed :
297
- result = f":red_circle: ** { build_preset } **: some tests FAILED "
299
+ result = f"Some tests failed, follow the links below. "
298
300
else :
299
- result = f":green_circle: ** { build_preset } **: all tests PASSED "
301
+ result = f"Tests successful. "
300
302
301
- body = [f"{ result } for commit { pr .head .sha } ." ]
303
+ body = [
304
+ result
305
+ ]
302
306
303
307
if test_history_url :
304
308
body .append ("" )
@@ -309,36 +313,6 @@ def get_comment_text(pr: PullRequest, summary: TestSummary, build_preset: str, t
309
313
return body
310
314
311
315
312
- def update_pr_comment (run_number : int , pr : PullRequest , summary : TestSummary , build_preset : str , test_history_url : str ):
313
- header = f"<!-- status pr={ pr .number } , run={{}} -->"
314
- header_re = re .compile (header .format (r"(\d+)" ))
315
-
316
- comment = body = None
317
-
318
- for c in pr .get_issue_comments ():
319
- if matches := header_re .match (c .body ):
320
- comment = c
321
- if int (matches [1 ]) == run_number :
322
- body = [c .body , "" , "---" , "" ]
323
-
324
- if body is None :
325
- body = [
326
- header .format (run_number ),
327
- "> [!NOTE]" ,
328
- "> This is an automated comment that will be appended during run." ,
329
- "" ,
330
- ]
331
-
332
- body .extend (get_comment_text (pr , summary , build_preset , test_history_url ))
333
-
334
- body = "\n " .join (body )
335
-
336
- if comment is None :
337
- pr .create_issue_comment (body )
338
- else :
339
- comment .edit (body )
340
-
341
-
342
316
def main ():
343
317
parser = argparse .ArgumentParser ()
344
318
parser .add_argument ("--summary-out-path" , required = True )
@@ -364,9 +338,16 @@ def main():
364
338
with open (os .environ ["GITHUB_EVENT_PATH" ]) as fp :
365
339
event = json .load (fp )
366
340
367
- run_number = int (os .environ .get ("GITHUB_RUN_NUMBER" ))
368
341
pr = gh .create_from_raw_data (PullRequest , event ["pull_request" ])
369
- update_pr_comment (run_number , pr , summary , args .build_preset , args .test_history_url )
342
+
343
+ text = get_comment_text (pr , summary , args .test_history_url )
344
+
345
+ if summary .is_empty | summary .is_failed :
346
+ color = 'red'
347
+ else :
348
+ color = 'green'
349
+
350
+ update_pr_comment_text (pr , args .build_preset , color , text = '\n ' .join (text ), rewrite = False )
370
351
371
352
372
353
if __name__ == "__main__" :
0 commit comments