diff --git a/swh/lister/github/lister.py b/swh/lister/github/lister.py --- a/swh/lister/github/lister.py +++ b/swh/lister/github/lister.py @@ -14,6 +14,7 @@ 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 @@ 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) diff --git a/swh/lister/github/utils.py b/swh/lister/github/utils.py --- a/swh/lister/github/utils.py +++ b/swh/lister/github/utils.py @@ -17,8 +17,6 @@ wait_exponential, ) -from .. import USER_AGENT - logger = logging.getLogger(__name__) @@ -52,7 +50,9 @@ """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 @@ 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