Skip to content
Snippets Groups Projects
Commit d715aaf9 authored by vlorentz's avatar vlorentz
Browse files

Make user_agent a parameter of GitHubSession

So it can be set when used by other packages
parent 2d04244c
No related branches found
No related tags found
Loading
......@@ -14,6 +14,7 @@ import iso8601
from swh.scheduler.interface import SchedulerInterface
from swh.scheduler.model import ListedOrigin
from .. import USER_AGENT
from ..pattern import CredentialsType, Lister
from .utils import GitHubSession, MissingRateLimitReset
......@@ -85,7 +86,9 @@ class GitHubLister(Lister[GitHubListerState, List[Dict[str, Any]]]):
self.relisting = self.first_id is not None or self.last_id is not None
self.github_session = GitHubSession(credentials=self.credentials)
self.github_session = GitHubSession(
credentials=self.credentials, user_agent=USER_AGENT
)
def state_from_dict(self, d: Dict[str, Any]) -> GitHubListerState:
return GitHubListerState(**d)
......
......@@ -17,8 +17,6 @@ from tenacity import (
wait_exponential,
)
from .. import USER_AGENT
logger = logging.getLogger(__name__)
......@@ -52,7 +50,9 @@ class GitHubSession:
"""Manages a :class:`requests.Session` with (optionally) multiple credentials,
and cycles through them when reaching rate-limits."""
def __init__(self, credentials: Optional[List[Dict[str, str]]] = None) -> None:
def __init__(
self, user_agent: str, credentials: Optional[List[Dict[str, str]]] = None
) -> None:
"""Initialize a requests session with the proper headers for requests to
GitHub."""
self.credentials = credentials
......@@ -62,7 +62,7 @@ class GitHubSession:
self.session = requests.Session()
self.session.headers.update(
{"Accept": "application/vnd.github.v3+json", "User-Agent": USER_AGENT}
{"Accept": "application/vnd.github.v3+json", "User-Agent": user_agent}
)
self.anonymous = not self.credentials
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment