Skip to content

Comments

Add support for default project ID via config and environment#23

Merged
stympy merged 6 commits intomainfrom
claude/env-var-project-id-IDTlX
Feb 11, 2026
Merged

Add support for default project ID via config and environment#23
stympy merged 6 commits intomainfrom
claude/env-var-project-id-IDTlX

Conversation

@stympy
Copy link
Member

@stympy stympy commented Feb 10, 2026

Summary

This PR adds support for configuring a default project ID through configuration files and environment variables, eliminating the need to specify --project-id flag for every command that requires it.

Key Changes

  • Configuration Support: Added project_id configuration option to YAML config files and HONEYBADGER_PROJECT_ID environment variable support
  • Fallback Logic: Updated all Data API commands to fall back to the configured default project ID when the --project-id flag is not provided
  • Improved Error Messages: Updated error messages to inform users they can set the project ID via flag, config file, or environment variable
  • Commands Updated: Applied changes across all affected command files:
    • cmd/checkins.go (5 commands)
    • cmd/comments.go (5 commands)
    • cmd/deployments.go (3 commands)
    • cmd/environments.go (5 commands)
    • cmd/faults.go (5 commands)
    • cmd/insights.go (1 command, also removed redundant flag requirement)
    • cmd/uptime.go (7 commands)
  • Documentation: Updated README.md with examples of the new configuration options

Implementation Details

  • The implementation uses Viper's GetInt("project_id") to retrieve the configured default value
  • Each command checks if the project ID flag is zero, and if so, attempts to load it from configuration
  • If still zero after the fallback, the command returns an error with updated guidance
  • This maintains backward compatibility while providing a more convenient workflow for users working with a single project

https://claude.ai/code/session_01WT7m3r3dcygQtJYdacCnN7

Allow the project ID to be provided via the HONEYBADGER_PROJECT_ID
environment variable as a fallback when the --project-id flag is not
set. This follows the same pattern used by HONEYBADGER_API_KEY and
HONEYBADGER_AUTH_TOKEN, leveraging Viper's AutomaticEnv with the
HONEYBADGER prefix.

Updated all commands that accept --project-id (faults, check-ins,
comments, deployments, environments, insights, uptime) to check
viper for the project_id config key when the flag value is zero.
Also removed MarkFlagRequired for project-id in insights since the
value can now come from the environment.

https://claude.ai/code/session_01WT7m3r3dcygQtJYdacCnN7
Add project_id to the config file example and HONEYBADGER_PROJECT_ID
to the environment variables section.

https://claude.ai/code/session_01WT7m3r3dcygQtJYdacCnN7
Copilot AI review requested due to automatic review settings February 10, 2026 11:30
Break the project ID error message across multiple lines to satisfy
the golines line-length linter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a “default project ID” mechanism for Data API commands so users don’t need to pass --project-id on every invocation, by falling back to project_id from Viper config / HONEYBADGER_PROJECT_ID.

Changes:

  • Added per-command fallback logic: if --project-id is unset/0, read project_id from configuration.
  • Updated “missing project ID” validation errors and removed the project-id required-flag constraint for insights query.
  • Updated README configuration + environment variable examples to include project_id / HONEYBADGER_PROJECT_ID.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
cmd/checkins.go Adds project ID fallback to project_id before validating presence.
cmd/comments.go Adds project ID fallback to project_id before validating presence.
cmd/deployments.go Adds project ID fallback to project_id before validating presence.
cmd/environments.go Adds project ID fallback to project_id before validating presence.
cmd/faults.go Adds project ID fallback to project_id before validating presence.
cmd/insights.go Adds project ID fallback + removes project-id as a required flag.
cmd/uptime.go Adds project ID fallback to project_id before validating presence.
README.md Documents new project_id config key and HONEYBADGER_PROJECT_ID env var.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

stympy and others added 3 commits February 10, 2026 04:18
Address PR review feedback:
- Extract repeated project ID resolution into resolveProjectID() helper
- Update error message to mention config file as a valid source
- Add test coverage for viper config fallback path

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The project_id key was never registered with viper (unlike api_key,
auth_token, and endpoint which are bound via BindPFlag). Without
registration, viper.GetInt("project_id") with AutomaticEnv doesn't
find the HONEYBADGER_PROJECT_ID environment variable.

Add viper.BindEnv("project_id") in initConfig to explicitly register
the key for env var lookup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@stympy stympy marked this pull request as ready for review February 10, 2026 13:02
@stympy stympy requested a review from a team February 10, 2026 13:02
Copy link
Member

@joshuap joshuap left a comment

Choose a reason for hiding this comment

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

This should work with hbtui as well. 👍

@stympy stympy merged commit cae7b71 into main Feb 11, 2026
4 checks passed
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.

3 participants