Skip to content

Commit

Permalink
Update GitStats (#57)
Browse files Browse the repository at this point in the history
* Remove pull request and issue stats
  • Loading branch information
R055A authored Jul 4, 2024
1 parent 46323af commit e7bc8b8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_code_convention.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
# Use Ruff to lint all files
- name: Ruff lint
run: ruff --output-format=github .
run: ruff check --output-format=github .

# Use Black to check format for all files
- name: Black lint
Expand Down
30 changes: 15 additions & 15 deletions src/generate_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,21 @@ async def generate_overview(self) -> None:
"{{ views_from_date }}", f"Repo views (as of {views_from})", output
)

pull_requests = f"{await self.__stats.pull_requests:,}"
pull_requests = (
pull_requests
if len(str(pull_requests)) < TXT_SPACER_MAX_LEN
else add_unit(pull_requests)
)
issues = f"{await self.__stats.issues:,}"
issues = issues if len(str(issues)) < TXT_SPACER_MAX_LEN else add_unit(issues)
pull_requests_and_issues = (
pull_requests
+ " " * max(1, TXT_SPACER_MAX_LEN - len(str(pull_requests)) + 1)
+ "| "
+ issues
)
output = sub("{{ pull_requests_and_issues }}", pull_requests_and_issues, output)
# pull_requests = f"{await self.__stats.pull_requests:,}"
# pull_requests = (
# pull_requests
# if len(str(pull_requests)) < TXT_SPACER_MAX_LEN
# else add_unit(pull_requests)
# )
# issues = f"{await self.__stats.issues:,}"
# issues = issues if len(str(issues)) < TXT_SPACER_MAX_LEN else add_unit(issues)
# pull_requests_and_issues = (
# pull_requests
# + " " * max(1, TXT_SPACER_MAX_LEN - len(str(pull_requests)) + 1)
# + "| "
# + issues
# )
# output = sub("{{ pull_requests_and_issues }}", pull_requests_and_issues, output)

generate_output_folder()
with open("{}/{}".format(OUTPUT_DIR, OVERVIEW_FILE_NAME), "w") as f:
Expand Down
65 changes: 32 additions & 33 deletions src/github_repo_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def __init__(self, environment_vars: EnvironmentVariables, session: ClientSessio
self._owned_repos: Optional[Set[str]] = None
self._users_lines_changed: Optional[Tuple[int, int]] = None
self._avg_percent: Optional[str] = None
self._weighted_avg_percent: Optional[str] = None
self._views: Optional[int] = None
self._collaborators: Optional[int] = None
self._collaborator_set: Optional[Set[str]] = None
Expand All @@ -64,21 +63,35 @@ async def to_str(self) -> str:

users_lines_changed = await self.lines_changed
avg_percent = await self.avg_contribution_percent
weighted_avg_percent = await self.weighted_avg_contribution_percent
contributors = max(len(await self.contributors) - 1, 0)

# return f"""GitHub Repository Statistics:
# Stargazers: {await self.stargazers:,}
# Forks: {await self.forks:,}
# Pull requests: {await self.pull_requests:,}
# Issues: {await self.issues:,}
# All-time contributions: {await self.total_contributions:,}
# Repositories with contributions: {len(await self.repos):,}
# Lines of code added: {users_lines_changed[0]:,}
# Lines of code deleted: {users_lines_changed[1]:,}
# Total lines of code changed: {sum(users_lines_changed):,}
# Avg. % of contributions (per collab repo): {avg_percent}
# Project page views: {await self.views:,}
# Project page views from date: {await self.views_from_date}
# Project repository collaborators: {await self.collaborators:,}
# Project repository contributors: {contributors:,}
# Total number of languages: {len(list(languages.keys()))} (+{len(await self.excluded_languages):,})
# Languages:\n\t\t\t- {formatted_languages}"""

return f"""GitHub Repository Statistics:
Stargazers: {await self.stargazers:,}
Forks: {await self.forks:,}
Pull requests: {await self.pull_requests:,}
Issues: {await self.issues:,}
All-time contributions: {await self.total_contributions:,}
Repositories with contributions: {len(await self.repos):,}
Lines of code added: {users_lines_changed[0]:,}
Lines of code deleted: {users_lines_changed[1]:,}
Total lines of code changed: {sum(users_lines_changed):,}
Avg. % of contributions (per collab repo): {avg_percent}
Weighted avg. % of contributions (per collab repo): {weighted_avg_percent}
Project page views: {await self.views:,}
Project page views from date: {await self.views_from_date}
Project repository collaborators: {await self.collaborators:,}
Expand Down Expand Up @@ -409,10 +422,11 @@ async def lines_changed(self) -> Tuple[int, int]:
contributor_set = set()
repo_total_changes_arr = []
author_contribution_percentages = []
weighted_author_contribution_percentages = []
author_total_additions = 0
author_total_deletions = 0

repos = []

for repo in await self.repos:
if repo in self._empty_repos:
continue
Expand Down Expand Up @@ -466,20 +480,12 @@ async def lines_changed(self) -> Tuple[int, int]:
)
repo_total_changes_arr.append(repo_total_changes)

weighted_author_contribution_percentages.append(
author_contribution_percentages[-1]
* (1 - 1 / num_repo_collabs if num_repo_collabs > 1 else 1)
)
repos.append(repo)

if sum(author_contribution_percentages) > 0:
self._avg_percent = f"{(sum(author_contribution_percentages) / len(repo_total_changes_arr) * 100):0.2f}%"

weighted_avg_percent = sum(weighted_author_contribution_percentages) / len(
repo_total_changes_arr
)
self._weighted_avg_percent = f"{weighted_avg_percent * 100:0.2f}%"
else:
self._weighted_avg_percent = self._avg_percent = "N/A"
self._avg_percent = "N/A"

self._contributors = contributor_set

Expand All @@ -497,17 +503,6 @@ async def avg_contribution_percent(self) -> str:
assert self._avg_percent is not None
return self._avg_percent

@property
async def weighted_avg_contribution_percent(self) -> str:
"""
:return: str representing the weighted avg percent of user's repo contributions
"""
if self._weighted_avg_percent is not None:
return self._weighted_avg_percent
await self.lines_changed
assert self._weighted_avg_percent is not None
return self._weighted_avg_percent

@property
async def views(self) -> int:
"""
Expand Down Expand Up @@ -624,9 +619,11 @@ async def pull_requests(self) -> int:

for pr_data in await self.queries.query_rest(end_point):
try:
pull_requests.add(
pr_data["url"]
) if "url" in pr_data.keys() else None
(
pull_requests.add(pr_data["url"])
if "url" in pr_data.keys()
else None
)
except AttributeError:
self._is_fetch_rate_limit_exceeded = True
break
Expand Down Expand Up @@ -658,9 +655,11 @@ async def issues(self) -> int:

for issue_data in await self.queries.query_rest(end_point):
try:
issues.add(
issue_data["url"]
) if "url" in issue_data.keys() else None
(
issues.add(issue_data["url"])
if "url" in issue_data.keys()
else None
)
except AttributeError:
self._is_fetch_rate_limit_exceeded = True
break
Expand Down
2 changes: 1 addition & 1 deletion src/templates/languages.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 20 additions & 20 deletions src/templates/overview.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e7bc8b8

Please sign in to comment.