Use the new utils.get_user_agent function everywhere instead of hardcoding a User-Agent

This commit is contained in:
Marco Castelluccio 2024-10-22 13:01:55 +02:00
Родитель aadbf8d9fd
Коммит f1b684c0a5
9 изменённых файлов: 41 добавлений и 9 удалений

Просмотреть файл

@ -16,7 +16,9 @@ from libmozdata import versions
from libmozdata.bugzilla import Bugzilla
from sklearn.base import BaseEstimator, TransformerMixin
from bugbug import bug_snapshot, bugzilla, repository
from bugbug import bug_snapshot, bugzilla, repository, utils
utils.setup_libmozdata()
def field(bug, field):

Просмотреть файл

@ -22,6 +22,8 @@ from bugbug import db, utils
basicConfig(level=INFO)
logger = getLogger(__name__)
utils.setup_libmozdata()
BugDict = NewType("BugDict", dict)
BUGS_DB = "data/bugs.json"
@ -444,7 +446,10 @@ def get_groups_users(group_names: list[str]) -> list[str]:
"names": group_names,
"membership": "1",
},
headers={"X-Bugzilla-API-Key": Bugzilla.TOKEN, "User-Agent": "bugbug"},
headers={
"X-Bugzilla-API-Key": Bugzilla.TOKEN,
"User-Agent": utils.get_user_agent(),
},
)
r.raise_for_status()
@ -553,7 +558,10 @@ def calculate_maintenance_effectiveness_indicator(
r = utils.get_session("bugzilla").get(
"https://bugzilla.mozilla.org/rest/bug",
params={**params, "count_only": 1},
headers={"X-Bugzilla-API-Key": Bugzilla.TOKEN, "User-Agent": "bugbug"},
headers={
"X-Bugzilla-API-Key": Bugzilla.TOKEN,
"User-Agent": utils.get_user_agent(),
},
)
r.raise_for_status()

Просмотреть файл

@ -95,7 +95,9 @@ if __name__ == "__main__":
import requests
from libmozdata.phabricator import PhabricatorAPI
from bugbug.utils import get_secret
from bugbug.utils import get_secret, setup_libmozdata
setup_libmozdata()
phabricator = PhabricatorAPI(
get_secret("PHABRICATOR_TOKEN"), get_secret("PHABRICATOR_URL")

Просмотреть файл

@ -11,12 +11,14 @@ import tenacity
from libmozdata.phabricator import PhabricatorAPI
from tqdm import tqdm
from bugbug import db
from bugbug import db, utils
from bugbug.db import LastModifiedNotAvailable
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
utils.setup_libmozdata()
RevisionDict = NewType("RevisionDict", dict)
TransactionDict = NewType("TransactionDict", dict)

Просмотреть файл

@ -30,7 +30,7 @@ import requests
from tqdm import tqdm
from bugbug import db, repository
from bugbug.utils import ExpQueue, LMDBDict
from bugbug.utils import ExpQueue, LMDBDict, get_user_agent
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@ -877,7 +877,7 @@ def get_failure_bugs(since: datetime, until: datetime) -> list[dict[str, int]]:
"https://treeherder.mozilla.org/api/failures/?startday={}&endday={}&tree=trunk".format(
since.strftime("%Y-%m-%d"), until.strftime("%Y-%m-%d")
),
headers={"Accept": "application/json", "User-Agent": "bugbug"},
headers={"Accept": "application/json", "User-Agent": get_user_agent()},
)
r.raise_for_status()
return r.json()

Просмотреть файл

@ -22,6 +22,7 @@ from typing import Any, Iterator
import boto3
import dateutil.parser
import libmozdata
import lmdb
import numpy as np
import psutil
@ -139,7 +140,7 @@ def get_taskcluster_options() -> dict:
return options
def get_secret(secret_id: str) -> Any:
def get_secret(secret_id: str, default_value: str | None = None) -> Any:
"""Return the secret value."""
env_variable_name = f"BUGBUG_{secret_id}"
@ -158,6 +159,9 @@ def get_secret(secret_id: str) -> Any:
return secret_bucket["secret"][secret_id]
elif default_value is not None:
return default_value
else:
raise ValueError("Failed to find secret {}".format(secret_id))
@ -495,6 +499,15 @@ def get_session(name: str) -> requests.Session:
return session
def get_user_agent():
return get_secret("USER_AGENT", "bugbug")
def setup_libmozdata():
libmozdata.config.set_config(libmozdata.config.ConfigEnv())
os.environ["LIBMOZDATA_CFG_USER-AGENT_NAME"] = get_user_agent()
def get_hgmo_stack(branch: str, revision: str) -> list[bytes]:
"""Load descriptions of patches in the stack for a given revision."""
url = f"https://hg.mozilla.org/{branch}/json-automationrelevance/{revision}"

Просмотреть файл

@ -42,6 +42,8 @@ from bugbug_http.sentry import setup_sentry
if os.environ.get("SENTRY_DSN"):
setup_sentry(dsn=os.environ.get("SENTRY_DSN"), integrations=[FlaskIntegration()])
utils.setup_libmozdata()
API_TOKEN = "X-Api-Key"
API_DESCRIPTION = """

Просмотреть файл

@ -36,6 +36,7 @@ from bugbug.utils import (
download_model,
escape_markdown,
get_secret,
setup_libmozdata,
zstd_compress,
zstd_decompress,
)
@ -43,6 +44,7 @@ from bugbug.utils import (
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
setup_libmozdata()
TEST_INFOS_DB = "data/test_info.json"
db.register(

Просмотреть файл

@ -9,13 +9,14 @@ from libmozdata.phabricator import PhabricatorAPI
from bugbug import db, phabricator
from bugbug.tools.code_review import PhabricatorReviewData
from bugbug.utils import get_secret, zstd_compress
from bugbug.utils import get_secret, setup_libmozdata, zstd_compress
review_data = PhabricatorReviewData()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
setup_libmozdata()
api = PhabricatorAPI(get_secret("PHABRICATOR_TOKEN"))