Skip to content
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

Arg for on/off PR comments export #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def parse_args():
parser.add_argument('-l', '--list', type=str, required=True, help='Path to the file containing the list of repositories. Repositories should be separated by a line break. Names should be in the format <organization or owner>/<name> ')
parser.add_argument("--download_repos", type=str, help="path to downloaded repositories", default='./')
parser.add_argument('-o', '--out', type=str, required=True, help='output filename')
parser.add_argument("-C", "--comments", help="log comments for PR", action="store_true")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser.add_argument("-c", "--commits", help="log commits", action="store_true")
Мы точно хотим иметь флаг c и C? Может отказаться от короткого флага?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мб default=False или мы принудительно хотим заставлять пользователя вводить этот флаг?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+может добавить инфу о новом флаге во readme?

parser.add_argument('-s', '--start', type=str, required=False, help='start time', default='2000/01/01-00:00:00')
parser.add_argument('-f', '--finish', type=str, required=False, help='finish time', default='2400/01/01-00:00:00')
parser.add_argument('-b', '--branch', type=str, required=False, help='branch to select commits, by default use "default" repository branch, use "all" to get all commits from all branches', default=None)
Expand Down Expand Up @@ -60,6 +61,7 @@ def main():
csv_name = args.out
path_drepo = args.download_repos
fork_flag = args.forks_include
log_comments = args.comments

try:
client = git_logger.login(token=token)
Expand All @@ -74,7 +76,7 @@ def main():
if args.commits:
commits_parser.log_commits(client, working_repos, csv_name, start, finish, args.branch, fork_flag)
if args.pull_requests:
pull_requests_parser.log_pull_requests(client, working_repos, csv_name, token, start, finish, fork_flag)
pull_requests_parser.log_pull_requests(client, working_repos, csv_name, token, start, finish, fork_flag, log_comments)
if args.issues:
issues_parser.log_issues(client, working_repos, csv_name, token, start, finish, fork_flag)
if args.invites:
Expand Down
28 changes: 15 additions & 13 deletions pull_requests_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_related_issues(pull_request_number, repo_owner, repo_name, token):
return ';'.join(list_issues_url)


def log_repositories_pr(repository: Repository, csv_name, token, start, finish):
def log_repositories_pr(repository: Repository, csv_name, token, start, finish, log_comments=False):
for pull in repository.get_pulls(state='all'):
if pull.created_at.astimezone(pytz.timezone(TIMEZONE)) < start or pull.created_at.astimezone(
pytz.timezone(TIMEZONE)) > finish:
Expand Down Expand Up @@ -106,23 +106,25 @@ def log_repositories_pr(repository: Repository, csv_name, token, start, finish):
'milestone': get_info(pull.milestone, 'title')
}

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)
log_pr_to_csv(info, csv_name)
log_pr_to_stdout(info)
if log_comments:
comments = pull.get_comments()
if comments.totalCount > 0:
for comment in 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)
log_pr_to_csv(info, csv_name)
log_pr_to_stdout(info)
else:
log_pr_to_csv(info_tmp, csv_name)
log_pr_to_stdout(info_tmp)
sleep(TIMEDELTA)


def log_pull_requests(client: Github, working_repos, csv_name, token, start, finish, fork_flag):
def log_pull_requests(client: Github, working_repos, csv_name, token, start, finish, fork_flag, log_comments=False):
with open(csv_name, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(FIELDNAMES)
Expand All @@ -134,7 +136,7 @@ def log_pull_requests(client: Github, working_repos, csv_name, token, start, fin
if fork_flag:
for forked_repo in repo.get_forks():
print('=' * 20, "FORKED:", forked_repo.full_name, '=' * 20)
log_repositories_pr(forked_repo, csv_name, token, start, finish)
log_repositories_pr(forked_repo, csv_name, token, start, finish, log_comments)
sleep(TIMEDELTA)
sleep(TIMEDELTA)
except Exception as e:
Expand Down