Skip to content

Commit eb9c7d6

Browse files
authored
Create API Diff Report only when the first commit in PR has an API change (#11275)
1 parent ecd4035 commit eb9c7d6

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

scripts/api_diff_report/pr_commenter.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,32 @@ def main():
5050
run_id = args.run_id
5151

5252
report = ""
53+
comment_id = get_comment_id(token, pr_number, COMMENT_HIDDEN_IDENTIFIER)
5354
if stage == STAGES_PROGRESS:
54-
report = COMMENT_HIDDEN_IDENTIFIER
55-
report += generate_markdown_title(TITLE_PROGESS, commit, run_id)
56-
delete_label(token, pr_number, PR_LABEL)
55+
if comment_id:
56+
report = COMMENT_HIDDEN_IDENTIFIER
57+
report += generate_markdown_title(TITLE_PROGESS, commit, run_id)
58+
update_comment(token, comment_id, report)
59+
delete_label(token, pr_number, PR_LABEL)
5760
elif stage == STAGES_END:
5861
diff_report_file = os.path.join(os.path.expanduser(args.report),
5962
api_diff_report.API_DIFF_FILE_NAME)
6063
with open(diff_report_file, 'r') as file:
6164
report_content = file.read()
62-
if report_content:
65+
if report_content: # Diff detected
6366
report = COMMENT_HIDDEN_IDENTIFIER + generate_markdown_title(
6467
TITLE_END_DIFF, commit, run_id) + report_content
68+
if comment_id:
69+
update_comment(token, comment_id, report)
70+
else:
71+
add_comment(token, pr_number, report)
6572
add_label(token, pr_number, PR_LABEL)
66-
else:
67-
report = COMMENT_HIDDEN_IDENTIFIER + generate_markdown_title(
68-
TITLE_END_NO_DIFF, commit, run_id)
69-
delete_label(token, pr_number, PR_LABEL)
70-
71-
if report:
72-
comment_id = get_comment_id(token, pr_number, COMMENT_HIDDEN_IDENTIFIER)
73-
if not comment_id:
74-
add_comment(token, pr_number, report)
75-
else:
76-
update_comment(token, comment_id, report)
73+
else: # No diff
74+
if comment_id:
75+
report = COMMENT_HIDDEN_IDENTIFIER + generate_markdown_title(
76+
TITLE_END_NO_DIFF, commit, run_id)
77+
update_comment(token, comment_id, report)
78+
delete_label(token, pr_number, PR_LABEL)
7779

7880

7981
def generate_markdown_title(title, commit, run_id):

0 commit comments

Comments
 (0)