From 7e606a28e4151550bd8c3be84cf099035d74ff19 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 21 Oct 2024 23:48:24 +0300 Subject: [PATCH 1/2] add --comments args --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 268dc1c..b54e6d8 100644 --- a/main.py +++ b/main.py @@ -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 / ') 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") 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) @@ -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) @@ -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: From f07125461bf5baf437d9ba1b0619a2ce63664a97 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Mon, 21 Oct 2024 23:49:38 +0300 Subject: [PATCH 2/2] log PR comments only if flag is set --- pull_requests_parser.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/pull_requests_parser.py b/pull_requests_parser.py index 5cb85bc..979d3eb 100644 --- a/pull_requests_parser.py +++ b/pull_requests_parser.py @@ -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: @@ -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) @@ -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: