Skip to content

Commit 95d050f

Browse files
add exit(1) during exceptions (#108)
1 parent 7490ddf commit 95d050f

File tree

11 files changed

+57
-91
lines changed

11 files changed

+57
-91
lines changed

GitHubRepoAPI.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from github import Github, GithubException
2+
13
from interface_wrapper import (
24
Branch,
35
Comment,
@@ -13,8 +15,6 @@
1315
logging,
1416
)
1517

16-
from github import Github, GithubException
17-
1818

1919
class GitHubRepoAPI(IRepositoryAPI):
2020
def __init__(self, client: Github):

commits_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dataclasses import asdict, dataclass
2+
from datetime import datetime
23
from time import sleep
34
from typing import Generator
4-
from datetime import datetime
55

66
import pytz
77

@@ -88,3 +88,4 @@ def log_commits(
8888
sleep(TIMEDELTA)
8989
except Exception as e:
9090
print(e)
91+
exit(1)

interface_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dataclasses import dataclass
44
from datetime import datetime
55

6-
from github import Github, Auth
6+
from github import Auth, Github
77
from pyforgejo import PyforgejoApi
88

99
# Настройка логирования

invites_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ def log_invitations(
4545
log_repository_invitations(client, repo, csv_name)
4646
except Exception as e:
4747
print(e)
48+
exit(1)

issues_parser.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import json
22
from dataclasses import asdict, dataclass
3+
from datetime import datetime
34
from time import sleep
45
from typing import Generator
5-
from datetime import datetime
66

77
import pytz
88
import requests
@@ -36,11 +36,11 @@ class IssueData:
3636

3737
@dataclass(kw_only=True, frozen=True)
3838
class IssueDataWithComment(IssueData):
39-
body: str = ''
40-
created_at: str = ''
41-
author_name: str = ''
42-
author_login: str = ''
43-
author_email: str = ''
39+
comment_body: str = ''
40+
comment_created_at: str = ''
41+
comment_author_name: str = ''
42+
comment_author_login: str = ''
43+
comment_author_email: str = ''
4444

4545

4646
def get_connected_pulls(issue_number, repo_owner, repo_name, token):
@@ -171,12 +171,12 @@ def log_issue_and_comments(csv_name, issue_data: IssueData, comments):
171171
if comments:
172172
for comment in comments:
173173
comment_data = IssueDataWithComment(
174-
**issue_data,
175-
body=comment.body,
176-
created_at=str(comment.created_at),
177-
author_name=comment.author.username,
178-
author_login=comment.author.login,
179-
author_email=comment.author.email,
174+
**asdict(issue_data),
175+
comment_body=comment.body,
176+
comment_created_at=str(comment.created_at),
177+
comment_author_name=comment.author.username,
178+
comment_author_login=comment.author.login,
179+
comment_author_email=comment.author.email,
180180
)
181181
comment_data = asdict(comment_data)
182182

@@ -213,3 +213,4 @@ def log_issues(
213213
sleep(TIMEDELTA)
214214
except Exception as e:
215215
print("log_issues exception:", e)
216+
exit(1)

main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import argparse
22
import traceback
33

4-
import git_logger
5-
import export_sheets
64
import commits_parser
75
import contributors_parser
8-
import pull_requests_parser
6+
import export_sheets
7+
import git_logger
98
import invites_parser
109
import issues_parser
10+
import pull_requests_parser
1111
import wikipars
12-
1312
from utils import parse_time
1413

1514

pull_requests_parser.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import json
22
from dataclasses import asdict, dataclass
3+
from datetime import datetime
34
from time import sleep
45
from typing import Generator
5-
from datetime import datetime
66

77
import pytz
88
import requests
@@ -39,11 +39,11 @@ class PullRequestData:
3939

4040
@dataclass(kw_only=True, frozen=True)
4141
class PullRequestDataWithComment(PullRequestData):
42-
body: str = ''
43-
created_at: str = ''
44-
author_name: str = ''
45-
author_login: str = ''
46-
author_email: str = ''
42+
comment_body: str = ''
43+
comment_created_at: str = ''
44+
comment_author_name: str = ''
45+
comment_author_login: str = ''
46+
comment_author_email: str = ''
4747

4848

4949
def get_related_issues(pull_request_number, repo_owner, repo_name, token):
@@ -165,12 +165,12 @@ def get_info(obj, attr):
165165
if comments:
166166
for comment in comments:
167167
comment_data = PullRequestDataWithComment(
168-
**pr_data,
169-
body=comment.body,
170-
created_at=str(comment.created_at),
171-
author_name=comment.author.name,
172-
author_login=comment.author.login,
173-
author_email=nvl(comment.author.email),
168+
**asdict(pr_data),
169+
comment_body=comment.body,
170+
comment_created_at=str(comment.created_at),
171+
comment_author_name=comment.author.name,
172+
comment_author_login=comment.author.login,
173+
comment_author_email=nvl(comment.author.email),
174174
)
175175
comment_data = asdict(comment_data)
176176

@@ -222,3 +222,4 @@ def log_pull_requests(
222222
sleep(TIMEDELTA)
223223
except Exception as e:
224224
print(e)
225+
exit(1)

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pandas==2.2.3
55
pytz==2024.2
66
requests==2.32.3
77
pyforgejo==2.0.0
8-
isodate==0.7.2
8+
isodate==0.7.2
9+
unittest-parametrize==1.6.0

test_token_usage.py

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import unittest
21
import argparse
32
import sys
3+
import unittest
44

5-
from main import run
5+
from unittest_parametrize import ParametrizedTestCase, param, parametrize
66

77
import git_logger
8+
from main import run
89

910

1011
def parse_args(args):
@@ -25,7 +26,7 @@ def parse_args(args):
2526
return parser.parse_args(args)
2627

2728

28-
class TestTokenUsage(unittest.TestCase):
29+
class TestTokenUsage(ParametrizedTestCase):
2930
def setUp(self):
3031
test_args = parse_args(sys.argv[1:])
3132
self.tokens = [test_args.tt1, test_args.tt2]
@@ -79,60 +80,21 @@ def _get_usage(self, binded_repos, clients):
7980

8081
return limit_start, limit_finish
8182

82-
def test_commits_parser(self):
83-
self.args.commits = True
84-
for i in range(2):
85-
clients = git_logger.Clients(
86-
"github", self._change_tokens_order(self.tokens, i)
87-
)
88-
binded_repos = git_logger.get_next_binded_repo(clients, [self.repo])
89-
90-
limit_start, limit_finish = self._get_usage(binded_repos, clients)
91-
92-
self.assertTrue(self._is_only_one_token_used(limit_start, limit_finish))
93-
self.assertTrue(self._is_max_token_used(limit_start, limit_finish))
94-
95-
def test_contributors_parser(self):
96-
self.args.contributors = True
97-
for i in range(2):
98-
clients = git_logger.Clients(
99-
"github", self._change_tokens_order(self.tokens, i)
100-
)
101-
binded_repos = git_logger.get_next_binded_repo(clients, [self.repo])
102-
103-
limit_start, limit_finish = self._get_usage(binded_repos, clients)
104-
105-
self.assertTrue(self._is_only_one_token_used(limit_start, limit_finish))
106-
self.assertTrue(self._is_max_token_used(limit_start, limit_finish))
107-
108-
def test_issues_parser(self):
109-
self.args.issues = True
110-
for i in range(2):
111-
clients = git_logger.Clients(
112-
"github", self._change_tokens_order(self.tokens, i)
113-
)
114-
binded_repos = git_logger.get_next_binded_repo(clients, [self.repo])
115-
116-
limit_start, limit_finish = self._get_usage(binded_repos, clients)
117-
118-
self.assertTrue(self._is_only_one_token_used(limit_start, limit_finish))
119-
self.assertTrue(self._is_max_token_used(limit_start, limit_finish))
120-
121-
def test_invites_parser(self):
122-
self.args.invites = True
123-
for i in range(2):
124-
clients = git_logger.Clients(
125-
"github", self._change_tokens_order(self.tokens, i)
126-
)
127-
binded_repos = git_logger.get_next_binded_repo(clients, [self.repo])
128-
129-
limit_start, limit_finish = self._get_usage(binded_repos, clients)
130-
131-
self.assertTrue(self._is_only_one_token_used(limit_start, limit_finish))
132-
self.assertTrue(self._is_max_token_used(limit_start, limit_finish))
83+
@parametrize(
84+
'args',
85+
[
86+
param({'commits': True}, id='commits'),
87+
param({'contributors': True}, id='contributors'),
88+
param({'issues': True}, id='issues'),
89+
param({'invites': True}, id='invites'),
90+
param({'pull_requests': True}, id='pull_requests'),
91+
],
92+
)
93+
def test_commits_parser(self, args: dict[str, bool]):
94+
# patch args
95+
for k, v in args.items():
96+
setattr(self.args, k, v)
13397

134-
def test_pull_requests_parser(self):
135-
self.args.pull_requests = True
13698
for i in range(2):
13799
clients = git_logger.Clients(
138100
"github", self._change_tokens_order(self.tokens, i)

utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import csv
22
from datetime import datetime
3+
34
import pytz
45

5-
from constants import MIN_SIDE_PADDING, SIDE_WHITE_SPACES, TITLE_LEN, TIMEZONE
6+
from constants import MIN_SIDE_PADDING, SIDE_WHITE_SPACES, TIMEZONE, TITLE_LEN
67

78

89
class logger:

0 commit comments

Comments
 (0)