Archive / std.lint.repo

ru en cn

с начала прошло: 9105 д. 05:50
страница обновлена: 05.12.2024 05:49

std.lint.repo: lint_repo.py

import re
import requests
import sys

with open(sys.argv[1]) as f:
    commit_url = f.readline()

github_acceptable_name_re = r'[a-zA-Z][a-zA-Z\d+\-_.]+'
git_url_re = re.compile(
    fr'^https://github.com/({github_acceptable_name_re})/({github_acceptable_name_re})/commit/([0-9a-f]+)$')

m = git_url_re.match(commit_url)
if not m:
    print('Not a github commit url')
    exit(1)

(author, repo_name, sha) = m.groups()
r = requests.get(f'https://api.github.com/repos/{author}/{repo_name}/git/commits/{sha}')
if not r:
    print('Error retrieving:', r.status_code)
    exit(1)

j = r.json()
if j['sha'] != sha:
    print('Not found?', j.get('message', ''))
    exit(1)

print('ok:', j['message'])
Дальневосточный федеральный университет