-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit_logger.py
49 lines (42 loc) · 1.61 KB
/
git_logger.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
44
45
46
47
48
49
from github import Github, GithubException, PullRequest
from time import sleep
TIMEDELTA = 0.05
TIMEZONE = 'Europe/Moscow'
def login(token):
client = Github(login_or_token=token)
try:
client.get_user().login
except GithubException as err:
print(f'Github: Connect: error {err.data}')
print('Github: Connect: user could not be authenticated please try again.')
raise exit(1)
else:
return client
def get_next_repo(client: Github, repositories):
with open(repositories, 'r') as file:
list_repos = [x for x in file.read().split('\n') if x]
print(list_repos)
for repo_name in list_repos:
try:
repo = client.get_repo(repo_name)
except GithubException as err:
print(f'Github: Connect: error {err.data}')
print(f'Github: Connect: failed to load repository "{repo_name}"')
exit(1)
else:
yield repo
def get_assignee_story(github_object):
assignee_result = ""
events = github_object.get_issue_events() if type(
github_object) is PullRequest.PullRequest else github_object.get_events()
for event in events:
if event.event in ["assigned", "unassigned"]:
date = event.created_at
assigner = github_object.user.login
assignee = event.assignee.login
assignee_result += f"{date}: {assigner} -"
if event.event == "unassigned":
assignee_result += "/"
assignee_result += f"> {assignee}; "
sleep(TIMEDELTA)
return assignee_result