-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub_client.py
43 lines (34 loc) · 1.4 KB
/
github_client.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
37
38
39
40
41
42
43
from http import HTTPStatus
from github import Github
import requests
class GithubAPI:
"""Получение данных с сервиса Github."""
def __init__(self, token=None, organization=None, repo=None):
self.token = token
self.git = Github(token)
self.org = self.git.get_organization(organization)
self.repo = self.org.get_repo(repo)
self.request_headers = {
"Accept": "application/vnd.github.antiope-preview+json",
"Authorization": "token " + token,
}
def get_token(self):
return self.token
def get_repo_name(self):
return self.repo.name
def repo_is_private(self):
return self.repo.private
def get_checks_info(self, commit_sha):
url = ('https://api.github.com/repos/' + self.org.name + '/' +
self.repo.name + '/commits/' + commit_sha +
'/check-runs')
response = requests.get(url, headers=self.request_headers)
check_runs = None
if response.status_code == HTTPStatus.OK:
check_runs = response.json()['check_runs']
return check_runs
def get_latest_commit_sha(self, branch='master'):
"""Последний коммит в ветке."""
branch = self.repo.get_branch(branch)
latest_commit = branch.commit
return latest_commit.sha