Skip to content

refactor(no-ticket): refactor metadata to shared util#292

Open
BartoszBlizniak wants to merge 1 commit into
masterfrom
refactor/metadata-common
Open

refactor(no-ticket): refactor metadata to shared util#292
BartoszBlizniak wants to merge 1 commit into
masterfrom
refactor/metadata-common

Conversation

@BartoszBlizniak
Copy link
Copy Markdown
Member

Description

Extracts the JSON-content resolution and source-identity defaulting logic out of cloudsmith metadata into a new shared module, cloudsmith_cli/cli/metadata_common.py, so push-time metadata flags (follow-up PR).

No behavior change for cloudsmith metadata — same flags, same errors, same output.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Other (please describe)

Additional Notes

What moved into cli/metadata_common.py

  • ResolvedMetadata dataclass — carries parsed content plus source labels through the command.
  • resolve_metadata_content(...) — enforces XOR between --file and --content, reads stdin/file/inline, parses JSON, validates it is an object. Replaces the private _load_content in
    cli/commands/metadata.py.
  • require_metadata_content_type(...) — guards the --content-type requirement when content is supplied.
  • attach_metadata_options(...) — folds content type and source identity onto a resolved payload.
  • default_metadata_source_identity() — replaces the private _default_source_identity (was cloudsmith-cli@<version>).
  • source_label_for(...) — human-readable label for stdin / filename / inline.
  • MetadataContentErrorClickException subclass that carries source_label so callers can render structured error context.

Verification

  • pytest cloudsmith_cli/cli/tests/test_metadata_common.py cloudsmith_cli/cli/tests/commands/test_metadata.py — green.
  • pre-commit run -a — clean.
  • Manual smoke: cloudsmith metadata add/update/list/remove against a test repo, both --file and --content paths, with valid + invalid JSON.

@BartoszBlizniak BartoszBlizniak requested a review from a team as a code owner May 11, 2026 15:44
Copilot AI review requested due to automatic review settings May 11, 2026 15:44
@BartoszBlizniak BartoszBlizniak changed the title chore(no-ticket): add metadata common and re-factor metadata command refactor(no-ticket): refactor metadata to shared util May 11, 2026
Copy link
Copy Markdown
Contributor

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

Refactors the cloudsmith metadata CLI command by extracting shared metadata content parsing/validation logic into a reusable module, with accompanying test updates and help-text/example tweaks.

Changes:

  • Added cli/metadata_common.py with helpers to resolve/parse JSON metadata content and attach related options.
  • Updated cli/commands/metadata.py to use the new shared helpers and refreshed help text/output strings.
  • Added/updated tests to cover the new helpers and ensure metadata command behavior around non-object JSON content.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
cloudsmith_cli/cli/metadata_common.py New shared helpers for resolving/parsing metadata JSON and attaching option defaults.
cloudsmith_cli/cli/commands/metadata.py Refactor to use shared helpers; adjusts help text and user-facing messages.
cloudsmith_cli/cli/tests/test_metadata_common.py New unit tests for the shared metadata helper module.
cloudsmith_cli/cli/tests/commands/test_metadata.py Updates help-text assertions and adds command-level tests for rejecting non-object JSON.

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

Comment thread cloudsmith_cli/cli/metadata_common.py
Comment thread cloudsmith_cli/cli/metadata_common.py
Comment thread cloudsmith_cli/cli/metadata_common.py
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