-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comment on backport PR when status checks are done. (GH-27)
Leave a comment when status checks for the backport PR are done. Only leave the comment on backports made by @miss-islington. Mention the original PR author and the core dev who merged the original PR. Closes #26
- Loading branch information
Showing
5 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import requests | ||
import os | ||
import re | ||
|
||
from gidgethub import sansio, routing | ||
|
||
from . import util | ||
|
||
router = routing.Router() | ||
|
||
TITLE_RE = re.compile(r'\[(?P<branch>\d+\.\d+)\].+?(?P<pr>\d+)\)') | ||
|
||
|
||
|
||
@router.register("status") | ||
async def check_status(event, gh, *args, **kwargs): | ||
""" | ||
Check the state change | ||
""" | ||
if event.data["commit"]["committer"]["login"] == "miss-islington": | ||
sha = event.data["sha"] | ||
status_url = f"https://api.github.com/repos/python/cpython/commits/{sha}/status" | ||
request_headers = sansio.create_headers( | ||
"miss-islington", | ||
oauth_token=os.getenv('GH_AUTH')) | ||
response = requests.get(status_url, | ||
headers=request_headers) | ||
result = response.json() | ||
|
||
if result["state"] != "pending": | ||
url = "https://api.github.com/repos/miss-islington/cpython/git/refs/heads/" | ||
response = requests.get(url, headers=request_headers) | ||
for ref in response.json(): | ||
print("ref obj") | ||
print(ref) | ||
if "backport-" in ref["ref"] and ref["object"]["sha"] == sha: | ||
backport_branch_name = ref["ref"].split("/")[-1] | ||
pr_url = f"https://api.github.com/repos/python/cpython/pulls?state=open&head=miss-islington:{backport_branch_name}" | ||
pr_response = requests.get(pr_url, headers=request_headers).json() | ||
print("pr respponse") | ||
print(pr_response) | ||
if pr_response: | ||
pr_number = pr_response[0]["number"] | ||
normalized_pr_title = util.normalize_title(pr_response[0]["title"], | ||
pr_response[0]["body"]) | ||
|
||
title_match = TITLE_RE.match(normalized_pr_title) | ||
if title_match: | ||
original_pr_number = title_match.group('pr') | ||
original_pr_url = f"https://api.github.com/repos/python/cpython/pulls/{original_pr_number}" | ||
original_pr_result = requests.get(original_pr_url, | ||
headers=request_headers).json() | ||
pr_author = original_pr_result["user"]["login"] | ||
committer = original_pr_result["merged_by"]["login"] | ||
|
||
participants = util.get_participants( | ||
pr_author, committer) | ||
emoji = "✅" if result['state'] == "success" else "❌" | ||
util.comment_on_pr( | ||
pr_number, | ||
message=f"{participants}: Backport status check is done, and it's a {result['state']} {emoji} .") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters