From cb667e6422ea0acea2dcfa15c4550adf85856793 Mon Sep 17 00:00:00 2001 From: Topher Lamey Date: Mon, 9 Sep 2024 11:31:05 -0600 Subject: [PATCH] Add commit url output option --- README.md | 3 +++ github-repo-committers.py | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2139ba0..9290acd 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ committers at the end. ```console usage: github-repo-committers.py [-h] --access_token ACCESS_TOKEN [--org_name ORG_NAME] [--max_repos MAX_REPOS] [--repo_name REPO_NAME] + [--commit_urls | --no-commit_urls] [--ghe_hostname GHE_HOSTNAME] [--count-by {login,name,email}] Count developers on a GitHub repo or in a GitHub Organization for the last 90 days @@ -110,6 +111,8 @@ optional arguments: How many repos in the Org do you want to inspect? Default=100 --repo_name REPO_NAME Name of the repo you want to check in 'org/repo' format + --commit_urls, --no-commit_urls + Controls outputting commit URLs, defaults to '--no-commit-urls' --ghe_hostname GHE_HOSTNAME If you use GHE, this is the hostname part of the URL --count-by {username,name,email} diff --git a/github-repo-committers.py b/github-repo-committers.py index 675b4cd..dca04dc 100755 --- a/github-repo-committers.py +++ b/github-repo-committers.py @@ -9,6 +9,12 @@ import re +class CommitterInfo: + def __init__(self, date, commit_url): + self.date = date + self.commit_url = commit_url + + def parse_args(): parser = argparse.ArgumentParser(description="Count developers on a GitHub repo or in a GitHub Organization " "for the last 90 days") @@ -18,6 +24,9 @@ def parse_args(): parser.add_argument('--max_repos', default=100, type=str, help="How many repos in the Org do you want " "to inspect? Default=100") parser.add_argument('--repo_name', type=str, help="Name of the repo you want to check in 'org/repo' format") + parser.add_argument('--commit_urls', type=bool, + help="Controls outputting commit URLs, defaults to '--no-commit-urls'", + default=False, action=argparse.BooleanOptionalAction) parser.add_argument('--ghe_hostname', type=str, help="If you use GHE, this is the hostname part of the URL") parser.add_argument('--count-by', default="username", choices=["username", "name", "email"], help="How to count contributors. Either by GitHub username, display name or email address of " @@ -125,7 +134,8 @@ def repo_details(repo_name, count_by): author = author_email if author not in repo_authors: - repo_authors[author] = commit.raw_data['commit']['committer']['date'] + repo_authors[author] = CommitterInfo(commit.raw_data['commit']['committer']['date'], + commit.raw_data['html_url']) else: break @@ -134,8 +144,11 @@ def repo_details(repo_name, count_by): f' contributor(s) over 90 days with the earliest commit' f' on {earliest_commit}.') print('Here is the list of Github contributors:') - for author, commit_date in repo_authors.items(): - print(author + ': ' + commit_date) + for author, committer_info in repo_authors.items(): + print(author + ': ' + committer_info.date, end='') + if args.commit_urls: + print(',', committer_info.commit_url, end='') + print() print('\n') return repo_authors