From 4336fa3a6df58407482bca36fa34dd2210690b43 Mon Sep 17 00:00:00 2001 From: thehighestmath Date: Sat, 29 Mar 2025 18:56:45 +0300 Subject: [PATCH 1/6] add exit(1) --- commits_parser.py | 1 + invites_parser.py | 1 + issues_parser.py | 1 + pull_requests_parser.py | 1 + 4 files changed, 4 insertions(+) diff --git a/commits_parser.py b/commits_parser.py index e4e248f3..4d5eebdc 100644 --- a/commits_parser.py +++ b/commits_parser.py @@ -88,3 +88,4 @@ def log_commits( sleep(TIMEDELTA) except Exception as e: print(e) + exit(1) diff --git a/invites_parser.py b/invites_parser.py index 33848d8f..1198b4da 100644 --- a/invites_parser.py +++ b/invites_parser.py @@ -45,3 +45,4 @@ def log_invitations( log_repository_invitations(client, repo, csv_name) except Exception as e: print(e) + exit(1) diff --git a/issues_parser.py b/issues_parser.py index c10cea59..f607ae04 100644 --- a/issues_parser.py +++ b/issues_parser.py @@ -213,3 +213,4 @@ def log_issues( sleep(TIMEDELTA) except Exception as e: print("log_issues exception:", e) + exit(1) diff --git a/pull_requests_parser.py b/pull_requests_parser.py index fb9f59c6..983ef723 100644 --- a/pull_requests_parser.py +++ b/pull_requests_parser.py @@ -222,3 +222,4 @@ def log_pull_requests( sleep(TIMEDELTA) except Exception as e: print(e) + exit(1) From 61703159f6a707fedd7b20ca00ade483948573b0 Mon Sep 17 00:00:00 2001 From: thehighestmath Date: Sat, 29 Mar 2025 19:01:05 +0300 Subject: [PATCH 2/6] fix --- ForgejoRepoAPI.py | 17 +++-------------- GitHubRepoAPI.py | 19 ++++--------------- commits_parser.py | 2 +- interface_wrapper.py | 2 +- issues_parser.py | 4 ++-- main.py | 7 +++---- pull_requests_parser.py | 4 ++-- test_token_usage.py | 5 ++--- utils.py | 3 ++- wikipars.py | 1 - 10 files changed, 20 insertions(+), 44 deletions(-) diff --git a/ForgejoRepoAPI.py b/ForgejoRepoAPI.py index 3a386d60..dc05da6e 100644 --- a/ForgejoRepoAPI.py +++ b/ForgejoRepoAPI.py @@ -4,20 +4,9 @@ import isodate from pyforgejo import PyforgejoApi -from interface_wrapper import ( - Branch, - Comment, - Commit, - Contributor, - Invite, - IRepositoryAPI, - Issue, - PullRequest, - Repository, - User, - WikiPage, - logging, -) +from interface_wrapper import (Branch, Comment, Commit, Contributor, Invite, + IRepositoryAPI, Issue, PullRequest, Repository, + User, WikiPage, logging) class ForgejoRepoAPI(IRepositoryAPI): diff --git a/GitHubRepoAPI.py b/GitHubRepoAPI.py index a74a5efa..94b06ea1 100644 --- a/GitHubRepoAPI.py +++ b/GitHubRepoAPI.py @@ -1,20 +1,9 @@ -from interface_wrapper import ( - Branch, - Comment, - Commit, - Contributor, - Invite, - IRepositoryAPI, - Issue, - PullRequest, - Repository, - User, - WikiPage, - logging, -) - from github import Github, GithubException +from interface_wrapper import (Branch, Comment, Commit, Contributor, Invite, + IRepositoryAPI, Issue, PullRequest, Repository, + User, WikiPage, logging) + class GitHubRepoAPI(IRepositoryAPI): def __init__(self, client: Github): diff --git a/commits_parser.py b/commits_parser.py index 4d5eebdc..333a5af5 100644 --- a/commits_parser.py +++ b/commits_parser.py @@ -1,7 +1,7 @@ from dataclasses import asdict, dataclass +from datetime import datetime from time import sleep from typing import Generator -from datetime import datetime import pytz diff --git a/interface_wrapper.py b/interface_wrapper.py index c3df4342..aa28736d 100644 --- a/interface_wrapper.py +++ b/interface_wrapper.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from datetime import datetime -from github import Github, Auth +from github import Auth, Github from pyforgejo import PyforgejoApi # Настройка логирования diff --git a/issues_parser.py b/issues_parser.py index f607ae04..0d1d80c8 100644 --- a/issues_parser.py +++ b/issues_parser.py @@ -1,8 +1,8 @@ import json from dataclasses import asdict, dataclass +from datetime import datetime from time import sleep from typing import Generator -from datetime import datetime import pytz import requests @@ -171,7 +171,7 @@ def log_issue_and_comments(csv_name, issue_data: IssueData, comments): if comments: for comment in comments: comment_data = IssueDataWithComment( - **issue_data, + **asdict(issue_data), body=comment.body, created_at=str(comment.created_at), author_name=comment.author.username, diff --git a/main.py b/main.py index dc72a0bf..c2e72ac5 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,14 @@ import argparse import traceback -import git_logger -import export_sheets import commits_parser import contributors_parser -import pull_requests_parser +import export_sheets +import git_logger import invites_parser import issues_parser +import pull_requests_parser import wikipars - from utils import parse_time diff --git a/pull_requests_parser.py b/pull_requests_parser.py index 983ef723..60c474b3 100644 --- a/pull_requests_parser.py +++ b/pull_requests_parser.py @@ -1,8 +1,8 @@ import json from dataclasses import asdict, dataclass +from datetime import datetime from time import sleep from typing import Generator -from datetime import datetime import pytz import requests @@ -165,7 +165,7 @@ def get_info(obj, attr): if comments: for comment in comments: comment_data = PullRequestDataWithComment( - **pr_data, + **asdict(pr_data), body=comment.body, created_at=str(comment.created_at), author_name=comment.author.name, diff --git a/test_token_usage.py b/test_token_usage.py index ac6d516f..92e6766f 100644 --- a/test_token_usage.py +++ b/test_token_usage.py @@ -1,10 +1,9 @@ -import unittest import argparse import sys - -from main import run +import unittest import git_logger +from main import run def parse_args(args): diff --git a/utils.py b/utils.py index 9088b574..62ba46a8 100644 --- a/utils.py +++ b/utils.py @@ -1,8 +1,9 @@ import csv from datetime import datetime + import pytz -from constants import MIN_SIDE_PADDING, SIDE_WHITE_SPACES, TITLE_LEN, TIMEZONE +from constants import MIN_SIDE_PADDING, SIDE_WHITE_SPACES, TIMEZONE, TITLE_LEN class logger: diff --git a/wikipars.py b/wikipars.py index fbb86425..67318c25 100644 --- a/wikipars.py +++ b/wikipars.py @@ -4,7 +4,6 @@ from git import Repo, exc from constants import WIKI_FIELDNAMES - from utils import logger From 9977c01decbc3f9c56b0dca4a7814a5339956995 Mon Sep 17 00:00:00 2001 From: thehighestmath Date: Sat, 29 Mar 2025 19:08:47 +0300 Subject: [PATCH 3/6] upgrade test --- list.txt | 1 + requirements.txt | 3 +- test_token_usage.py | 73 ++++++++++++--------------------------------- 3 files changed, 22 insertions(+), 55 deletions(-) create mode 100644 list.txt diff --git a/list.txt b/list.txt new file mode 100644 index 00000000..8c8f035d --- /dev/null +++ b/list.txt @@ -0,0 +1 @@ +moevm/github_repo_commitment_calc diff --git a/requirements.txt b/requirements.txt index 44ebea63..75446911 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ pandas==2.2.3 pytz==2024.2 requests==2.32.3 pyforgejo==2.0.0 -isodate==0.7.2 \ No newline at end of file +isodate==0.7.2 +unittest-parametrize==1.6.0 diff --git a/test_token_usage.py b/test_token_usage.py index 92e6766f..eb41a138 100644 --- a/test_token_usage.py +++ b/test_token_usage.py @@ -5,6 +5,10 @@ import git_logger from main import run +from unittest_parametrize import parametrize +from unittest_parametrize import ParametrizedTestCase +from unittest_parametrize import param + def parse_args(args): parser = argparse.ArgumentParser() @@ -24,7 +28,7 @@ def parse_args(args): return parser.parse_args(args) -class TestTokenUsage(unittest.TestCase): +class TestTokenUsage(ParametrizedTestCase): def setUp(self): test_args = parse_args(sys.argv[1:]) self.tokens = [test_args.tt1, test_args.tt2] @@ -78,60 +82,21 @@ def _get_usage(self, binded_repos, clients): return limit_start, limit_finish - def test_commits_parser(self): - self.args.commits = True - for i in range(2): - clients = git_logger.Clients( - "github", self._change_tokens_order(self.tokens, i) - ) - binded_repos = git_logger.get_next_binded_repo(clients, [self.repo]) - - limit_start, limit_finish = self._get_usage(binded_repos, clients) - - self.assertTrue(self._is_only_one_token_used(limit_start, limit_finish)) - self.assertTrue(self._is_max_token_used(limit_start, limit_finish)) - - def test_contributors_parser(self): - self.args.contributors = True - for i in range(2): - clients = git_logger.Clients( - "github", self._change_tokens_order(self.tokens, i) - ) - binded_repos = git_logger.get_next_binded_repo(clients, [self.repo]) - - limit_start, limit_finish = self._get_usage(binded_repos, clients) - - self.assertTrue(self._is_only_one_token_used(limit_start, limit_finish)) - self.assertTrue(self._is_max_token_used(limit_start, limit_finish)) - - def test_issues_parser(self): - self.args.issues = True - for i in range(2): - clients = git_logger.Clients( - "github", self._change_tokens_order(self.tokens, i) - ) - binded_repos = git_logger.get_next_binded_repo(clients, [self.repo]) - - limit_start, limit_finish = self._get_usage(binded_repos, clients) - - self.assertTrue(self._is_only_one_token_used(limit_start, limit_finish)) - self.assertTrue(self._is_max_token_used(limit_start, limit_finish)) - - def test_invites_parser(self): - self.args.invites = True - for i in range(2): - clients = git_logger.Clients( - "github", self._change_tokens_order(self.tokens, i) - ) - binded_repos = git_logger.get_next_binded_repo(clients, [self.repo]) - - limit_start, limit_finish = self._get_usage(binded_repos, clients) - - self.assertTrue(self._is_only_one_token_used(limit_start, limit_finish)) - self.assertTrue(self._is_max_token_used(limit_start, limit_finish)) + @parametrize( + 'args', + [ + param({'commits': True}, id='commits'), + param({'contributors': True}, id='contributors'), + param({'issues': True}, id='issues'), + param({'invites': True}, id='invites'), + param({'pull_requests': True}, id='pull_requests'), + ], + ) + def test_commits_parser(self, args: dict[str, bool]): + # patch args + for k, v in args.items(): + setattr(self.args, k, v) - def test_pull_requests_parser(self): - self.args.pull_requests = True for i in range(2): clients = git_logger.Clients( "github", self._change_tokens_order(self.tokens, i) From a795752cc90e720c23cd226366463827a5c31795 Mon Sep 17 00:00:00 2001 From: thehighestmath Date: Sat, 29 Mar 2025 19:13:34 +0300 Subject: [PATCH 4/6] fix --- issues_parser.py | 20 ++++++++++---------- pull_requests_parser.py | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/issues_parser.py b/issues_parser.py index 0d1d80c8..aefede77 100644 --- a/issues_parser.py +++ b/issues_parser.py @@ -36,11 +36,11 @@ class IssueData: @dataclass(kw_only=True, frozen=True) class IssueDataWithComment(IssueData): - body: str = '' - created_at: str = '' - author_name: str = '' - author_login: str = '' - author_email: str = '' + comment_body: str = '' + comment_created_at: str = '' + comment_author_name: str = '' + comment_author_login: str = '' + comment_author_email: str = '' def get_connected_pulls(issue_number, repo_owner, repo_name, token): @@ -172,11 +172,11 @@ def log_issue_and_comments(csv_name, issue_data: IssueData, comments): for comment in comments: comment_data = IssueDataWithComment( **asdict(issue_data), - body=comment.body, - created_at=str(comment.created_at), - author_name=comment.author.username, - author_login=comment.author.login, - author_email=comment.author.email, + comment_body=comment.body, + comment_created_at=str(comment.created_at), + comment_author_name=comment.author.username, + comment_author_login=comment.author.login, + comment_author_email=comment.author.email, ) comment_data = asdict(comment_data) diff --git a/pull_requests_parser.py b/pull_requests_parser.py index 60c474b3..2b23df03 100644 --- a/pull_requests_parser.py +++ b/pull_requests_parser.py @@ -39,11 +39,11 @@ class PullRequestData: @dataclass(kw_only=True, frozen=True) class PullRequestDataWithComment(PullRequestData): - body: str = '' - created_at: str = '' - author_name: str = '' - author_login: str = '' - author_email: str = '' + comment_body: str = '' + comment_created_at: str = '' + comment_author_name: str = '' + comment_author_login: str = '' + comment_author_email: str = '' def get_related_issues(pull_request_number, repo_owner, repo_name, token): @@ -166,11 +166,11 @@ def get_info(obj, attr): for comment in comments: comment_data = PullRequestDataWithComment( **asdict(pr_data), - body=comment.body, - created_at=str(comment.created_at), - author_name=comment.author.name, - author_login=comment.author.login, - author_email=nvl(comment.author.email), + comment_body=comment.body, + comment_created_at=str(comment.created_at), + comment_author_name=comment.author.name, + comment_author_login=comment.author.login, + comment_author_email=nvl(comment.author.email), ) comment_data = asdict(comment_data) From d77c24d583d9df8da3e828d56977beeed1fbd2b6 Mon Sep 17 00:00:00 2001 From: thehighestmath Date: Sat, 29 Mar 2025 19:15:02 +0300 Subject: [PATCH 5/6] f --- ForgejoRepoAPI.py | 17 ++++++++++++++--- GitHubRepoAPI.py | 17 ++++++++++++++--- test_token_usage.py | 6 ++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ForgejoRepoAPI.py b/ForgejoRepoAPI.py index dc05da6e..3a386d60 100644 --- a/ForgejoRepoAPI.py +++ b/ForgejoRepoAPI.py @@ -4,9 +4,20 @@ import isodate from pyforgejo import PyforgejoApi -from interface_wrapper import (Branch, Comment, Commit, Contributor, Invite, - IRepositoryAPI, Issue, PullRequest, Repository, - User, WikiPage, logging) +from interface_wrapper import ( + Branch, + Comment, + Commit, + Contributor, + Invite, + IRepositoryAPI, + Issue, + PullRequest, + Repository, + User, + WikiPage, + logging, +) class ForgejoRepoAPI(IRepositoryAPI): diff --git a/GitHubRepoAPI.py b/GitHubRepoAPI.py index 94b06ea1..576021bb 100644 --- a/GitHubRepoAPI.py +++ b/GitHubRepoAPI.py @@ -1,8 +1,19 @@ from github import Github, GithubException -from interface_wrapper import (Branch, Comment, Commit, Contributor, Invite, - IRepositoryAPI, Issue, PullRequest, Repository, - User, WikiPage, logging) +from interface_wrapper import ( + Branch, + Comment, + Commit, + Contributor, + Invite, + IRepositoryAPI, + Issue, + PullRequest, + Repository, + User, + WikiPage, + logging, +) class GitHubRepoAPI(IRepositoryAPI): diff --git a/test_token_usage.py b/test_token_usage.py index eb41a138..81148248 100644 --- a/test_token_usage.py +++ b/test_token_usage.py @@ -2,13 +2,11 @@ import sys import unittest +from unittest_parametrize import ParametrizedTestCase, param, parametrize + import git_logger from main import run -from unittest_parametrize import parametrize -from unittest_parametrize import ParametrizedTestCase -from unittest_parametrize import param - def parse_args(args): parser = argparse.ArgumentParser() From 08d5f07b223ea64fa9a68f4b838e4d354f700cbc Mon Sep 17 00:00:00 2001 From: thehighestmath Date: Sat, 29 Mar 2025 19:21:18 +0300 Subject: [PATCH 6/6] f --- list.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 list.txt diff --git a/list.txt b/list.txt deleted file mode 100644 index 8c8f035d..00000000 --- a/list.txt +++ /dev/null @@ -1 +0,0 @@ -moevm/github_repo_commitment_calc