diff options
-rw-r--r-- | ci/comment_on_fixes.py | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/ci/comment_on_fixes.py b/ci/comment_on_fixes.py index b0f469b1..2c9a424d 100644 --- a/ci/comment_on_fixes.py +++ b/ci/comment_on_fixes.py @@ -14,22 +14,34 @@ comment = ( f"This is now released as part of [coverage {version}]" + f"(https://pypi.org/project/coverage/{version})." ) -print(f"Comment will be: {comment}") +print(f"Comment will be:\n\n{comment}\n") owner = "nedbat" repo = "coveragepy" -for m in re.finditer(r"https://github.com/nedbat/coveragepy/(issues|pull)/(\d+)", latest["text"]): +for m in re.finditer(rf"https://github.com/{owner}/{repo}/(issues|pull)/(\d+)", latest["text"]): kind, number = m.groups() + do_comment = False if kind == "issues": url = f"https://api.github.com/repos/{owner}/{repo}/issues/{number}" issue_data = requests.get(url).json() if issue_data["state"] == "closed": - print(f"Commenting on {m[0]}") - url = f"https://api.github.com/repos/{owner}/{repo}/issues/{number}/comments" - resp = requests.post(url, json={"body": comment}) - print(resp) + do_comment = True else: print(f"Still open, comment manually: {m[0]}") else: - print(f"You need to manually coment on {m[0]}") + url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{number}" + pull_data = requests.get(url).json() + if pull_data["state"] == "closed": + if pull_data["merged"]: + do_comment = True + else: + print(f"Not merged, comment manually: {m[0]}") + else: + print(f"Still open, comment manually: {m[0]}") + + if do_comment: + print(f"Commenting on {m[0]}") + url = f"https://api.github.com/repos/{owner}/{repo}/issues/{number}/comments" + resp = requests.post(url, json={"body": comment}) + print(resp) |