Skip to content

Commit ab81879

Browse files
authored
Update comment-ci-results.py
1 parent 7fc5c88 commit ab81879

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

.github/workflows/scripts/comment-ci-results.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,43 @@ def sort_report_names(value):
2222
return 2 # For releases or others
2323

2424

25-
def delete_previous_comments(commit, created_comment_ids, exchanges):
25+
def delete_previous_comments(commit, created_comment_ids, targets):
2626
# We'll match comments that start with "## {exchange} - {tradingmode} -"
27-
comment_starts = tuple(
28-
f"## {exchange.split('-')[0].capitalize()} - {exchange.split('-')[1].capitalize()} -" for exchange in exchanges
27+
expected_prefixes = tuple(
28+
f"## {exchange.capitalize()} - {tradingmode.capitalize()} -" for exchange, tradingmode in targets
2929
)
3030
for comment in commit.get_comments():
3131
if comment.user.login != "github-actions[bot]":
3232
continue
3333
if comment.id in created_comment_ids:
3434
continue
35-
if not comment.body.startswith(comment_starts):
36-
continue
37-
print(f"Deleting previous comment {comment}")
38-
comment.delete()
35+
if comment.body.startswith(expected_prefixes):
36+
print(f"Deleting previous comment {comment.id}", file=sys.stderr)
37+
comment.delete()
3938

4039

4140
def comment_results(options, results_data):
4241
gh = github.Github(os.environ["GITHUB_TOKEN"])
4342
repo = gh.get_repo(options.repo)
44-
print(f"Loaded Repository: {repo.full_name}", file=sys.stderr, flush=True)
45-
46-
exchanges = set()
47-
comment_ids = set()
4843
commit = repo.get_commit(os.environ["GITHUB_SHA"])
4944
print(f"Loaded Commit: {commit}", file=sys.stderr, flush=True)
5045

46+
targets = set()
47+
for exchange in results_data:
48+
for tradingmode in ("spot", "futures"):
49+
if tradingmode in results_data[exchange]:
50+
targets.add((exchange, tradingmode))
51+
52+
comment_ids = set()
53+
54+
# Clean up old comments before adding new ones
55+
delete_previous_comments(commit, comment_ids, targets)
56+
57+
# Create new commits
5158
for exchange in sorted(results_data):
5259
for tradingmode in ("spot", "futures"):
5360
if tradingmode not in results_data[exchange]:
5461
continue
55-
exchanges.add(f"{exchange}-{tradingmode}")
5662
mode_data = results_data[exchange][tradingmode]
5763
sorted_report_names = sorted(mode_data["names"], key=sort_report_names)
5864
for timerange in mode_data["timeranges"]:
@@ -156,8 +162,6 @@ def comment_results(options, results_data):
156162
print(f"Created Comment: {comment}", file=sys.stderr, flush=True)
157163
comment_ids.add(comment.id)
158164

159-
delete_previous_comments(commit, comment_ids, exchanges)
160-
161165

162166
def main():
163167
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)