Skip to content

Commit 8434493

Browse files
committed
add option to ignore forked repositories
1 parent cc2f190 commit 8434493

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Generate Stats Images
55
# Controls when the action will run. Triggers the workflow on push events
66
on:
77
push:
8-
branches: [ master ]
8+
branches: [ main ]
99
schedule:
1010
- cron: "0 0 * * *"
1111
workflow_dispatch:
@@ -56,11 +56,12 @@ jobs:
5656
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5757
EXCLUDED: ${{ secrets.EXCLUDED }}
5858
EXCLUDED_LANGS: ${{ secrets.EXCLUDE_LANGS }}
59+
IGNORE_FORKED_REPOSITORIES: ${{ secrets.IGNORE_FORKED_REPOSITORIES }}
5960

6061
# Commits all changed files to the repository
6162
- name: Commit to the output branch of repo
6263
run: |
63-
git config --global user.name "github-actions[bot]"
64+
git config --global user.name "github-stats[bot]"
6465
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
6566
git add .
6667
git commit -m 'temp commit' || echo

github_stats.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ def __init__(self, username: str, access_token: str,
247247
self._lines_changed = None
248248
self._views = None
249249

250+
self._ignore_forked_repositories = False
251+
if len(os.getenv("IGNORE_FORKED_REPOSITORIES")) != 0:
252+
self._ignore_forked_repositories = True
253+
250254
async def to_str(self) -> str:
251255
"""
252256
:return: summary of all available statistics
@@ -304,8 +308,11 @@ async def get_stats(self) -> None:
304308
.get("data", {})
305309
.get("viewer", {})
306310
.get("repositories", {}))
307-
repos = (contrib_repos.get("nodes", [])
308-
+ owned_repos.get("nodes", []))
311+
312+
repos = owned_repos.get("nodes", [])
313+
if not self._ignore_forked_repositories:
314+
repos += contrib_repos.get("nodes", [])
315+
309316

310317
for repo in repos:
311318
name = repo.get("nameWithOwner")

0 commit comments

Comments
 (0)