-
Notifications
You must be signed in to change notification settings - Fork 5
/
enqueue.py
36 lines (30 loc) · 1.14 KB
/
enqueue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import subprocess
from urllib.parse import urlparse
patch_url = os.environ.get('PATCH_URL').strip().replace('@','')
user = os.environ.get('USER')
authorized_users = ['dtcxzyw','nikic','preames','topperc','goldsteinn','fhahn','RKSimon','arsenm','antoniofrighetto','asb']
if user not in authorized_users:
print(f'User {user} is not authorized to submit tasks.')
exit(0)
try:
res = urlparse(patch_url)
if res.scheme != 'https':
print(f'Please provide a valid HTTPS URL: {patch_url}')
exit(0)
if res.netloc != 'github.com':
print(f'Please provide a valid GitHub URL: {patch_url}')
exit(0)
except:
print(f'Invalid patch URL: {patch_url}')
exit(0)
patch_name = patch_url.replace('https://github.com/llvm/llvm-project/pull/', '')
try:
subprocess.check_call(['sed', '-i', f's|export GITHUB_PATCH_ID=.*|export GITHUB_PATCH_ID={patch_url}|', 'scripts/setup_pre_commit_patch.sh'])
except Exception as e:
print(f'Failed to set up patch: {e}')
exit(0)
env_path = os.getenv('GITHUB_ENV')
with open(env_path, 'w') as f:
f.write(f"SHOULD_OPEN_PR=1\n")
f.write(f"PR_TITLE={patch_name}\n")