Skip to content

Commit 9d004ec

Browse files
committed
Handle case when changes had been reported, and then removed
1 parent 5657c21 commit 9d004ec

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

misc/scripts/library-coverage/comment-pr.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
comparison_artifact_file_name = "comparison.md"
1515

1616

17+
comment_first_line = ":warning: The head of this PR and the base branch were compared for differences in the framework coverage reports. "
18+
19+
1720
def get_comment_text(output_file, repo, run_id):
1821
size = os.path.getsize(output_file)
1922
if size == 0:
2023
print("No difference in the coverage reports")
2124
return
2225

23-
comment = ":warning: The head of this PR and the base branch were compared for differences in the framework coverage reports. " + \
26+
comment = comment_first_line + \
2427
f"The generated reports are available in the [artifacts of this workflow run](https://github.com/{repo}/actions/runs/{run_id}). " + \
2528
"The differences will be picked up by the nightly job after the PR gets merged. "
2629

@@ -57,6 +60,7 @@ def comment_pr(repo, run_id):
5760
shutil.rmtree("pr")
5861

5962
# Try storing diff for previous run:
63+
prev_run_id = 0
6064
try:
6165
prev_run_id = get_previous_run_id(repo, run_id, pr_number)
6266
prev_diff_folder = "prev_diff"
@@ -75,6 +79,14 @@ def comment_pr(repo, run_id):
7579

7680
comment = get_comment_text(
7781
f"{current_diff_folder}/{comparison_artifact_file_name}", repo, run_id)
82+
83+
if comment == None:
84+
if prev_run_id == 0:
85+
print("Nothing to comment.")
86+
return
87+
print("Previous run found, and current run removes coverage change.")
88+
comment = comment_first_line + \
89+
"A recent commit removed the previously reported differences."
7890
post_comment(comment, repo, pr_number)
7991

8092

@@ -119,7 +131,7 @@ def get_previous_run_id(repo, run_id, pr_number):
119131

120132
# the previous run needs to be coming from the same PR:
121133
if pr_number == prev_pr_number:
122-
return previous_run_id
134+
return int(previous_run_id)
123135

124136
raise Exception("Couldn't find previous run.")
125137

0 commit comments

Comments
 (0)