|
| 1 | +import subprocess, json, re, sys, urllib.request |
| 2 | + |
| 3 | +def get_owner_repo_and_token(): |
| 4 | + url = subprocess.check_output(["git","remote","get-url","origin"]).decode().strip() |
| 5 | + m = re.search(r"https://x-access-token:([^@]+)@github.com/([^/]+/[^/.]+)(?:\\.git)?$", url) |
| 6 | + if not m: |
| 7 | + return None, None |
| 8 | + token = m.group(1) |
| 9 | + owner_repo = m.group(2) |
| 10 | + return owner_repo, token |
| 11 | + |
| 12 | +def get_current_branch(): |
| 13 | + return subprocess.check_output(["git","rev-parse","--abbrev-ref","HEAD"]).decode().strip() |
| 14 | + |
| 15 | +owner_repo, token = get_owner_repo_and_token() |
| 16 | +branch = get_current_branch() |
| 17 | +if not owner_repo or not token: |
| 18 | + print("") |
| 19 | + sys.exit(0) |
| 20 | + |
| 21 | +payload = { |
| 22 | + "title": "docs: document Runtime.start() blocking behavior (#280)", |
| 23 | + "head": branch, |
| 24 | + "base": "main", |
| 25 | + "body": "This PR documents Runtime.start() blocking behavior and adds non-blocking examples. Fixes #280." |
| 26 | +} |
| 27 | + |
| 28 | +data = json.dumps(payload).encode() |
| 29 | +req = urllib.request.Request( |
| 30 | + f"https://api.github.com/repos/{owner_repo}/pulls", |
| 31 | + data=data, |
| 32 | + headers={ |
| 33 | + "Accept": "application/vnd.github+json", |
| 34 | + "Authorization": f"Bearer {token}", |
| 35 | + "Content-Type": "application/json", |
| 36 | + "X-GitHub-Api-Version": "2022-11-28", |
| 37 | + }, |
| 38 | + method="POST", |
| 39 | +) |
| 40 | +try: |
| 41 | + with urllib.request.urlopen(req) as resp: |
| 42 | + pr = json.loads(resp.read().decode()) |
| 43 | + print(pr.get("html_url", "")) |
| 44 | +except Exception as e: |
| 45 | + # On failure, print empty to fallback to compare URL construction outside |
| 46 | + print("") |
0 commit comments