Skip to content

Commit

Permalink
Update GitStats (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
R055A authored May 6, 2023
1 parent 00193ff commit 750aee8
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 189 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/auto_update_stat_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ on:
permissions:
contents: write

# A workflow run is made up of one or more jobs that can run sequentially or in
# parallel
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

# This workflow contains a single job called "build"
Expand Down Expand Up @@ -71,6 +70,7 @@ jobs:
MORE_COLLABS: ${{ secrets.MORE_COLLABS }}
MORE_REPOS: ${{ secrets.MORE_REPOS }}
ONLY_INCLUDED: ${{ secrets.ONLY_INCLUDED }}
EXCLUDED_COLLAB_REPOS: ${{ secrets.EXCLUDED_COLLAB_REPOS }}

# Commits all changed files to the repository
- name: Commit to the repo
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/non_auto_generate_stat_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ on:
permissions:
contents: write

# A workflow run is made up of one or more jobs that can run sequentially or in
# parallel
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

# This workflow contains a single job called "build"
Expand Down Expand Up @@ -74,6 +73,7 @@ jobs:
MORE_COLLABS: ${{ secrets.MORE_COLLABS }}
MORE_REPOS: ${{ secrets.MORE_REPOS }}
ONLY_INCLUDED: ${{ secrets.ONLY_INCLUDED }}
EXCLUDED_COLLAB_REPOS: ${{ secrets.EXCLUDED_COLLAB_REPOS }}

# Commits all changed files to the repository
- name: Commit to the repo
Expand Down
67 changes: 41 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# [GitHub Stats Visualization](https://github.com/R055A/GitStats) 📈🔭
# 📈 [GitHub Stats Visualization](https://github.com/R055A/GitStats) 🔭

Generate daily updated visualizations of user and repository statistics from the GitHub [GraphQL](https://docs.github.com/en/graphql) and [REST](https://docs.github.com/en/rest) APIs using GitHub [Actions](https://docs.github.com/en/actions) and [Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets). Customizable visualizations support dark and light mode and can adapt to device sizes.

> A modification of [`jstrieb/github-stats`](https://github.com/jstrieb/github-stats) with new and improved statistical visualizations and more options!
[![GitStats Overview](https://raw.githubusercontent.com/R055A/GitStats/actions_branch/generated_images/overview.svg)![GitStats Languages](https://raw.githubusercontent.com/R055A/GitStats/actions_branch/generated_images/languages.svg)](https://github.com/R055A/GitStats)

# Instructions
# :rocket: Instructions

<details>
<summary>Click drop-down to view step-by-step instructions for generating your own GitHub statistics visualizations
Expand Down Expand Up @@ -77,56 +77,57 @@ Generate daily updated visualizations of user and repository statistics from the

</details>

# Options
# :closed_lock_with_key: Options

<details>
<summary>Click drop-down to view Repository Secrets for customizing GitHub statistic visualizations
<summary>Click drop-down to view optional repository Secrets for customizing GitHub statistic visualizations
</summary>

* ### Optional Secret *Name*: `EXCLUDED`
For excluding listed repositories from being included in the generated statistic visualizations.
For excluding repositories from being included entirely in the generated statistic visualizations.

**Instructions**:
* enter *Value* in the following format (separated by commas):
* `[owner/repo],[owner/repo],...,[owner/repo]`
* example:
* `jstrieb/github-stats,rahul-jha98/github-stats-transparent,idiotWu/stats`
* ### Optional Secret *Name*: `ONLY_INCLUDED`
For **ONLY** including listed repositories in the generated statistic visualizations.
For **ONLY** including repositories in the generated statistic visualizations
- such as when there are fewer repositories to include than to exclude

**Instructions**:
* enter *Value* in the following format (separated by commas):
* `[owner/repo],[owner/repo],...,[owner/repo]`
* example:
* `R055A/GitStats,R055A/R055A`
**Instructions**:
* enter *Value* in the following format (separated by commas):
* `[owner/repo],[owner/repo],...,[owner/repo]`
* example:
* `R055A/GitStats,R055A/R055A`
* ### Optional Secret *Name*: `EXCLUDED_LANGS`
For excluding listed languages from being included in the generated statistic visualizations.
For excluding undesired languages from being included in the generated statistic visualizations

**Instructions**:
* enter *Value* in the following format (separated by commas):
* `[language],[language],...,[language]`
* example:
* `HTML,Jupyter Notebook,Makefile,Dockerfile`
* ### Optional Secret *Name*: `INCLUDE_FORKED_REPOS`
For including forked repositories in the generated statistic visualizations
Boolean option for including forked repositories in the generated statistic visualizations. These could repeat statistical calculations
- `false` by default

**Instructions**:
* enter *Value* in the following format:
* `<boolean>`
* examples:
* `true`
* ### Optional Secret *Name*: `EXCLUDE_CONTRIB_REPOS`
For excluding repositories (pull request) contributed to in the generated statistic visualizations
Boolean option for excluding non-owned repositories contributed to in the generated statistic visualizations
- `false` by default

**Instructions**:
* enter *Value* in the following format:
* `<boolean>`
* examples:
* `true`
* ### Optional Secret *Name*: `EXCLUDE_ARCHIVE_REPOS`
For excluding archived repositories in the generated statistic visualizations
Boolean option for excluding archived repositories in the generated statistic visualizations
- `false` by default

**Instructions**:
Expand All @@ -135,7 +136,8 @@ Generate daily updated visualizations of user and repository statistics from the
* examples:
* `true`
* ### Optional Secret *Name*: `EXCLUDE_PRIVATE_REPOS`
For excluding private repositories in the generated statistic visualizations
Boolean option for excluding private repositories in the generated statistic visualizations
- for when you want to keep those secrets locked away from prying eyes
- `false` by default

**Instructions**:
Expand All @@ -144,7 +146,7 @@ Generate daily updated visualizations of user and repository statistics from the
* examples:
* `true`
* ### Optional Secret *Name*: `EXCLUDE_PUBLIC_REPOS`
For excluding public repositories in the generated statistic visualizations
Boolean option for excluding public repositories in the generated statistic visualizations
- `false` by default

**Instructions**:
Expand All @@ -153,8 +155,8 @@ Generate daily updated visualizations of user and repository statistics from the
* examples:
* `true`
* ### Optional Secret *Name*: `MORE_REPOS`
For including repositories that are otherwise not included in the generated statistic visualizations
- such as imported repositories with contributions
For including repositories that are otherwise not included in generated statistic visualizations when scraping by username
- such as repositories imported from, say, GitLab - hint: add emails used in imported repo commits to profile settings

**Instructions**:
* enter *Value* in the following format (separated by commas):
Expand All @@ -170,10 +172,23 @@ Generate daily updated visualizations of user and repository statistics from the
* `<int>`
* example:
* `4`
* ### Optional Secret *Name*: `EXCLUDED_COLLAB_REPOS`
For excluding collaborative repositories from being included in the average contribution statistics
- for example, such as for when
- contributions are included in a collaborative repo, but it is not one of your projects
- someone deletes and re-adds the entire codebase a few times
- your performance is not fairly represented
- ninjas

**Instructions**:
* enter *Value* in the following format (separated by commas):
* `[owner/repo],[owner/repo],...,[owner/repo]`
* example:
* `jstrieb/github-stats,rahul-jha98/github-stats-transparent,idiotWu/stats`
* ### Optional Secret *Name*: `STORE_REPO_VIEWS`
For storing generated repository view statistic visualization data beyond the 14 day-limit GitHub API allows
Boolean for storing generated repository view statistic visualization data beyond the 14 day-limit GitHub API allows
- `true` by default

**Instructions**:
* enter *Value* in the following format:
* `<boolean>`
Expand Down Expand Up @@ -213,10 +228,10 @@ Generate daily updated visualizations of user and repository statistics from the
* `2021-03-31`
</details>

# Support the Project
# :green_heart: Support the Project

There are a few things you can do to support the project:

- ✨ Star this repository (and/or 🌠 star [`jstrieb/github-stats`](https://github.com/jstrieb/github-stats) and 🔭 follow [`jstrieb`](https://github.com/jstrieb) for more)
- 📝 Report any bugs, glitches, or errors that you find
- 🥹 Spare a donation to a worthy cause
- :memo: Report any bugs :bug:, glitches, or errors that you find :monocle_face:
- :money_with_wings: Spare a donation to a worthy cause 🥹
18 changes: 13 additions & 5 deletions src/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def __init__(self,
repo_last_viewed: Optional[str] = getenv("LAST_VIEWED"),
repo_first_viewed: Optional[str] = getenv("FIRST_VIEWED"),
store_repo_view_count: str = getenv("STORE_REPO_VIEWS"),
more_collabs: Optional[str] = getenv("MORE_COLLABS"),
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_repos: Optional[str] = getenv("ONLY_INCLUDED"),
exclude_collab_repos: Optional[str] = getenv("EXCLUDED_COLLAB_REPOS")):
self.__db = GitRepoStatsDB()

self.username = username
Expand All @@ -44,7 +45,7 @@ def __init__(self,
{x.strip() for x in exclude_repos.split(",")}
)

if exclude_repos is None:
if exclude_langs is None:
self.exclude_langs = set()
else:
self.exclude_langs = (
Expand Down Expand Up @@ -122,9 +123,9 @@ def __init__(self,
self.__db.set_views_to_date(self.repo_last_viewed)

try:
self.more_collabs = int(more_collabs) if more_collabs else 0
self.more_collaborators = int(more_collaborators) if more_collaborators else 0
except ValueError:
self.more_collabs = 0
self.more_collaborators = 0

if manually_added_repos is None:
self.manually_added_repos = set()
Expand All @@ -140,6 +141,13 @@ def __init__(self,
{x.strip() for x in only_included_repos.split(",")}
)

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

def set_views(self, views: any) -> None:
self.repo_views += int(views)
environ["REPO_VIEWS"] = str(self.repo_views)
Expand Down
35 changes: 26 additions & 9 deletions src/generate_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
TEMPLATE_PATH = "src/templates/"
OVERVIEW_FILE_NAME = "overview.svg"
LANGUAGES_FILE_NAME = "languages.svg"
TXT_SPACER_MAX_LEN = 4
TXT_SPACER_MAX_LEN = 7
MAX_NAME_LEN = 18


###############################################################################
Expand Down Expand Up @@ -68,9 +69,17 @@ async def generate_overview(self) -> None:
OVERVIEW_FILE_NAME), "r") as f:
output = f.read()

name = (await self.__stats.name) + "'" \
if (await self.__stats.name)[-1] == "s" \
else (await self.__stats.name) + "'s"
name = await self.__stats.name
name += "'" if name[-1] == "s" else "'s"
if len(name) > MAX_NAME_LEN:
names = name.split(' ')
if len(names) == 1:
name = names[0]
elif len(names[0][0] + '. ' + names[-1]) > MAX_NAME_LEN:
name = names[0] + "'" if names[0][-1] == "s" else "'s"
else:
name = names[0][0] + '. ' + names[-1]
name = name if len(name) <= MAX_NAME_LEN else name[:MAX_NAME_LEN-2] + '..'
output = sub("{{ name }}",
name,
output)
Expand All @@ -83,8 +92,7 @@ async def generate_overview(self) -> None:
forks = f"{await self.__stats.forks:,}"
stars = f"{await self.__stats.stargazers:,}"
forks_and_stars = \
forks + ' ' * max(1, TXT_SPACER_MAX_LEN - len(str(forks)) + 1) + '|' \
+ ' ' * max(1, TXT_SPACER_MAX_LEN - len(str(stars)) + 1) + stars
forks + ' ' * max(1, TXT_SPACER_MAX_LEN - len(str(forks)) + 1) + '| ' + stars
output = sub("{{ forks_and_stars }}",
forks_and_stars,
output)
Expand Down Expand Up @@ -117,14 +125,13 @@ async def generate_overview(self) -> None:

views_from = (await self.__stats.views_from_date)
output = sub("{{ views_from_date }}",
f"Repository views (as of {views_from})",
f"Repo views (as of {views_from})",
output)

pull_requests = f"{await self.__stats.pull_requests:,}"
issues = f"{await self.__stats.issues:,}"
pull_requests_and_issues = \
pull_requests + ' ' * max(1, TXT_SPACER_MAX_LEN - len(str(pull_requests)) + 1) + '|' \
+ ' ' * max(1, TXT_SPACER_MAX_LEN - len(str(issues)) + 1) + 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)
Expand All @@ -147,6 +154,12 @@ async def generate_languages(self) -> None:
sorted_languages = sorted((await self.__stats.languages).items(),
reverse=True,
key=lambda t: t[1].get("size"))

lang_count = str(len(sorted_languages))
num_excluded_languages = len(await self.__stats.excluded_languages)
if num_excluded_languages > 0:
lang_count += ' [+' + str(num_excluded_languages) + ']'

delay_between = 150

for i, (lang, data) in enumerate(sorted_languages):
Expand Down Expand Up @@ -176,6 +189,10 @@ async def generate_languages(self) -> None:
</span>
</li>"""

output = sub(r"{{ lang_count }}",
lang_count,
output)

output = sub(r"{{ progress }}",
progress,
output)
Expand Down
1 change: 0 additions & 1 deletion src/github_api_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from requests import post, get
from aiohttp import ClientSession
from typing import Dict, Optional, List
from requests import get
from json import loads

###############################################################################
Expand Down
Loading

0 comments on commit 750aee8

Please sign in to comment.