Skip to content

SP-4383: Environmental variable support - #157

Merged
Alex-1089 merged 2 commits into
mainfrom
feat/SP-4383_env-var-support
May 21, 2026
Merged

Alex-1089 merged 2 commits into
mainfrom
feat/SP-4383_env-var-support

Conversation

@Alex-1089

@Alex-1089 Alex-1089 commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • API configuration can be supplied via environment variables (SCANOSS_API_KEY, SCANOSS_SCAN_URL).
    • CLI arguments continue to take precedence over environment variables.
  • Tests

    • Added tests covering API configuration behavior, including env var support and CLI override scenarios.
  • Documentation

    • Changelog updated with the 0.13.2 entry noting environment variable support.

Review Change Stack

@Alex-1089
Alex-1089 requested a review from eeisegn May 21, 2026 14:30
@coderabbitai

coderabbitai Bot commented May 21, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1042dc1f-a910-4242-9650-cbe5cdd473ba

📥 Commits

Reviewing files that changed from the base of the PR and between 9baee42 and 119fdff.

📒 Files selected for processing (1)
  • CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

📝 Walkthrough

Walkthrough

Defaults for API URL/token are set earlier during config initialization. initializeApiConfig now populates API settings from SCANOSS_SCAN_URL and SCANOSS_API_KEY when arguments are empty, then applies CLI overrides. Tests and changelog were added to cover and document this behavior.

Changes

API Configuration Enhancement

Layer / File(s) Summary
Default settings and environment variable precedence
internal/config/config.go, CHANGELOG.md
Default viper values for apiurl and apitoken are moved to the start of initializeConfigFile. initializeApiConfig reads SCANOSS_SCAN_URL and SCANOSS_API_KEY when its apiUrl or apiKey arguments are empty, then applies existing CLI-flag overrides. Changelog entry for 0.13.2 documents the new env vars.
Configuration initialization tests
internal/config/config_test.go
New helper initConfigWithApiArgs resets the config singleton and initializes config with a temporary settings file. TestInitializeApiConfig adds subtests covering defaults, environment-variable population for API URL/key, and CLI-argument precedence over env vars.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through config fields today,
Env vars whispered what they'd say,
CLI flags danced to claim the crown,
Defaults set early, none let down,
A tiny rabbit cheers the change — hooray! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'SP-4383: Environmental variable support' accurately summarizes the main change: adding support for environment variables (SCANOSS_SCAN_URL and SCANOSS_API_KEY) in configuration initialization.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/SP-4383_env-var-support

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

SCANOSS SCAN Completed 🚀

  • Detected components: 3
  • Undeclared components: 0
  • Declared components: 3
  • Detected files: 188
  • Detected files undeclared: 0
  • Detected files declared: 188
  • Licenses detected: 2
  • Licenses detected with copyleft: 1
  • Policies: ✅ 1 pass (1 total)

View more details on SCANOSS Action Summary

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/config/config.go`:
- Around line 355-369: The env-var branch in initializeApiConfig currently
writes directly to c.apiUrl / c.apiToken which bypasses viper and
notifyListeners causing divergence and swallowed errors; update the logic to
either use viper.BindEnv("apiurl") / viper.BindEnv("apitoken") so viper reflects
env values, or call the existing setters c.SetApiUrl(v) and c.SetApiToken(v)
(which will call notifyListeners and return errors) / or at minimum call
viper.Set("apiurl"/"apitoken") followed by notifyListeners(); ensure you use the
initializeApiConfig function and SetApiUrl/SetApiToken or viper.BindEnv so
future viper.WriteConfig() persists the correct, non-stale values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 741d0bce-347f-4ff5-8649-c33fb106969a

📥 Commits

Reviewing files that changed from the base of the PR and between d8e66f0 and 9baee42.

📒 Files selected for processing (2)
  • internal/config/config.go
  • internal/config/config_test.go

Comment thread internal/config/config.go
@github-actions

Copy link
Copy Markdown

SCANOSS SCAN Completed 🚀

  • Detected components: 3
  • Undeclared components: 0
  • Declared components: 3
  • Detected files: 188
  • Detected files undeclared: 0
  • Detected files declared: 188
  • Licenses detected: 2
  • Licenses detected with copyleft: 1
  • Policies: ✅ 1 pass (1 total)

View more details on SCANOSS Action Summary

@Alex-1089
Alex-1089 merged commit 3b302fe into main May 21, 2026
6 checks passed
@Alex-1089
Alex-1089 deleted the feat/SP-4383_env-var-support branch May 21, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants