Skip to content

feat: add User-Agent header to all GitHub API calls#433

Open
Dipro-cyber wants to merge 1 commit into
chaoss:mainfrom
Dipro-cyber:feat/user-agent-header-408
Open

feat: add User-Agent header to all GitHub API calls#433
Dipro-cyber wants to merge 1 commit into
chaoss:mainfrom
Dipro-cyber:feat/user-agent-header-408

Conversation

@Dipro-cyber

Copy link
Copy Markdown
Contributor

Description
Adds a User-Agent header to all outgoing GitHub API requests so GitHub
can identify traffic from CollectOSS tooling. This helps with bot
detection, allows GitHub staff to reach out if needed, and will benefit
future support for other forge instances (Forgejo etc.).

The User-Agent format is:
CollectOSS/1.0.0 (github:chaoss/collectoss; CHAOSS/Linux Foundation)

A get_user_agent() helper is added to metadata.py so the version
number stays in sync with the project version automatically. Applied in:

  • github_data_access.py (REST API — primary path)
  • github_graphql_data_access.py (GraphQL API)
  • github_api_key_handler.py (key validation calls)
  • github_paginator.py (deprecated hit_api path)

This PR fixes #408

Notes for Reviewers
No logic changes — purely additive header injection. The get_user_agent()
helper in metadata.py makes the version easy to update in one place.

Signed commits

  • Yes, I signed my commits.

Generative AI disclosure

  • This contribution was assisted or created by Generative AI tools.
  • What tools were used? Kiro (Claude-based AI coding assistant)
  • How were these tools used? Helped locate all API call sites and draft the changes
  • Did you review these outputs before submitting this PR? Yes

@Dipro-cyber Dipro-cyber requested a review from MoralCode as a code owner June 30, 2026 11:38
@MoralCode

Copy link
Copy Markdown
Contributor

Can you fix the merge conflicts?

Also I'm not sure that the strategy of importing from the metadata file is going to work. It was tried when we rolled out #322 and we ended up backtracking on using the version number because the imports were complaining about importing something from outside the module or something.

#251 i think was the issue created as a result of this problem

@MoralCode

Copy link
Copy Markdown
Contributor

we might need to find a way to resolve that metadata problem before this PR will be possible. I think the version number is somewhat more important to include in the user agent than the database connection args.

- Moves get_user_agent() into collectoss/util/version.py using
  importlib.metadata to read the version, avoiding the metadata.py
  import-outside-module issue (chaoss#251/chaoss#322)
- Falls back to 'unknown' if the package is not installed
- Updates github_graphql_data_access.py to use new import path and
  resolves merge conflicts with upstream changes to that file

Signed-off-by: Diptesh Roy <droy88333@gmail.com>
@Dipro-cyber Dipro-cyber force-pushed the feat/user-agent-header-408 branch from 5c3f96c to 3cf1051 Compare July 1, 2026 16:21
@Dipro-cyber

Copy link
Copy Markdown
Contributor Author

Fixed the merge conflicts and replaced the metadata.py import with a new version.py helper that uses importlib.metadata to read the version, avoids the import issue from #251/#322.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Have CollectOSS declare (via a user agent header) itself in API calls to github

2 participants