From 51325dab2fdebccd049cf09c75634c0050de3c1f Mon Sep 17 00:00:00 2001 From: Yonggan <30302975+Y0ngg4n@users.noreply.github.com> Date: Tue, 21 Sep 2021 15:33:19 +0200 Subject: [PATCH] Add Support for User (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update github-traffic.py * Update push.yaml * Update push.yaml * Update github-traffic.py * Update .github/workflows/push.yaml Co-authored-by: Daniel González Co-authored-by: Daniel González --- github-traffic.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/github-traffic.py b/github-traffic.py index 76dc1fa..577bfc1 100644 --- a/github-traffic.py +++ b/github-traffic.py @@ -7,7 +7,8 @@ from prometheus_client import start_http_server, Gauge from logfmt_logger import getLogger -ORG_NAME = config("ORG_NAME") +ORG_NAME = config("ORG_NAME", default="") +USER_NAME = config("USER_NAME", default="") REPO_TYPE = config("REPO_TYPE", default="public") REPO_NAME_CONTAINS = config("REPO_NAME_CONTAINS", default="") CRONTAB_SCHEDULE = config("CRONTAB_SCHEDULE", default="0 * * * *") @@ -61,8 +62,12 @@ def job_function(): api_limits = github.get_rate_limit().core gh_traffic_api_requests_limit.set(api_limits.limit) gh_traffic_api_requests_remaining.set(api_limits.remaining) - - repositories = github.get_organization(ORG_NAME).get_repos(type=REPO_TYPE) + if(not ORG_NAME and not USER_NAME): + logger.error(f"Please fill ORG_NAME or USER_NAME in config") + if(ORG_NAME): + repositories = github.get_organization(ORG_NAME).get_repos(type=REPO_TYPE) + if(USER_NAME): + repositories = github.get_user(USER_NAME).get_repos(type=REPO_TYPE) for repo in repositories: if REPO_NAME_CONTAINS in repo.name: repo_name = repo.name