Skip to content

Conversation

@brianredbeard
Copy link

Summary

  • Add safe environment variable access patterns using os.environ.get() with fallbacks
  • Add specific exception handling with error context logging
  • Fix variable scope issues to prevent UnboundLocalError
  • Add check=True to subprocess calls to catch failures
  • Make repository paths and timeouts configurable via environment variables

Changes

create_ci_badge.py

  • Use os.environ.get("HOME", "/tmp") instead of direct dict access
  • Validate WORKSPACE and versions before use
  • Replace bare except Exception with specific exception types
  • Include exception details in error messages

test_modify_web_content.py

  • Initialize route = None before loop to fix scope issue
  • Add check=True to subprocess.run() calls
  • Add PATTERNS_REPO_PATH environment variable for configurable paths
  • Extract timeout values to configurable constants

Test Plan

  • Run pytest on modified test files
  • Verify tests pass with and without environment variables set

Fixes #512
Fixes #513
Fixes #514
Fixes #515
Fixes #516
Fixes #517
Fixes #518
Fixes #519
Fixes #520
Fixes #521

…e.py

- Use os.environ.get() for HOME to avoid KeyError at module load
- Handle all exception types in get_openshift_version() (KeyError, JSONDecodeError, etc.)
- Check subprocess return code before processing output
- Validate versions tuple is not None before indexing
- Validate WORKSPACE exists and is a directory before os.listdir()
- Validate PATTERN_SHORTNAME and INFRA_PROVIDER before string concatenation
- Exit with error code on failures instead of crashing
…_web_content.py

- Initialize route variable before loop to avoid UnboundLocalError
- Add explicit check for route being None after loop
- Check subprocess return codes for git add, commit, and push
- Log errors when git commands fail
- Make timeout and poll interval configurable via environment variables
- Initialize new_content before while loop to avoid UnboundLocalError
- Add PATTERNS_REPO_PATH environment variable with sensible default
- Use os.path.join for proper path construction
- Removes hardcoded path that assumed specific directory structure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment