Skip to content

Commit

Permalink
Update GitStats (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
R055A committed Jul 16, 2024
1 parent e685e15 commit 2bcc41c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/auto_update_stat_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
MORE_COLLABS: ${{ secrets.MORE_COLLABS }}
MORE_REPOS: ${{ secrets.MORE_REPOS }}
ONLY_INCLUDED: ${{ secrets.ONLY_INCLUDED }}
ONLY_INCLUDED_COLLAB_REPOS: ${{ secrets.ONLY_INCLUDED_COLLAB_REPOS }}
EXCLUDED_COLLAB_REPOS: ${{ secrets.EXCLUDED_COLLAB_REPOS }}
MORE_COLLAB_REPOS: ${{ secrets.MORE_COLLAB_REPOS }}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/non_auto_generate_stat_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
MORE_COLLABS: ${{ secrets.MORE_COLLABS }}
MORE_REPOS: ${{ secrets.MORE_REPOS }}
ONLY_INCLUDED: ${{ secrets.ONLY_INCLUDED }}
ONLY_INCLUDED_COLLAB_REPOS: ${{ secrets.ONLY_INCLUDED_COLLAB_REPOS }}
EXCLUDED_COLLAB_REPOS: ${{ secrets.EXCLUDED_COLLAB_REPOS }}
MORE_COLLAB_REPOS: ${{ secrets.MORE_COLLAB_REPOS }}

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ Generate daily updated visualizations of user and repository statistics from the
* `<int>`
* example:
* `4`
* ### Optional Secret *Name*: `ONLY_INCLUDED_COLLAB_REPOS`
For **ONLY** including collaborative repositories in the generated average contribution statistics calculations
- such as when there are fewer collaborative repositories to include than to exclude

**Instructions**:
* enter *Value* in the following format (separated by commas):
* `[owner/repo],[owner/repo],...,[owner/repo]`
* example:
* `R055A/UniversityProject-A,R055A/UniversityProject-B`
* ### Optional Secret *Name*: `EXCLUDED_COLLAB_REPOS`
For excluding collaborative repositories from being included in the average contribution statistics calculations
- for example, such as for when
Expand Down
8 changes: 8 additions & 0 deletions src/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(
more_collaborators: Optional[str] = getenv("MORE_COLLABS"),
manually_added_repos: Optional[str] = getenv("MORE_REPOS"),
only_included_repos: Optional[str] = getenv("ONLY_INCLUDED"),
only_included_collab_repos: Optional[str] = getenv("ONLY_INCLUDED_COLLAB_REPOS"),
exclude_collab_repos: Optional[str] = getenv("EXCLUDED_COLLAB_REPOS"),
more_collab_repos: Optional[str] = getenv("MORE_COLLAB_REPOS"),
):
Expand Down Expand Up @@ -141,6 +142,13 @@ def __init__(
x.strip() for x in only_included_repos.split(",")
}

if only_included_collab_repos is None or only_included_collab_repos == "":
self.only_included_collab_repos = set()
else:
self.only_included_collab_repos = {
x.strip() for x in only_included_collab_repos.split(",")
}

if exclude_collab_repos is None:
self.exclude_collab_repos = set()
else:
Expand Down
38 changes: 20 additions & 18 deletions src/github_repo_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, environment_vars: EnvironmentVariables, session: ClientSessio
self._languages: Optional[Dict[str, Any]] = None
self._excluded_languages: Optional[Set[str]] = None
self._repos: Optional[Set[str]] = None
# self._owned_repos: Optional[Set[str]] = None
self._owned_repos: Optional[Set[str]] = None
self._users_lines_changed: Optional[Tuple[int, int]] = None
self._avg_percent: Optional[str] = None
self._views: Optional[int] = None
Expand Down Expand Up @@ -358,23 +358,23 @@ async def repos(self) -> Set[str]:
assert self._repos is not None
return self._repos

# @property
# async def owned_repos(self) -> Set[str]:
# """
# :return: list of names of repos owned by user
# """
# if self._owned_repos is not None:
# return self._owned_repos
# await self.get_stats()
# assert self._repos is not None
# self._owned_repos = set(
# [
# i
# for i in self._repos
# if self.environment_vars.username == i.split("/")[0]
# ]
# )
# return self._owned_repos
@property
async def owned_repos(self) -> Set[str]:
"""
:return: list of names of repos owned by user
"""
if self._owned_repos is not None:
return self._owned_repos
await self.get_stats()
assert self._repos is not None
self._owned_repos = set(
[
i
for i in self._repos
if self.environment_vars.username == i.split("/")[0]
]
)
return self._owned_repos

@property
async def total_contributions(self) -> int:
Expand Down Expand Up @@ -418,6 +418,7 @@ async def lines_changed(self) -> Tuple[int, int]:
return self._users_lines_changed
_, collab_repos = await self.raw_collaborators()
slave_status_repos = self.environment_vars.more_collab_repos
exclusive_collab_repos = self.environment_vars.only_included_collab_repos

contributor_set = set()
repo_total_changes_arr = []
Expand Down Expand Up @@ -464,6 +465,7 @@ async def lines_changed(self) -> Tuple[int, int]:
# calculate average author's contributions to each repository with at least one other collaborator
if (
repo not in self.environment_vars.exclude_collab_repos
and (not exclusive_collab_repos or repo in exclusive_collab_repos or repo in slave_status_repos)
and (author_additions + author_deletions) > 0
and (
other_authors_total_changes > 0
Expand Down

0 comments on commit 2bcc41c

Please sign in to comment.