-
Notifications
You must be signed in to change notification settings - Fork 3
Линтер, тесты, сабмодули и многое другое #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a8e6cf2
fb86017
66885f9
e03f766
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#For all | ||
EMPTY_FIELD = 'Empty field' | ||
TIMEDELTA = 0.05 | ||
TIMEZONE = 'Europe/Moscow' | ||
|
||
#Fieldnames | ||
REPO_NAME = 'repository name' | ||
AUTHOR_NAME = 'author name' | ||
AUTHOR_LOGIN = 'author login' | ||
AUTHOR_EMAIL = 'author email' | ||
DATE_AND_TIME = 'date and time' | ||
CHANGED_FILES = 'changed files' | ||
COMMIT_ID = 'commit id' | ||
BRANCH = 'branch' | ||
ADDED_LINES = 'added lines' | ||
DELETED_LINES = 'deleted lines' | ||
TITLE = 'title' | ||
ID = 'id' | ||
STATE = 'state' | ||
COMMIT_INTO = 'commit into' | ||
COMMIT_FROM = 'commit from' | ||
CREATED_AT = 'created at' | ||
CREATOR_NAME = 'creator name' | ||
CREATOR_LOGIN = 'creator login' | ||
CREATOR_EMAIL = 'creator email' | ||
COMMENT_BODY = 'comment body' | ||
COMMENT_CREATED_AT = 'comment created at' | ||
COMMENT_AUTHOR_NAME = 'comment author name' | ||
COMMENT_AUTHOR_LOGIN = 'comment author login' | ||
COMMENT_AUTHOR_EMAIL = 'comment author email' | ||
MERGER_NAME = 'merger name' | ||
MERGER_LOGIN = 'merger login' | ||
MERGER_EMAIL = 'merger email' | ||
SOURCE_BRANCH = 'source branch' | ||
TARGET_BRANCH = 'target branch' | ||
ASSIGNEE_STORY = 'assignee story' | ||
RELATED_ISSUES = 'related issues' | ||
LABELS = 'labels' | ||
MILESTONE = 'milestone' | ||
NUMBER = 'number' | ||
TASK = 'task' | ||
CLOSER_NAME = 'closer name' | ||
CLOSER_LOGIN = 'closer login' | ||
CLOSER_EMAIL = 'closer email' | ||
CLOSED_AT = 'closed at' | ||
CONNECTED_PULL_REQUESTS = 'connected pull requests' | ||
INVITED_LOGIN = 'invited login' | ||
INVITE_CREATION_DATE = 'invite creation date' | ||
INVITATION_URL = 'invitation url' | ||
PAGE = 'page' | ||
ACTION = 'action' | ||
REVISION_ID = 'revision id' | ||
|
||
#For commits | ||
FORKED_REPO = False | ||
ORIG_REPO_COMMITS = [] | ||
COMMIT_FIELDNAMES = (REPO_NAME, AUTHOR_NAME, AUTHOR_LOGIN, AUTHOR_EMAIL, DATE_AND_TIME, CHANGED_FILES, COMMIT_ID, BRANCH, ADDED_LINES, DELETED_LINES) | ||
|
||
#For pull requests | ||
PULL_REQUEST_FIELDNAMES = (REPO_NAME, TITLE, ID, STATE, COMMIT_INTO, COMMIT_FROM, CREATED_AT, CREATOR_NAME, CREATOR_LOGIN, CREATOR_EMAIL, | ||
CHANGED_FILES, COMMENT_BODY, COMMENT_CREATED_AT, COMMENT_AUTHOR_NAME, COMMENT_AUTHOR_LOGIN, COMMENT_AUTHOR_EMAIL, | ||
MERGER_NAME, MERGER_LOGIN, MERGER_EMAIL, SOURCE_BRANCH, TARGET_BRANCH, ASSIGNEE_STORY, RELATED_ISSUES, LABELS, MILESTONE) | ||
|
||
#For issues | ||
ISSUE_FIELDNAMES = (REPO_NAME, NUMBER, TITLE, STATE, TASK, CREATED_AT, CREATOR_NAME, CREATOR_LOGIN, CREATOR_EMAIL, CLOSER_NAME, CLOSER_LOGIN, | ||
CLOSER_EMAIL, CLOSED_AT, COMMENT_BODY, COMMENT_CREATED_AT, COMMENT_AUTHOR_NAME, COMMENT_AUTHOR_LOGIN, COMMENT_AUTHOR_EMAIL, | ||
ASSIGNEE_STORY, CONNECTED_PULL_REQUESTS, LABELS, MILESTONE) | ||
|
||
#For invites | ||
INVITE_FIELDNAMES = (REPO_NAME, INVITED_LOGIN, INVITE_CREATION_DATE, INVITATION_URL) | ||
|
||
#For wikis | ||
EMPTY_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" #Хэш пустого дерева для сравнения с первым коммитом. Способ был найден здесь: https://stackoverflow.com/questions/33916648/get-the-diff-details-of-first-commit-in-gitpython | ||
ACTIVITY = {"A": "Страница добавлена", "M": "Страница изменена", "D": "Страница удалена", "R": "Страница переименована"} | ||
ENG_ACTIVITY = {"A" : "Page added", "M" : "Page modified", "D" : "Page deleted", "R": "Page renamed"} | ||
WIKI_FIELDNAMES = (REPO_NAME, AUTHOR_NAME, AUTHOR_LOGIN, DATE_AND_TIME, PAGE, ACTION, REVISION_ID, ADDED_LINES, DELETED_LINES) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,11 @@ | |
from time import sleep | ||
from git_logger import get_assignee_story | ||
from github import Github, Repository, GithubException, PullRequest | ||
|
||
EMPTY_FIELD = 'Empty field' | ||
TIMEDELTA = 0.05 | ||
TIMEZONE = 'Europe/Moscow' | ||
FIELDNAMES = ('repository name', 'number', 'title', 'state', 'task', 'created at', 'creator name', 'creator login', | ||
'creator email', 'closer name', 'closer login', 'closer email', 'closed at', 'comment body', | ||
'comment created at', 'comment author name', 'comment author login', 'comment author email', | ||
'assignee story', 'connected pull requests', 'labels', 'milestone') | ||
from constants import EMPTY_FIELD, TIMEDELTA, TIMEZONE, ISSUE_FIELDNAMES, COMMENT_BODY, COMMENT_CREATED_AT, COMMENT_AUTHOR_NAME, COMMENT_AUTHOR_LOGIN, COMMENT_AUTHOR_EMAIL | ||
|
||
def log_issue_to_csv(info, csv_name): | ||
with open(csv_name, 'a', newline='') as file: | ||
writer = csv.DictWriter(file, fieldnames=FIELDNAMES) | ||
writer = csv.DictWriter(file, fieldnames=ISSUE_FIELDNAMES) | ||
writer.writerow(info) | ||
|
||
|
||
|
@@ -93,36 +86,21 @@ def log_repository_issues(repository: Repository, csv_name, token, start, finish | |
continue | ||
nvl = lambda val: val or EMPTY_FIELD | ||
get_info = lambda obj, attr: EMPTY_FIELD if obj is None else getattr(obj, attr) | ||
info_tmp = { | ||
'repository name': repository.full_name, 'number': issue.number, 'title': issue.title, | ||
'state': issue.state, 'task': issue.body, | ||
'created at': issue.created_at, | ||
'creator name': get_info(issue.user, 'name'), | ||
'creator login': get_info(issue.user, 'login'), | ||
'creator email': get_info(issue.user, 'email'), | ||
'closed at': nvl(issue.closed_at), | ||
'closer name': get_info(issue.closed_by, 'name'), | ||
'closer login': get_info(issue.closed_by, 'login'), | ||
'closer email': get_info(issue.closed_by, 'email'), | ||
'comment body': EMPTY_FIELD, | ||
'comment created at': EMPTY_FIELD, | ||
'comment author name': EMPTY_FIELD, | ||
'comment author login': EMPTY_FIELD, | ||
'comment author email': EMPTY_FIELD, | ||
'assignee story': get_assignee_story(issue), | ||
'connected pull requests': EMPTY_FIELD if issue.number is None else get_connected_pulls(issue.number, repository.owner, repository.name, token), | ||
'labels': EMPTY_FIELD if issue.labels is None else ';'.join([label.name for label in issue.labels]), | ||
'milestone': get_info(issue.milestone, 'title') | ||
} | ||
issue_data = [repository.full_name, issue.number, issue.title, issue.state, issue.body, issue.created_at, get_info(issue.user, 'name'), | ||
get_info(issue.user, 'login'), get_info(issue.user, 'email'), nvl(issue.closed_at), get_info(issue.closed_by, 'name'), | ||
get_info(issue.closed_by, 'login'), get_info(issue.closed_by, 'email'), EMPTY_FIELD, EMPTY_FIELD, EMPTY_FIELD, EMPTY_FIELD, | ||
EMPTY_FIELD, get_assignee_story(issue), EMPTY_FIELD if issue.number is None else get_connected_pulls(issue.number, repository.owner, repository.name, token), | ||
EMPTY_FIELD if issue.labels is None else ';'.join([label.name for label in issue.labels]), get_info(issue.milestone, 'title')] | ||
info_tmp = dict(zip(ISSUE_FIELDNAMES, issue_data)) | ||
Comment on lines
+90
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. подумать надо бы There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. давайте попробуем посмотреть в сторону датаклассов There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from dataclasses import dataclass, asdict
@dataclass(kw_only=True, frozen=True)
class A:
field1: str
field2: str
a = A(field1='qwe', field2='asd')
print(a, asdict(a))
-->
A(field1='qwe', field2='asd') {'field1': 'qwe', 'field2': 'asd'} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Понял, сделаю так |
||
|
||
if issue.get_comments().totalCount > 0: | ||
for comment in issue.get_comments(): | ||
info = info_tmp | ||
info['comment body'] = comment.body | ||
info['comment created at'] = comment.created_at | ||
info['comment author name'] = comment.user.name | ||
info['comment author login'] = comment.user.login | ||
info['comment author email'] = comment.user.email | ||
info[COMMENT_BODY] = comment.body | ||
info[COMMENT_CREATED_AT] = comment.created_at | ||
info[COMMENT_AUTHOR_NAME] = comment.user.name | ||
info[COMMENT_AUTHOR_LOGIN] = comment.user.login | ||
info[COMMENT_AUTHOR_EMAIL] = nvl(comment.user.email) | ||
log_issue_to_csv(info, csv_name) | ||
log_issue_to_stdout(info) | ||
else: | ||
|
@@ -134,7 +112,7 @@ def log_repository_issues(repository: Repository, csv_name, token, start, finish | |
def log_issues(client: Github, working_repo, csv_name, token, start, finish, fork_flag): | ||
with open(csv_name, 'w', newline='') as file: | ||
writer = csv.writer(file) | ||
writer.writerow(FIELDNAMES) | ||
writer.writerow(ISSUE_FIELDNAMES) | ||
|
||
for repo in working_repo: | ||
try: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,23 +5,15 @@ | |
from time import sleep | ||
from git_logger import get_assignee_story | ||
from github import Github, Repository, GithubException, PullRequest | ||
|
||
EMPTY_FIELD = 'Empty field' | ||
TIMEDELTA = 0.05 | ||
TIMEZONE = 'Europe/Moscow' | ||
FIELDNAMES = ('repository name', 'title', 'id', 'state', 'commit into', 'commit from', 'created at', 'creator name', | ||
'creator login', 'creator email', 'changed files', 'comment body', | ||
'comment created at', 'comment author name', 'comment author login', | ||
'comment author email', 'merger name', 'merger login', 'merger email', 'source branch', | ||
'target branch', 'assignee story', 'related issues', 'labels', 'milestone') | ||
from constants import EMPTY_FIELD, TIMEDELTA, TIMEZONE, PULL_REQUEST_FIELDNAMES, COMMENT_BODY, COMMENT_CREATED_AT, COMMENT_AUTHOR_NAME, COMMENT_AUTHOR_LOGIN, COMMENT_AUTHOR_EMAIL | ||
|
||
def log_pr_to_stdout(info): | ||
print(info) | ||
|
||
|
||
def log_pr_to_csv(info, csv_name): | ||
with open(csv_name, 'a', newline='') as file: | ||
writer = csv.DictWriter(file, fieldnames=FIELDNAMES) | ||
writer = csv.DictWriter(file, fieldnames=PULL_REQUEST_FIELDNAMES) | ||
writer.writerow(info) | ||
|
||
|
||
|
@@ -78,42 +70,22 @@ def log_repositories_pr(repository: Repository, csv_name, token, start, finish): | |
continue | ||
nvl = lambda val: val or EMPTY_FIELD | ||
get_info = lambda obj, attr: EMPTY_FIELD if obj is None else getattr(obj, attr) | ||
info_tmp = { | ||
'repository name': repository.full_name, | ||
'title': pull.title, | ||
'id': pull.number, | ||
'state': pull.state, | ||
'commit into': pull.base.label, | ||
'commit from': pull.head.label, | ||
'created at': pull.created_at, | ||
'creator name': nvl(pull.user.name), | ||
'creator login': pull.user.login, | ||
'creator email': pull.user.email, | ||
'changed files': '; '.join([file.filename for file in pull.get_files()]), | ||
'comment body': EMPTY_FIELD, | ||
'comment created at': EMPTY_FIELD, | ||
'comment author name': EMPTY_FIELD, | ||
'comment author login': EMPTY_FIELD, | ||
'comment author email': EMPTY_FIELD, | ||
'merger name': get_info(pull.merged_by, 'name'), | ||
'merger login': get_info(pull.merged_by, 'login'), | ||
'merger email': get_info(pull.merged_by, 'email'), | ||
'source branch': pull.head.ref, | ||
'target branch': pull.base.ref, | ||
'assignee story': get_assignee_story(pull), | ||
'related issues': EMPTY_FIELD if pull.issue_url is None else get_related_issues(pull.number, repository.owner, repository.name, token), | ||
'labels': EMPTY_FIELD if pull.labels is None else ';'.join([label.name for label in pull.labels]), | ||
'milestone': get_info(pull.milestone, 'title') | ||
} | ||
pr_data = [repository.full_name, pull.title, pull.number, pull.state, pull.base.label, pull.head.label, pull.created_at, | ||
nvl(pull.user.name), pull.user.login, pull.user.email, '; '.join([file.filename for file in pull.get_files()]), | ||
EMPTY_FIELD, EMPTY_FIELD, EMPTY_FIELD, EMPTY_FIELD, EMPTY_FIELD, get_info(pull.merged_by, 'name'), | ||
get_info(pull.merged_by, 'login'), get_info(pull.merged_by, 'email'), pull.head.ref, pull.base.ref, | ||
get_assignee_story(pull), EMPTY_FIELD if pull.issue_url is None else get_related_issues(pull.number, repository.owner, repository.name, token), | ||
EMPTY_FIELD if pull.labels is None else ';'.join([label.name for label in pull.labels]), get_info(pull.milestone, 'title')] | ||
info_tmp = dict(zip(PULL_REQUEST_FIELDNAMES, pr_data)) | ||
Comment on lines
+74
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не нравится так, ведь нужно помнить, что порядок важен... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. переделаю, загружу коммит с датаклассами, тегну |
||
|
||
if pull.get_comments().totalCount > 0: | ||
for comment in pull.get_comments(): | ||
info = info_tmp | ||
info['comment body'] = comment.body | ||
info['comment created at'] = comment.created_at | ||
info['comment author name'] = comment.user.name | ||
info['comment author login'] = comment.user.login | ||
info['comment author email'] = nvl(comment.user.email) | ||
info[COMMENT_BODY] = comment.body | ||
info[COMMENT_CREATED_AT] = comment.created_at | ||
info[COMMENT_AUTHOR_NAME] = comment.user.name | ||
info[COMMENT_AUTHOR_LOGIN] = comment.user.login | ||
info[COMMENT_AUTHOR_EMAIL] = nvl(comment.user.email) | ||
log_pr_to_csv(info, csv_name) | ||
log_pr_to_stdout(info) | ||
else: | ||
|
@@ -125,7 +97,7 @@ def log_repositories_pr(repository: Repository, csv_name, token, start, finish): | |
def log_pull_requests(client: Github, working_repos, csv_name, token, start, finish, fork_flag): | ||
with open(csv_name, 'w', newline='') as file: | ||
writer = csv.writer(file) | ||
writer.writerow(FIELDNAMES) | ||
writer.writerow(PULL_REQUEST_FIELDNAMES) | ||
|
||
for repo in working_repos: | ||
try: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
капсом == константа, а мы в нее что-то добавляем, а потом чистим?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
получения списка репо я планировал переделать, в git_logger'е сделаю такую функцию, чтобы возвращала словарь с ключами в виде репо, а значениями в виде списка форков
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А, это не то, в общем, исправлю)