Skip to content

Commit

Permalink
Merge pull request #243 from cicirello/fix-watchers
Browse files Browse the repository at this point in the history
Eliminated adjustment to Watched By for repositories watched by owner
  • Loading branch information
cicirello authored Dec 1, 2023
2 parents 8bd46ca + 0428a82 commit a06def9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 67 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - 2023-11-06
## [Unreleased] - 2023-12-01

### Added

Expand All @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

### Fixed
* Eliminated adjustment for watching own repositories from the "Watched By" stat for consistency with other stats that don't make such an adjustment such as the star count.

### Dependencies
* Bump cicirello/pyaction from 4.25.0 to 4.26.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ The statistics include the following.
| `public` | My Repositories | simple count |
| `starredBy` | Starred By | simple count |
| `forkedBy` | Forked By | simple count |
| `watchedBy` | Watched By | number watching your repositories (excluding you) |
| `watchedBy` | Watched By | number watching your repositories |
| `templates` | Templates | number of your repositories that are templates |
| `archived` | Archived | number of your repositories that you have archived |

Expand Down
27 changes: 5 additions & 22 deletions src/Statistician.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ def __init__(
fail)
oneYearContribTemplate = self.loadQuery("/queries/singleYearQueryFragment.graphql",
fail)
watchingAdjustmentQuery = self.loadQuery("/queries/watchingAdjustment.graphql",
fail)

reposContributedTo = self.loadQuery("/queries/reposContributedTo.graphql",
fail)

Expand All @@ -104,9 +101,6 @@ def __init__(
self.executeQuery(additionalRepoStatsQuery,
needsPagination=True,
failOnError=fail),
self.executeQuery(watchingAdjustmentQuery,
needsPagination=True,
failOnError=fail),
self.executeQuery(reposContributedTo,
needsPagination=True,
failOnError=fail)
Expand Down Expand Up @@ -152,13 +146,12 @@ def loadQuery(self, queryFilepath, failOnError=True):
set_outputs({"exit-code" : 1})
exit(1 if failOnError else 0)

def parseStats(self, basicStats, repoStats, watchingStats, reposContributedToStats):
def parseStats(self, basicStats, repoStats, reposContributedToStats):
"""Parses the user statistics.
Keyword arguments:
basicStats - The results of the basic stats query.
repoStats - The results of the repo stats query.
watchingStats - The results of the query of repositories the user is watching.
"""
# Extract username (i.e., login) and fullname.
# Name needed for title of statistics card, and username
Expand Down Expand Up @@ -208,7 +201,6 @@ def parseStats(self, basicStats, repoStats, watchingStats, reposContributedToSta

# Reorganize for simplicity
repoStats = list(map(lambda x : x["data"]["user"]["repositories"], repoStats))
watchingStats = list(map(lambda x : x["data"]["user"]["watching"], watchingStats))
reposContributedToStats = list(
map(lambda x : x["data"]["user"]["topRepositories"], reposContributedToStats))

Expand Down Expand Up @@ -243,7 +235,7 @@ def parseStats(self, basicStats, repoStats, watchingStats, reposContributedToSta
# precautionary since the above check of totalCount should be sufficient
# to protect against a null list of repos.

# Count stargazers, forks of my repos, and watchers excluding me
# Count stargazers, forks of my repos, and watchers
stargazers = sum(
repo["stargazerCount"] for page in repoStats if page[
"nodes"] != None for repo in page[
Expand Down Expand Up @@ -282,24 +274,16 @@ def parseStats(self, basicStats, repoStats, watchingStats, reposContributedToSta
except ValueError:
pass

# Compute number of watchers excluding cases where user is watching their own repos.
# Compute number of watchers
watchers = sum(
repo["watchers"]["totalCount"] for page in repoStats if page[
"nodes"] != None for repo in page["nodes"] if not repo["isPrivate"])
watchers -= watchingStats[0]["totalCount"]

if watchingStats[0]["totalCount"] > 0:
watchingMyOwnNonForks = sum(
1 for page in watchingStats if page[
"nodes"] != None for repo in page["nodes"] if not repo["isFork"])
else:
watchingMyOwnNonForks = 0

watchersNonForks = sum(
repo["watchers"]["totalCount"] for page in repoStats if page[
"nodes"] != None for repo in page["nodes"] if not repo[
"isPrivate"] and not repo["isFork"])
watchersNonForks -= watchingMyOwnNonForks


# Count of private repos (not accurate since depends on token used to authenticate query,
# however, all those here are included in count of owned repos.
privateCount = sum(
Expand Down Expand Up @@ -342,7 +326,6 @@ def parseStats(self, basicStats, repoStats, watchingStats, reposContributedToSta
stargazersAll = 0
forksOfMyReposAll = 0
watchers = 0
watchingMyOwnNonForks = 0
watchersNonForks = 0
privateCount = 0
publicAll = 0
Expand Down
14 changes: 0 additions & 14 deletions src/queries/watchingAdjustment.graphql

This file was deleted.

45 changes: 16 additions & 29 deletions tests/tests.py

Large diffs are not rendered by default.

0 comments on commit a06def9

Please sign in to comment.