Support GitHub token

This commit is contained in:
Stéphane Bidoul 2021-10-31 11:05:38 +01:00
parent d6d9ac8a7f
commit 9627729ba2
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
3 changed files with 6 additions and 2 deletions

View file

@ -35,8 +35,6 @@ Contributions welcome.
Prototype (min required to do load testing): Prototype (min required to do load testing):
- github token for github api requests
- set requests otherwise requests is same as limits ?
- plug it on a bunch of OCA and shopinvader repos to test load - plug it on a bunch of OCA and shopinvader repos to test load
- configuring many repos in a .env file may be difficult, switch to a toml file ? - configuring many repos in a .env file may be difficult, switch to a toml file ?

View file

@ -4,6 +4,7 @@ from typing import Any
import requests import requests
from .exceptions import NotFoundOnGithub from .exceptions import NotFoundOnGithub
from .settings import settings
def _github_get(url: str) -> Any: def _github_get(url: str) -> Any:
@ -12,6 +13,8 @@ def _github_get(url: str) -> Any:
headers = { headers = {
"Accept": "application/vnd.github.v3+json", "Accept": "application/vnd.github.v3+json",
} }
if settings.github_token:
headers["Authorization"] = f"token {settings.github_token}"
response = requests.get(full_url, headers) response = requests.get(full_url, headers)
if response.status_code == 404: if response.status_code == 404:
raise NotFoundOnGithub(f"GitHub URL not found: {full_url}.") raise NotFoundOnGithub(f"GitHub URL not found: {full_url}.")

View file

@ -1,3 +1,5 @@
from typing import Optional
from pydantic import BaseSettings from pydantic import BaseSettings
@ -15,6 +17,7 @@ class Settings(BaseSettings):
build_pgpassword: str build_pgpassword: str
build_admin_passwd: str build_admin_passwd: str
build_domain: str build_domain: str
github_token: Optional[str]
class Config: class Config:
env_prefix = "RUNBOAT_" env_prefix = "RUNBOAT_"