Skip to content

Commit 91ec311

Browse files
authored
Merge pull request #33 from github/empty-repo-fix
Catch exception for empty repositories
2 parents 28c13be + 28adbe9 commit 91ec311

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

contributors.py

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# pylint: disable=broad-exception-caught
12
"""This file contains the main() and other functions needed to get contributor information from the organization or repository"""
23

4+
import sys
35
import env
46
import auth
57
import contributor_stats
@@ -123,39 +125,47 @@ def get_contributors(
123125
"""
124126
all_repo_contributors = repo.contributors()
125127
contributors = []
126-
for user in all_repo_contributors:
127-
# Ignore contributors with [bot] in their name
128-
if "[bot]" in user.login:
129-
continue
130-
131-
# Check if user has commits in the date range
132-
if start_date and end_date:
133-
user_commits = repo.commits(
134-
author=user.login, since=start_date, until=end_date
135-
)
136-
137-
# If the user has no commits in the date range, skip them
138-
try:
139-
next(user_commits)
140-
except StopIteration:
128+
try:
129+
for user in all_repo_contributors:
130+
# Ignore contributors with [bot] in their name
131+
if "[bot]" in user.login:
141132
continue
142133

143-
# Store the contributor information in a ContributorStats object
144-
if start_date and end_date:
145-
commit_url = f"https://github.com/{repo.full_name}/commits?author={user.login}&since={start_date}&until={end_date}"
146-
else:
147-
commit_url = (
148-
f"https://github.com/{repo.full_name}/commits?author={user.login}"
134+
# Check if user has commits in the date range
135+
if start_date and end_date:
136+
user_commits = repo.commits(
137+
author=user.login, since=start_date, until=end_date
138+
)
139+
140+
# If the user has no commits in the date range, skip them
141+
try:
142+
next(user_commits)
143+
except StopIteration:
144+
continue
145+
146+
# Store the contributor information in a ContributorStats object
147+
if start_date and end_date:
148+
commit_url = f"https://github.com/{repo.full_name}/commits?author={user.login}&since={start_date}&until={end_date}"
149+
else:
150+
commit_url = (
151+
f"https://github.com/{repo.full_name}/commits?author={user.login}"
152+
)
153+
contributor = contributor_stats.ContributorStats(
154+
user.login,
155+
False,
156+
user.avatar_url,
157+
user.contributions_count,
158+
commit_url,
159+
"",
149160
)
150-
contributor = contributor_stats.ContributorStats(
151-
user.login,
152-
False,
153-
user.avatar_url,
154-
user.contributions_count,
155-
commit_url,
156-
"",
161+
contributors.append(contributor)
162+
except Exception as e:
163+
print("Error getting contributors for repository: " + repo.full_name)
164+
print(
165+
"No more repositories will be processed. Please delete the (empty?) repository and try again."
157166
)
158-
contributors.append(contributor)
167+
print(e)
168+
sys.exit(1)
159169

160170
return contributors
161171

0 commit comments

Comments
 (0)