-
Notifications
You must be signed in to change notification settings - Fork 3
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
Линтер, тесты, сабмодули и многое другое #54
base: master
Are you sure you want to change the base?
Changes from all 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,77 @@ | ||
# 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 |
---|---|---|
|
@@ -4,19 +4,13 @@ | |
import json | ||
from time import sleep | ||
from git_logger import get_assignee_story | ||
from github import Github, Repository, GithubException, PullRequest | ||
from github import Github, Repository | ||
from constants import EMPTY_FIELD, TIMEDELTA, TIMEZONE, ISSUE_FIELDNAMES, COMMENT_BODY, COMMENT_CREATED_AT, COMMENT_AUTHOR_NAME, COMMENT_AUTHOR_LOGIN, COMMENT_AUTHOR_EMAIL | ||
|
||
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') | ||
|
||
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) | ||
|
||
|
||
|
@@ -74,10 +68,10 @@ def get_connected_pulls(issue_number, repo_owner, repo_name, token): | |
if (pull_request_data is not None): | ||
issues_data = pull_request_data["timelineItems"]["nodes"] | ||
for pulls in issues_data: | ||
if (pulls.get("CrossReferencedEvent") != None and pulls.get("CrossReferencedEvent").get( | ||
if (pulls.get("CrossReferencedEvent") is not None and pulls.get("CrossReferencedEvent").get( | ||
"url") not in list_url): | ||
list_url.append(pulls.get("CrossReferencedEvent").get("url")) | ||
if (pulls.get("ConnectedEvent") != None and pulls.get("ConnectedEvent").get("url") not in list_url): | ||
if (pulls.get("ConnectedEvent") is not None and pulls.get("ConnectedEvent").get("url") not in list_url): | ||
list_url.append(pulls.get("ConnectedEvent").get("url")) | ||
if (list_url == []): | ||
return 'Empty field' | ||
|
@@ -93,36 +87,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 +113,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: | ||
|
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.
А, это не то, в общем, исправлю)