Skip to content

Commit

Permalink
Merge pull request #36 from con/user-agent
Browse files Browse the repository at this point in the history
Set custom User-Agent in HTTP requests
  • Loading branch information
jwodder authored Nov 20, 2023
2 parents 9c93332 + 3368838 commit e351f06
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/solidation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from collections.abc import Iterable, Iterator
from dataclasses import InitVar, dataclass, field
from datetime import datetime, timedelta, timezone
import importlib.metadata
import logging
import os
from pathlib import Path
import platform
from random import sample
import re
from statistics import quantiles
Expand All @@ -19,10 +21,19 @@
from github.Repository import Repository
from pydantic import BaseModel, Field, StrictBool, StringConstraints
from ruamel.yaml import YAML
from . import __version__
from . import __url__, __version__

log = logging.getLogger("solidation")

USER_AGENT = "solidation/{} ({}) PyGithub/{} {}/{}".format(
__version__,
__url__,
importlib.metadata.version("pygithub"),
platform.python_implementation(),
platform.python_version(),
)


GHUser = Annotated[str, StringConstraints(pattern=r"^[-_A-Za-z0-9]+$")]
GHRepo = Annotated[str, StringConstraints(pattern=r"^[-_A-Za-z0-9]+/[-_.A-Za-z0-9]+$")]

Expand Down Expand Up @@ -76,7 +87,7 @@ class Consolidator:
since: datetime = field(init=False)

def __post_init__(self, token: str) -> None:
self.gh = Github(auth=Auth.Token(token))
self.gh = Github(auth=Auth.Token(token), user_agent=USER_AGENT)
self.since = datetime.now(timezone.utc) - timedelta(
days=self.config.recent_days
)
Expand Down

0 comments on commit e351f06

Please sign in to comment.