Skip to content

chore: migrate to transfer module#2075

Merged
fabianburth merged 3 commits into
open-component-model:mainfrom
jakobmoellerdev:use-transfer-cli
Mar 26, 2026
Merged

chore: migrate to transfer module#2075
fabianburth merged 3 commits into
open-component-model:mainfrom
jakobmoellerdev:use-transfer-cli

Conversation

@jakobmoellerdev

Copy link
Copy Markdown
Member

What this PR does / why we need it

this migrates to our new transfer lib in the CLI

Which issue(s) this PR fixes

fix open-component-model/ocm-project#933

Testing

mostly ran a lot of manual back and forth

Verification
  • I have tested the changes locally by running ocm

@jakobmoellerdev jakobmoellerdev requested a review from a team as a code owner March 26, 2026 11:51
@github-actions github-actions Bot added kind/chore chore, maintenance, etc. size/m Medium labels Mar 26, 2026
@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0333a70a-6b72-4ab0-aba9-8cc5b6cebf77

📥 Commits

Reviewing files that changed from the base of the PR and between 6ba632e and 670ddff.

⛔ Files ignored due to path filters (2)
  • cli/go.sum is excluded by !**/*.sum
  • cli/integration/go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • cli/cmd/transfer/component-version/cmd.go
  • cli/go.mod
  • cli/integration/go.mod
✅ Files skipped from review due to trivial changes (2)
  • cli/go.mod
  • cli/integration/go.mod
🚧 Files skipped from review as they are similar to previous changes (1)
  • cli/cmd/transfer/component-version/cmd.go

📝 Walkthrough

Walkthrough

The CLI transfer command now delegates graph construction, builder setup, and transformer configuration to the new ocm.software/open-component-model/bindings/go/transfer package and adds that module as a dependency; a local graph builder and internal enum helpers were removed.

Changes

Cohort / File(s) Summary
Transfer Command Refactoring
cli/cmd/transfer/component-version/cmd.go
Replaced local graphBuilder and internal enum mappings with calls into the transfer binding: use transfer.BuildGraphDefinition, transfer.WithTransfer(...) (with transfer.Component(...), transfer.ToRepositorySpec(...), transfer.FromResolver(...)) and transfer.NewDefaultBuilder(...). Removed local transformer registration and internal helper imports.
Module Dependencies
cli/go.mod, cli/integration/go.mod
Added dependency on ocm.software/open-component-model/bindings/go/transfer (v0.0.0-20260326091035-ef0ea1b8f695) to support the refactor.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as "CLI"
  participant Transfer as "transfer pkg\n(runnable builder + graph)"
  participant PM as "plugin registries\n(pm.ComponentVersionRepositoryRegistry\npm.ResourcePluginRegistry)"
  participant Cred as "CredentialGraph"
  participant Repo as "Repository / Resolver"

  CLI->>Transfer: BuildGraphDefinition(component, opts)
  Transfer->>Repo: FromResolver(spec)
  Transfer->>PM: NewDefaultBuilder(PM, ..., Cred)
  PM-->>Transfer: registry references
  Transfer->>Transfer: Compose transfer config (Component, ToRepoSpec, FromResolver)
  CLI->>Transfer: Process(graph)
  Transfer->>Repo: Fetch/Upload artifacts
  Transfer->>Cred: Resolve credentials
  Transfer-->>CLI: Result/Status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • jakobmoellerdev
  • Skarlso
  • frewilhelm

Poem

🐰 I hopped through code with nimble paws,
Moved transfer's work outside my claws.
Builders now call a shared domain,
Reused and tidy—less to maintain.
Hooray for modules, carrots, and gains! 🥕

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Linked Issues check ❓ Inconclusive The PR demonstrates the core objective of issue #933 by migrating CLI code to use the new transfer module, but lacks evidence of unit/integration test updates and documentation required by done criteria. Verify that unit and integration tests have been created/updated and that documentation has been added to satisfy issue #933's done criteria before merge.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change - migrating CLI code to use the new transfer module as the primary objective.
Description check ✅ Passed The description is related to the changeset, referencing the migration to the transfer lib and the linked issue #933.
Out of Scope Changes check ✅ Passed All changes are directly related to migrating CLI command code and dependencies to the transfer module as specified in issue #933; no out-of-scope modifications detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
cli/cmd/transfer/component-version/cmd.go (1)

157-192: Add a focused regression test for the option translation.

This block now owns the CLI contract for --copy-resources, --upload-as, and the resulting graph setup, but the PR only notes manual verification. A small table-driven test here would catch enum drift before it changes the generated graph unexpectedly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/cmd/transfer/component-version/cmd.go` around lines 157 - 192, Add a
focused table-driven regression test that exercises the CLI-to-graph translation
for the copy-resources and upload-as flags: for each case set copyResources and
FlagUploadAs values (including defaults and both enum variants) and invoke the
command code-path that runs the logic producing transfer.BuildGraphDefinition
(or call a small extracted helper that encapsulates the block creating copyMode,
upTyp and calling transfer.BuildGraphDefinition). Assert the resulting graph
definition (tgd) or the Builder inputs include the expected transfer.CopyMode
(via WithCopyMode) and transfer.UploadAs (via WithUploadType) values; stub/mocks
for repoProvider/creds are fine. Target the symbols copyMode/copyResources,
enum.Get(FlagUploadAs), upTyp, transfer.BuildGraphDefinition and the
WithCopyMode/WithUploadType options so future enum drift is caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cli/go.mod`:
- Line 38: The go.mod adds a new dependency
ocm.software/open-component-model/bindings/go/transfer
v0.0.0-20260326091035-ef0ea1b8f695 but corresponding checksums are missing from
cli/go.sum; fix it by running `go mod tidy` (or `go mod download`) in the cli
module to regenerate and populate cli/go.sum with the checksum entries for the
transfer module, then stage and commit the updated cli/go.sum alongside the
go.mod change.

---

Nitpick comments:
In `@cli/cmd/transfer/component-version/cmd.go`:
- Around line 157-192: Add a focused table-driven regression test that exercises
the CLI-to-graph translation for the copy-resources and upload-as flags: for
each case set copyResources and FlagUploadAs values (including defaults and both
enum variants) and invoke the command code-path that runs the logic producing
transfer.BuildGraphDefinition (or call a small extracted helper that
encapsulates the block creating copyMode, upTyp and calling
transfer.BuildGraphDefinition). Assert the resulting graph definition (tgd) or
the Builder inputs include the expected transfer.CopyMode (via WithCopyMode) and
transfer.UploadAs (via WithUploadType) values; stub/mocks for repoProvider/creds
are fine. Target the symbols copyMode/copyResources, enum.Get(FlagUploadAs),
upTyp, transfer.BuildGraphDefinition and the WithCopyMode/WithUploadType options
so future enum drift is caught.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1457dd6d-0ced-4136-8e10-e6fcd303f859

📥 Commits

Reviewing files that changed from the base of the PR and between 8cef52a and 6ba632e.

📒 Files selected for processing (2)
  • cli/cmd/transfer/component-version/cmd.go
  • cli/go.mod

Comment thread cli/go.mod
Signed-off-by: Jakob Möller <contact@jakob-moeller.com>
@matthiasbruns

Copy link
Copy Markdown
Contributor

tested with my handy test script

#!/bin/zsh

alias OCM='go run ../../main.go'
REGISTRY="ghcr.io/matthiasbruns/ocm-tutorials"
REGISTRY2="ghcr.io/matthiasbruns/ocm-tutorials-2"

pause() {
  echo "\n>>> Next: $1"
  echo "--- Press Enter to continue ---"
  read
}

# OCM --help

# create constructor.yaml
# https://stefanprodan.github.io/podinfo/podinfo-6.9.1.tgz
cat <<EOF > constructor.yaml
components:
- name: ocm.software/podinfo
  version: 6.9.1
  provider:
    name: ocm.software
  resources:
  - name: podinfo
    version: 6.9.1
    type: helmChart
    access:
      type: helm/v1
      helmRepository: https://stefanprodan.github.io/podinfo
      helmChart: podinfo-6.9.1.tgz
EOF

CTF_DIR=$(mktemp -d)
echo "Using temporary directory: $CTF_DIR"

pause "Add component version to CTF from constructor.yaml"

# add cv command
OCM add cv --repository ctf::$CTF_DIR --constructor constructor.yaml --skip-reference-digest-processing

HELM_REF="ctf::$CTF_DIR//ocm.software/podinfo:6.9.1"

pause "Create component version ($REGISTRY)"

# transfer
OCM transfer component-version $HELM_REF $REGISTRY --copy-resources --loglevel debug

# pause "Transfer with --upload-as localBlob (OCI registry)"

# transfer  --upload-as localBlob
# OCM transfer component-version $HELM_REF $REGISTRY --copy-resources --upload-as localBlob

pause "Transfer with --upload-as ociArtifact (OCI registry)"

# transfer  --upload-as ociArtifact
OCM transfer component-version $HELM_REF $REGISTRY --copy-resources --upload-as ociArtifact --loglevel debug

pause "Download resource using OCM CLI"

# rm downloaded if exists
rm -rf downloaded

# downloadCMD resource
OCM download resource https://$REGISTRY//ocm.software/podinfo:6.9.1 --identity name=podinfo,version=6.9.1 --output ./downloaded

good work

@matthiasbruns matthiasbruns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/chore chore, maintenance, etc. size/m Medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

move transfer into reusable module

3 participants