Skip to content

Commit b7a15f9

Browse files
committed
ci: Travis pull request comment only works in travis ci
Signed-off-by: Huaqi Fang <[email protected]>
1 parent 30124d7 commit b7a15f9

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

.ci/build.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,25 @@ def get_expected_result(expected_file, app_path, board, bd_ver):
377377

378378
def send_pull_request_comment(columns, results):
379379
job = os.environ.get("NAME")
380-
comment_job = "## " + job + "\n"
381-
if len(results)>0:
382-
head = "|".join(columns) + "\n"
383-
table_format = "|".join(["---"]*len(columns)) + "\n"
384-
table_head =head +table_format
385-
comments = ""
386-
comment = ""
387-
for result in results:
388-
for k in result:
389-
comment += (k.replace(Fore.RED, "")).replace("\n", "<br>") +" |"
390-
comment = comment.rstrip("|") + "\n"
391-
comments += comment
392-
comment_on_pull_request(comment_job + table_head + comments)
380+
pr_number = os.environ.get("TRAVIS_PULL_REQUEST")
381+
if all([job, pr_number]):
382+
comment_job = "## " + job + "\n"
383+
if len(results)>0:
384+
head = "|".join(columns) + "\n"
385+
table_format = "|".join(["---"]*len(columns)) + "\n"
386+
table_head =head +table_format
387+
comments = ""
388+
comment = ""
389+
for result in results:
390+
for k in result:
391+
comment += (k.replace(Fore.RED, "")).replace("\n", "<br>") +" |"
392+
comment = comment.rstrip("|") + "\n"
393+
comments += comment
394+
comment_on_pull_request(comment_job + table_head + comments)
395+
else:
396+
print("WARNING:Only send pull request comment in travis ci!")
397+
398+
pass
393399

394400

395401
def show_results(results, expected=None):
@@ -400,7 +406,7 @@ def show_results(results, expected=None):
400406
expected_results = None
401407
success_pt = PrettyTable(columns)
402408
expected_pt = PrettyTable(columns)
403-
409+
404410
for result in results:
405411
status = result.pop("status")
406412
if status != 0:
@@ -433,8 +439,8 @@ def show_results(results, expected=None):
433439
success_pt.add_row(result)
434440
print Fore.GREEN + "Successfull results"
435441
print success_pt
436-
437-
442+
443+
438444
print Style.RESET_ALL
439445
sys.stdout.flush()
440446

@@ -449,7 +455,7 @@ def show_results(results, expected=None):
449455

450456
print Fore.RED + "Failed result:"
451457
print failed_pt
452-
458+
453459
print Style.RESET_ALL
454460
sys.stdout.flush()
455461

0 commit comments

Comments
 (0)