diff --git a/environment.sample b/environment.sample index ff75553a..2463bda1 100644 --- a/environment.sample +++ b/environment.sample @@ -15,6 +15,8 @@ GITHUB_SECRET= GITHUB_LOGIN= # GitHub oauth token GITHUB_TOKEN= +# Repo is private +GITHUB_REPO_PRIVATE=True # Coma separated list of github organisations names (for organization wide scheduled tasks) #GITHUB_ORG= # Git name and email used for creating commits (default: user git config, diff --git a/src/oca_github_bot/config.py b/src/oca_github_bot/config.py index e5a23c3c..38ff4cfa 100644 --- a/src/oca_github_bot/config.py +++ b/src/oca_github_bot/config.py @@ -40,6 +40,7 @@ def func_wrapper(*args, **kwargs): GITHUB_ORG = ( os.environ.get("GITHUB_ORG") and os.environ.get("GITHUB_ORG").split(",") or [] ) +GITHUB_REPO_PRIVATE = os.environ.get("GITHUB_REPO_PRIVATE") GIT_NAME = os.environ.get("GIT_NAME") GIT_EMAIL = os.environ.get("GIT_EMAIL") diff --git a/src/oca_github_bot/github.py b/src/oca_github_bot/github.py index 92f5e62b..a1520bfd 100644 --- a/src/oca_github_bot/github.py +++ b/src/oca_github_bot/github.py @@ -68,8 +68,10 @@ def temporary_clone(org, repo, branch): if not os.path.isdir(repo_cache_dir): os.makedirs(repo_cache_dir) check_call(["git", "init", "--bare"], cwd=repo_cache_dir) - repo_url = f"https://github.com/{org}/{repo}" + repo_url_no_token = f"https://github.com/{org}/{repo}" repo_url_with_token = f"https://{config.GITHUB_TOKEN}@github.com/{org}/{repo}" + + repo_url = repo_url_with_token if config.GITHUB_REPO_PRIVATE else repo_url_no_token # fetch all branches into cache fetch_cmd = [ "git",