From 336883897429d8006e527c90ed3ecdff6d7fa7cc Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Wed, 8 Nov 2023 16:28:17 -0500 Subject: [PATCH] Set custom User-Agent in HTTP requests --- src/solidation/__main__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/solidation/__main__.py b/src/solidation/__main__.py index c450f5e..3c9122d 100644 --- a/src/solidation/__main__.py +++ b/src/solidation/__main__.py @@ -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 @@ -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]+$")] @@ -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 )