Skip to content

fix: write reliability and error-handling fixes#7

Merged
joe-niland merged 8 commits into
masterfrom
fix/write-reliability-and-error-handling
Jun 18, 2026
Merged

fix: write reliability and error-handling fixes#7
joe-niland merged 8 commits into
masterfrom
fix/write-reliability-and-error-handling

Conversation

@joe-niland

@joe-niland joe-niland commented Jun 18, 2026

Copy link
Copy Markdown
Member

This pull request introduces several improvements and bug fixes to the GitLab project variables management tool, along with enhanced documentation and expanded test coverage. The most significant changes include improved error handling, idempotent export behavior, and comprehensive tests for core functionality and edge cases.

Bug fixes and behavior improvements:

  • Fixed a bug in the write command where updating variables in a previously unseen environment scope could fail by using .get() with a default empty list (src/populate_secrets_gitlab/app.py).
  • Improved error handling for missing GITLAB_TOKEN by raising a click.ClickException instead of a generic Exception, ensuring cleaner CLI exits without tracebacks (src/populate_secrets_gitlab/app.py).
  • Changed error handling for GitLab API errors in the write command to specifically catch gitlab.exceptions.GitlabError, providing clearer log messages (src/populate_secrets_gitlab/app.py).
  • Made the get --export command idempotent by ensuring environment files are not appended to multiple times during a single run, preventing duplicate lines (src/populate_secrets_gitlab/app.py).

Documentation updates:

  • Added an overview, detailed command descriptions, and a new example for the download command to README.md for better usability and clarity. [1] [2]

Testing and development tooling:

  • Added a new test suite in tests/test_app.py covering:
    • Variable creation and updating for fresh and existing environments
    • Masking heuristics for secret keys
    • Consistent error handling for missing tokens
    • Idempotence of get --export
    • Scope filtering logic for environment/global variables
  • Added a test for the prepare_gitlab_host utility function in tests/test_util.py.
  • Introduced a dev dependency group with pytest in pyproject.toml for easier test setup.

…istent token error, and idempotent get --export

- Use .get(environment, []) instead of [environment] on the scope dict
  so write does not KeyError on a brand-new environment with zero
  existing variables.
- Narrow except Exception to except gitlab.exceptions.GitlabError so
  programming errors (like the above KeyError) surface instead of being
  swallowed as "unexpected error".
- Use click.ClickException in the get command for missing GITLAB_TOKEN,
  matching write/list/download (clean message, no traceback).
- Track which scope files have been opened during get --export so each
  file is truncated on first write and appended thereafter, preventing
  duplicate lines on re-run.
… and scope filtering

Covers the critical logic paths:
- Regression test for write to fresh environment scope (Task 1 fix)
- Masking heuristic (KEY/SECRET/TOKEN substring match)
- Consistent click.ClickException on missing GITLAB_TOKEN for all commands
- get --export idempotence (no duplicate lines on re-run)
- Scope filtering (global * vars included, other-env vars excluded)
- prepare_gitlab_host URL normalisation
@joe-niland joe-niland changed the title docs: add overview section and document download command fix: write reliability and error-handling fixes Jun 18, 2026
- Remove .%s from datefmt in logging.basicConfig (%s is not a valid
  strftime directive and renders literally).
- Remove trailing blank line in gitlab_server.py.
Without explicit config, the Python release type treats every
conventional commit as release-worthy. The config marks docs, test,
ci, refactor, and chore sections as hidden so they ride along in
the changelog but do not trigger a version bump on their own.
uv sync --group dev failed in CI. Use uv run --group dev instead,
which auto-syncs before running. Add ruff to dev dependency group
so it resolves through the project.
@joe-niland joe-niland merged commit 3fed1e0 into master Jun 18, 2026
2 checks passed
@joe-niland joe-niland deleted the fix/write-reliability-and-error-handling branch June 18, 2026 09: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.

1 participant