Skip to content

Commit

Permalink
build: only comment once on an issue mentioned twice
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 24, 2024
1 parent 2649c5c commit f3b269c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ci/comment_on_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
print(f"Comment will be:\n\n{comment}\n")

repo_owner = sys.argv[1]
for m in re.finditer(fr"https://github.com/{repo_owner}/(issues|pull)/(\d+)", latest["text"]):
kind, number = m.groups()
url_matches = re.finditer(fr"https://github.com/{repo_owner}/(issues|pull)/(\d+)", latest["text"])
urls = set((m[0], m[1], m[2]) for m in url_matches)

for url, kind, number in urls:
do_comment = False

if kind == "issues":
Expand All @@ -31,20 +33,20 @@
if issue_data["state"] == "closed":
do_comment = True
else:
print(f"Still open, comment manually: {m[0]}")
print(f"Still open, comment manually: {url}")
else:
url = f"https://api.github.com/repos/{repo_owner}/pulls/{number}"
pull_data = get_session().get(url).json()
if pull_data["state"] == "closed":
if pull_data["merged"]:
do_comment = True
else:
print(f"Not merged, comment manually: {m[0]}")
print(f"Not merged, comment manually: {url}")
else:
print(f"Still open, comment manually: {m[0]}")
print(f"Still open, comment manually: {url}")

if do_comment:
print(f"Commenting on {m[0]}")
print(f"Commenting on {url}")
url = f"https://api.github.com/repos/{repo_owner}/issues/{number}/comments"
resp = get_session().post(url, json={"body": comment})
print(resp)

0 comments on commit f3b269c

Please sign in to comment.