Скрипт для проверок заданий на скайпро
Запускать так
python3 start-review.py https://github.com/EkaterinaDolgova/env_home_work8/pull/1
GitPython==3.1.27 | |
gitdb==4.0.9 | |
smmap==5.0.0 | |
PyGithub==1.55 | |
certifi==2021.10.8 | |
cffi==1.14.5 | |
charset-normalizer==2.0.12 | |
Deprecated==1.2.13 | |
idna==3.3 | |
pycparser==2.20 | |
PyJWT==2.3.0 | |
PyNaCl==1.5.0 | |
requests==2.27.1 | |
urllib3==1.26.9 | |
wrapt==1.14.0 |
import os | |
import subprocess | |
import sys | |
from urllib.parse import urlparse | |
from git import Repo | |
from github import Github | |
# Тут ваш токен | |
g = Github("") | |
def parse_github_pr_url(pr_url): | |
pr_parsed = urlparse(pr_url) | |
return { | |
"repo_name": pr_parsed[2].split("/")[1] + "/" + pr_parsed[2].split("/")[2], | |
"pr_number": int(pr_parsed[2].split("/")[4]) | |
} | |
if __name__ == '__main__': | |
tasks_path = "/tmp/skyeng/" | |
if os.path.exists(tasks_path): | |
subprocess.check_output(["rm", "-rf", tasks_path]) | |
else: | |
print("Can not delete the file as it doesn't exists") | |
parsed_pr = parse_github_pr_url(sys.argv[1]) | |
repo = g.get_repo(parsed_pr["repo_name"]) | |
pr = repo.get_pull(parsed_pr["pr_number"]) | |
repo_url = repo.raw_data["ssh_url"] | |
pr_branch = pr.head.raw_data["ref"] | |
local_repo_path = tasks_path + repo.name | |
local_repo = Repo.clone_from(repo_url, local_repo_path) | |
local_repo.git.checkout(pr_branch) | |
subprocess.check_output(["/usr/local/bin/idea", local_repo_path]) |