Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from keyman.KeyClient import KeyClient
from collectoss.tasks.github.util.github_data_access import RatelimitException, NotAuthorizedException, ResourceGoneException
from collectoss.util.keys import mask_key
from collectoss.util.version import get_user_agent

URL = "https://api.github.com/graphql"

Expand Down Expand Up @@ -83,7 +84,7 @@ def make_request(self, query, variables, timeout=40):
if not self.key:
self.key = self.key_client.request()

headers = {"Authorization": f"token {self.key}"}
headers = {"Authorization": f"token {self.key}", "User-Agent": get_user_agent()}


json_dict = {
Expand Down
25 changes: 25 additions & 0 deletions collectoss/util/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-License-Identifier: MIT
from importlib.metadata import version, PackageNotFoundError

_FALLBACK_VERSION = "unknown"
_PACKAGE_NAME = "collectoss"


def get_version() -> str:
"""Return the installed version of CollectOSS.

Falls back to 'unknown' if the package metadata is not available
(e.g. running from source without installing).
"""
try:
return version(_PACKAGE_NAME)
except PackageNotFoundError:
return _FALLBACK_VERSION


def get_user_agent() -> str:
"""Return the User-Agent string CollectOSS should send with API requests.

Format: CollectOSS/<version> (github:chaoss/collectoss; CHAOSS/Linux Foundation)
"""
return f"CollectOSS/{get_version()} (github:chaoss/collectoss; CHAOSS/Linux Foundation)"
Loading