| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2aa60bd commit 5283a54
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,8 +14,12 @@ | |||
| 14 | 14 | from . import tasks | |
| 15 | 15 | from . import backport_pr | |
| 16 | 16 | from . import delete_branch | |
| 17 | + from . import status_change | ||
| 18 | + | ||
| 19 | + router = routing.Router(backport_pr.router, | ||
| 20 | + delete_branch.router, | ||
| 21 | + status_change.router) | ||
| 17 | 22 | ||
| 18 | - router = routing.Router(backport_pr.router, delete_branch.router) | ||
| 19 | 23 | cache = cachetools.LRUCache(maxsize=500) | |
| 20 | 24 | ||
| 21 | 25 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,7 +43,11 @@ async def backport_pr(event, gh, *args, **kwargs): | |||
| 43 | 43 | ||
| 44 | 44 | util.comment_on_pr(issue_number, message) | |
| 45 | 45 | ||
| 46 | - for branch in branches: | ||
| 46 | + sorted_branches = sorted(branches, | ||
| 47 | + reverse=True, | ||
| 48 | + key=lambda v: tuple(map(int, v.split('.')))) | ||
| 49 | + | ||
| 50 | + for branch in sorted_branches: | ||
| 47 | 51 | tasks.backport_task.delay(commit_hash, | |
| 48 | 52 | branch, | |
| 49 | 53 | issue_number=issue_number, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,61 @@ | |||
| 1 | + import requests | ||
| 2 | + import os | ||
| 3 | + import re | ||
| 4 | + | ||
| 5 | + from gidgethub import sansio, routing | ||
| 6 | + | ||
| 7 | + from . import util | ||
| 8 | + | ||
| 9 | + router = routing.Router() | ||
| 10 | + | ||
| 11 | + TITLE_RE = re.compile(r'\[(?P<branch>\d+\.\d+)\].+?(?P<pr>\d+)\)') | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + @router.register("status") | ||
| 16 | + async def check_status(event, gh, *args, **kwargs): | ||
| 17 | + """ | ||
| 18 | + Check the state change | ||
| 19 | + """ | ||
| 20 | + if event.data["commit"]["committer"]["login"] == "miss-islington": | ||
| 21 | + sha = event.data["sha"] | ||
| 22 | + status_url = f"https://api.github.com/repos/python/cpython/commits/{sha}/status" | ||
| 23 | + request_headers = sansio.create_headers( | ||
| 24 | + "miss-islington", | ||
| 25 | + oauth_token=os.getenv('GH_AUTH')) | ||
| 26 | + response = requests.get(status_url, | ||
| 27 | + headers=request_headers) | ||
| 28 | + result = response.json() | ||
| 29 | + | ||
| 30 | + if result["state"] != "pending": | ||
| 31 | + url = "https://api.github.com/repos/miss-islington/cpython/git/refs/heads/" | ||
| 32 | + response = requests.get(url, headers=request_headers) | ||
| 33 | + for ref in response.json(): | ||
| 34 | + print("ref obj") | ||
| 35 | + print(ref) | ||
| 36 | + if "backport-" in ref["ref"] and ref["object"]["sha"] == sha: | ||
| 37 | + backport_branch_name = ref["ref"].split("/")[-1] | ||
| 38 | + pr_url = f"https://api.github.com/repos/python/cpython/pulls?state=open&head=miss-islington:{backport_branch_name}" | ||
| 39 | + pr_response = requests.get(pr_url, headers=request_headers).json() | ||
| 40 | + print("pr respponse") | ||
| 41 | + print(pr_response) | ||
| 42 | + if pr_response: | ||
| 43 | + pr_number = pr_response[0]["number"] | ||
| 44 | + normalized_pr_title = util.normalize_title(pr_response[0]["title"], | ||
| 45 | + pr_response[0]["body"]) | ||
| 46 | + | ||
| 47 | + title_match = TITLE_RE.match(normalized_pr_title) | ||
| 48 | + if title_match: | ||
| 49 | + original_pr_number = title_match.group('pr') | ||
| 50 | + original_pr_url = f"https://api.github.com/repos/python/cpython/pulls/{original_pr_number}" | ||
| 51 | + original_pr_result = requests.get(original_pr_url, | ||
| 52 | + headers=request_headers).json() | ||
| 53 | + pr_author = original_pr_result["user"]["login"] | ||
| 54 | + committer = original_pr_result["merged_by"]["login"] | ||
| 55 | + | ||
| 56 | + participants = util.get_participants( | ||
| 57 | + pr_author, committer) | ||
| 58 | + emoji = "✅" if result['state'] == "success" else "❌" | ||
| 59 | + util.comment_on_pr( | ||
| 60 | + pr_number, | ||
| 61 | + message=f"{participants}: Backport status check is done, and it's a {result['state']} {emoji} .") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,8 +30,13 @@ def backport_task(commit_hash, branch, *, issue_number, created_by, merged_by): | |||
| 30 | 30 | """Backport a commit into a branch.""" | |
| 31 | 31 | if not util.is_cpython_repo(): | |
| 32 | 32 | # cd to cpython if we're not already in it | |
| 33 | - | ||
| 34 | - os.chdir('./cpython') | ||
| 33 | + if "cpython" in os.listdir('.'): | ||
| 34 | + os.chdir('./cpython') | ||
| 35 | + else: | ||
| 36 | + print(f"pwd: {os.pwd()}, listdir: {os.listdir('.')}") | ||
| 37 | + util.comment_on_pr(issue_number, | ||
| 38 | + f"""{util.get_participants(created_by, merged_by)}, Something is wrong... I can't backport for now. | ||
| 39 | + Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line.""") | ||
| 35 | 40 | cp = cherry_picker.CherryPicker('origin', commit_hash, [branch]) | |
| 36 | 41 | try: | |
| 37 | 42 | cp.backport() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ def comment_on_pr(issue_number, message): | |||
| 20 | 20 | headers=request_headers, | |
| 21 | 21 | json=data) | |
| 22 | 22 | if response.status_code == requests.codes.created: | |
| 23 | - print(f"Commented at {response.json()['html_url']}") | ||
| 23 | + print(f"Commented at {response.json()['html_url']}, message: {message}") | ||
| 24 | 24 | else: | |
| 25 | 25 | print(response.status_code) | |
| 26 | 26 | print(response.text) | |
@@ -60,4 +60,13 @@ def delete_branch(branch_name): | |||
| 60 | 60 | if response.status_code == 204: | |
| 61 | 61 | print(f"{branch_name} branch deleted.") | |
| 62 | 62 | else: | |
| 63 | - print(f"Couldn't delete the branch {branch_name}") | ||
| 63 | + print(f"Couldn't delete the branch {branch_name}") | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + def normalize_title(title, body): | ||
| 67 | + """Normalize the title if it spills over into the PR's body.""" | ||
| 68 | + if not (title.endswith('…') and body.startswith('…')): | ||
| 69 | + return title | ||
| 70 | + else: | ||
| 71 | + # Being paranoid in case \r\n is used. | ||
| 72 | + return title[:-1] + body[1:].partition('\r\n')[0] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments