Skip to content

Ignore empty GitHub API keys - #484

Merged
MoralCode merged 5 commits into
chaoss:mainfrom
drkrillo:fix/empty-api-keys-378
Nov 23, 2026
Merged

MoralCode merged 5 commits into
chaoss:mainfrom
drkrillo:fix/empty-api-keys-378

Conversation

@drkrillo

@drkrillo drkrillo commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When COLLECTOSS_GITHUB_API_KEY env variable was set to one or more whitespaces or left empty, that counted as set config_key, causing httpx.LocalProtocolError: Illegal header value b'token '.

Now, in GithubApiKeyHandler.get_api_keys():

  • If the key is set to one or more whitespaces or left empty, a warning is logged and the code doesn't add it to the keys list (new cases).
  • If its None, the warning is not logged and doesn't add the key (already covered before the fix).

Added tests/test_classes/test_github_api_keys.py covering the config key cases:
empty and whitespaces with and without database keys, None, and a valid key. Each one
asserts the key list, if the key is probed, and the warning.

docker compose up --build logs after the fix:

core-1      | 2026-09-16 23:41:45 097a6abde2c1 collectoss[33] WARNING GitHub API key is an empty string. Please, add a valid one.
core-1      | 2026-09-16 23:41:45 097a6abde2c1 collectoss[33] INFO Retrieved 0 github api keys for use

This PR fixes part of #378

Notes for Reviewers

  • The same issue is present in GitlabApiKeyHandler.get_api_keys(). I didn't add that fix here, just GitHub's. Let me know if I can open up a follow-up PR, open an issue (or both) or add the code and tests in this same PR.

Signed commits

  • Yes, I signed my commits.

Generative AI disclosure

Please select one option:

  • This contribution was NOT assisted or created by Generative AI tools.
  • This contribution was assisted or created by Generative AI tools.

If AI tools were used, please provide details below:
- What tools were used? Claude
- How were these tools used? Code review and tests guidance (not writing, suggested new ones covering cases I didn't consider)
- Did you review these outputs before submitting this PR? Yes, all the code was written by me, trying different approaches and Claude was used to review the changes.

Summary by CodeRabbit

  • Bug Fixes
    • Configured GitHub API keys now have surrounding whitespace removed before use. Empty keys are skipped, with a warning logged.
    • Database key handling remains unchanged.

Signed-off-by: Juan Pasutti <juanpasutti@gmail.com>
@drkrillo
drkrillo requested a review from MoralCode as a code owner September 17, 2026 01:19

@MoralCode MoralCode left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution and welcome to CHAOSS (i see this is your first contribution)! Had some questions about the code

Signed-off-by: Juan Pasutti <juanpasutti@gmail.com>
@MoralCode

Copy link
Copy Markdown
Contributor

The same issue is present in GitlabApiKeyHandler.get_api_keys(). I didn't add that fix here, just GitHub's. Let me know if I can open up a follow-up PR, open an issue (or both) or add the code and tests in this same PR.

id say for this if you update your pr description to say "fixes part of" the referenced issue (break the automatic closure that will otherwise happen when this merges) and then we can have the gitlab version in another PR.

Signed-off-by: Juan Pasutti <juanpasutti@gmail.com>
@drkrillo
drkrillo force-pushed the fix/empty-api-keys-378 branch from ba479f3 to 5e74418 Compare September 24, 2026 15:31
Signed-off-by: Juan Pasutti <juanpasutti@gmail.com>
@MoralCode

Copy link
Copy Markdown
Contributor

@drkrillo sorry this kinda fell off the wagon - PR looks good (and thanks for including unit tests) - my main concern is what reviewdog flagged about assert_not_called() not existing. are those just erroneous?

Signed-off-by: Juan Pasutti <juanpasutti@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The GitHub API key handler trims whitespace from configured keys and skips empty keys. New tests cover None, empty, padded, and valid keys, including cases with database keys.

Changes: GitHub API key handling

Layer / File(s) Summary
Normalize and validate configured keys
collectoss/tasks/github/util/github_api_key_handler.py, tests/test_classes/test_github_api_keys.py
The handler trims configured keys and warns when trimming changes a key. It skips empty configured keys and warns when a key is empty. Tests check returned keys, validation calls, Redis updates, and warnings.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • Issue 378: The changes skip empty GitHub API keys, addressing the reported cause in the GitHub handler. The issue summary says the GitLab handler remains unchanged.

Suggested reviewers: moralcode, abrain7710

Merge Risk: Minimal · up to c8dc4

Empty or whitespace-only GitHub API keys are now excluded with a warning, and padded keys are trimmed. This avoids the illegal-header error. No concrete merge-blocking risk remains. The GitLab handler still has the same issue, which the author deliberately left out of this change.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Ignore empty GitHub API keys" matches the main change. The PR stops empty and whitespace-only COLLECTOSS_GITHUB_API_KEY values from entering the GitHub key list, and it logs a warning for t…
Description check Passed The description follows the repository template. It has a summary of the change, a reference to the partial fix of issue #378, reviewer notes about the GitLab handler, a signed-commits checkbox, and a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Ignore empty GitHub API keys" matches the main change. The PR stops empty and whitespace-only COLLECTOSS_GITHUB_API_KEY values from entering the GitHub key list, and it logs a warning for them. The title is short, specific, and names the provider.

Full details: Description check

Explanation

The description follows the repository template. It has a summary of the change, a reference to the partial fix of issue #378, reviewer notes about the GitLab handler, a signed-commits checkbox, and a completed Generative AI disclosure with tool details. It also gives the behavior change, the new test file, and log output from a docker run. The template's "Notes for Reviewers" section is filled in. The description does not state a contribution-specific reason for the partial fix beyond the GitLab note, but this does not block the check.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d48197d-1a68-4fdb-92fa-33f0d0c4ac2b
Commits

Reviewing files that changed from the base of the PR and between b85ad45 and c8dc424.

Files selected for processing: 2

  • collectoss/tasks/github/util/github_api_key_handler.py
  • tests/test_classes/test_github_api_keys.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@274301d). Learn more about missing BASE report.

Additional details and impacted files
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@drkrillo

Copy link
Copy Markdown
Collaborator Author

my main concern is what reviewdog flagged about assert_not_called() not existing. are those just erroneous?

hey, yes, the asserts do work but pylint couldnt see that RedisList is patched with a mock. pushed a small change and reviewdog is clean now

@MoralCode

Copy link
Copy Markdown
Contributor

SGTM!

@MoralCode
MoralCode merged commit cfcf302 into chaoss:main Nov 23, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants