Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GitHubRepoAPI.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from github import Github, GithubException

from interface_wrapper import (
Branch,
Comment,
Expand All @@ -13,8 +15,6 @@
logging,
)

from github import Github, GithubException


class GitHubRepoAPI(IRepositoryAPI):
def __init__(self, client: Github):
Expand Down
3 changes: 2 additions & 1 deletion commits_parser.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -88,3 +88,4 @@ def log_commits(
sleep(TIMEDELTA)
except Exception as e:
print(e)
exit(1)
2 changes: 1 addition & 1 deletion interface_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

# Настройка логирования
Expand Down
1 change: 1 addition & 0 deletions invites_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ def log_invitations(
log_repository_invitations(client, repo, csv_name)
except Exception as e:
print(e)
exit(1)
25 changes: 13 additions & 12 deletions issues_parser.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -171,12 +171,12 @@ def log_issue_and_comments(csv_name, issue_data: IssueData, comments):
if comments:
for comment in comments:
comment_data = IssueDataWithComment(
**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,
**asdict(issue_data),
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)

Expand Down Expand Up @@ -213,3 +213,4 @@ def log_issues(
sleep(TIMEDELTA)
except Exception as e:
print("log_issues exception:", e)
exit(1)
7 changes: 3 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
25 changes: 13 additions & 12 deletions pull_requests_parser.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -165,12 +165,12 @@ def get_info(obj, attr):
if comments:
for comment in comments:
comment_data = PullRequestDataWithComment(
**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),
**asdict(pr_data),
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)

Expand Down Expand Up @@ -222,3 +222,4 @@ def log_pull_requests(
sleep(TIMEDELTA)
except Exception as e:
print(e)
exit(1)
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pandas==2.2.3
pytz==2024.2
requests==2.32.3
pyforgejo==2.0.0
isodate==0.7.2
isodate==0.7.2
unittest-parametrize==1.6.0
74 changes: 18 additions & 56 deletions test_token_usage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import unittest
import argparse
import sys
import unittest

from main import run
from unittest_parametrize import ParametrizedTestCase, param, parametrize

import git_logger
from main import run


def parse_args(args):
Expand All @@ -25,7 +26,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]
Expand Down Expand Up @@ -79,60 +80,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)
Expand Down
3 changes: 2 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 0 additions & 1 deletion wikipars.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from git import Repo, exc

from constants import WIKI_FIELDNAMES

from utils import logger


Expand Down