From aef87253860e8e1d88d7fe8f47a61f5e94cdc3c1 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 2 Jun 2022 07:21:57 -0400 Subject: build: comment_on_fixes comments on pull requests too --- ci/comment_on_fixes.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'ci') 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) -- cgit v1.2.1