diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0e2488133e9..69bb99dcf46 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,7 +42,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} EXCLUDED: ${{ secrets.EXCLUDED }} EXCLUDED_LANGS: ${{ secrets.EXCLUDED_LANGS }} - EXCLUDE_FORKED_REPOS: true + EXCLUDE_CONTRIB_REPOS: true # Commit all changed files to the repository - name: Commit to the repo diff --git a/README.md b/README.md index a24323b1cdc..73b46e5e46a 100644 --- a/README.md +++ b/README.md @@ -91,11 +91,14 @@ For more information on inaccuracies, see issue - To ignore certain languages, add them (separated by commas) to a new secret called `EXCLUDED_LANGS`. For example, to exclude HTML and TeX you could set the value to `html,tex`. - - To show statistics only for "owned" repositories and not forks with - contributions, add an environment variable (under the `env` header in the - [main - workflow](https://github.com/jstrieb/github-stats/blob/master/.github/workflows/main.yml)) - called `EXCLUDE_FORKED_REPOS` with a value of `true`. + - By default, statistics include your owned repositories (non-forks) AND + repositories you've contributed to. Note: Contributed repositories count + their entire stars/forks/languages (not proportional to your contributions); + only "lines changed" reflects your actual contributions. To exclude + contributed repositories, set `EXCLUDE_CONTRIB_REPOS: true` in the `env` + section of the [main + workflow](https://github.com/jstrieb/github-stats/blob/master/.github/workflows/main.yml). + Your forked repositories are never counted as "owned". - These other values are added as secrets by default to prevent leaking information about private repositories. If you're not worried about that, you can change the values directly [in the Actions workflow diff --git a/generate_images.py b/generate_images.py index e800b9357ea..82e9324f1c5 100644 --- a/generate_images.py +++ b/generate_images.py @@ -115,10 +115,16 @@ async def main() -> None: {x.strip() for x in exclude_langs.split(",")} if exclude_langs else None ) # Convert a truthy value to a Boolean - raw_ignore_forked_repos = os.getenv("EXCLUDE_FORKED_REPOS") - ignore_forked_repos = ( - not not raw_ignore_forked_repos - and raw_ignore_forked_repos.strip().lower() != "false" + # Try new name first, fall back to old name for backward compatibility + raw_exclude_contrib_repos = os.getenv("EXCLUDE_CONTRIB_REPOS") + if raw_exclude_contrib_repos is None: + raw_exclude_contrib_repos = os.getenv("EXCLUDE_FORKED_REPOS") + if raw_exclude_contrib_repos is not None: + print("WARNING: EXCLUDE_FORKED_REPOS is deprecated. Please use EXCLUDE_CONTRIB_REPOS instead.") + + exclude_contrib_repos = ( + not not raw_exclude_contrib_repos + and raw_exclude_contrib_repos.strip().lower() != "false" ) async with aiohttp.ClientSession() as session: s = Stats( @@ -127,7 +133,7 @@ async def main() -> None: session, exclude_repos=excluded_repos, exclude_langs=excluded_langs, - ignore_forked_repos=ignore_forked_repos, + exclude_contrib_repos=exclude_contrib_repos, ) await asyncio.gather(generate_languages(s), generate_overview(s)) diff --git a/github_stats.py b/github_stats.py index b663896e942..c6797179bae 100644 --- a/github_stats.py +++ b/github_stats.py @@ -257,10 +257,10 @@ def __init__( session: aiohttp.ClientSession, exclude_repos: Optional[Set] = None, exclude_langs: Optional[Set] = None, - ignore_forked_repos: bool = False, + exclude_contrib_repos: bool = False, ): self.username = username - self._ignore_forked_repos = ignore_forked_repos + self._exclude_contrib_repos = exclude_contrib_repos self._exclude_repos = set() if exclude_repos is None else exclude_repos self._exclude_langs = set() if exclude_langs is None else exclude_langs self.queries = Queries(username, access_token, session) @@ -334,7 +334,7 @@ async def get_stats(self) -> None: ) repos = owned_repos.get("nodes", []) - if not self._ignore_forked_repos: + if not self._exclude_contrib_repos: repos += contrib_repos.get("nodes", []) for repo in repos: