Skip to content

Add repository option to crossplane project init#105

Open
bobh66 wants to merge 3 commits into
crossplane:mainfrom
bobh66:initrepo
Open

Add repository option to crossplane project init#105
bobh66 wants to merge 3 commits into
crossplane:mainfrom
bobh66:initrepo

Conversation

@bobh66

@bobh66 bobh66 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Description of your changes

Added the --repository option to crossplane project init to override the default example.com/my-org values.

Made the directory name truly optional.

I have:

Need help with this checklist? See the cheat sheet.

@bobh66 bobh66 requested review from a team, jcogilvie and tampakrap as code owners June 12, 2026 17:28
@bobh66 bobh66 requested review from jbw976 and removed request for a team June 12, 2026 17:28
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 84156d1c-26b4-4c7b-8075-e07e2e883c71

📥 Commits

Reviewing files that changed from the base of the PR and between 92b63fa and 4675ae8.

📒 Files selected for processing (1)
  • cmd/crossplane/project/init.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/crossplane/project/init.go

📝 Walkthrough

Walkthrough

The crossplane project init command adds a configurable Repository argument (with default), updates Name/Directory argument metadata, normalizes and validates Repository at runtime, and uses it to populate spec.repository as <Repository>/<name> in the generated project YAML.

Changes

Project initialization repository configuration

Layer / File(s) Summary
CLI argument declarations
cmd/crossplane/project/init.go
initCmd struct tags updated: Name keeps arg metadata, Directory tag adjusted, and new Repository field added with default:"example.com/my-org", help, optional, and short:"r" metadata.
Repository normalization and validation
cmd/crossplane/project/init.go
Run now trims trailing slashes from Repository and returns an error if the resulting repository prefix is empty.
Template repository formatting
cmd/crossplane/project/init.go
Generated crossplane-project.yaml spec.repository now uses the configured <Repository>/<name> instead of hardcoded example.com/my-org/<name>.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding a repository option to the crossplane project init command.
Description check ✅ Passed The description clearly relates to the changeset, explaining the addition of the --repository option and clarification that directory is optional.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Breaking Changes ✅ Passed PR only adds new optional --repository (defaulted) and makes Directory optional in cmd/crossplane/project/init.go; it does not remove/rename public flags/fields, and no breaking-change label is pre...
Feature Gate Requirement ✅ Passed Adds a --repository option and uses it in generated spec.repository for crossplane project init; no experimental/feature-flag gated API behavior was introduced. citeturn5view0turn7view0

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


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

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/crossplane/project/init.go`:
- Around line 77-78: Normalize and validate the repository base (c.Repository)
before composing spec.repository: ensure c.Repository is non-empty and trim any
trailing slashes or whitespace, then join it with c.Name using a safe join
(e.g., path.Join or by appending "/" then name) instead of raw "%s/%s"
concatenation so you never produce double slashes; update the code that formats
spec.repository (the spot using c.Repository and c.Name) to use the normalized
value and return or surface a validation error if repository is empty/invalid.
- Line 42: The Directory field in the project init command is currently declared
as a positional arg (arg:"") but also has a short flag, so --directory/-d won't
parse; change Directory in cmd/crossplane/project/init.go from a positional to a
real flag by removing arg:"" and replacing it with a name tag and the existing
short/help/type tags (e.g. name:"directory" short:"d" help:"Directory to
initialize..." type:"path"), and if you instead prefer a second positional arg
update the command help/examples in cmd/crossplane/project/help/init.md to show
the positional usage; locate the Directory field in the relevant struct to apply
the change.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb516f46-3c47-48a4-a6a1-4696dba3d528

📥 Commits

Reviewing files that changed from the base of the PR and between 079254b and 3943268.

📒 Files selected for processing (1)
  • cmd/crossplane/project/init.go

Comment thread cmd/crossplane/project/init.go Outdated
Comment thread cmd/crossplane/project/init.go Outdated
Make the directory name truly optional.

Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>
Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
cmd/crossplane/project/init.go (1)

65-68: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Whitespace-only repository values can pass validation and generate invalid spec.repository.

Could you confirm whether --repository " " should be rejected? On Line 65, only trailing / is trimmed; on Line 66 the emptiness check can be bypassed by whitespace, which then propagates to Line 81 and fails later in downstream repository parsing.

Suggested minimal fix
-	repo := strings.TrimRight(c.Repository, "/")
+	repo := strings.TrimRight(strings.TrimSpace(c.Repository), "/")
 	if repo == "" {
 		return errors.New("repository cannot be empty; set --repository to an OCI repository prefix like 'xpkg.crossplane.io/my-org'")
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/crossplane/project/init.go` around lines 65 - 68, The current validation
trims only trailing slashes and allows all-whitespace repository values to pass;
update the handling of c.Repository by applying strings.TrimSpace (and still
TrimRight for slashes if needed) to produce repo, then validate repo == "" after
trimming so that inputs like "--repository \"   \"" are rejected; ensure the
rest of the function (where repo is used to set spec.repository) uses this
trimmed repo variable (referencing c.Repository, repo) so downstream parsing no
longer sees whitespace-only values.
🧹 Nitpick comments (1)
cmd/crossplane/project/init.go (1)

50-83: ⚡ Quick win

Please add focused tests for repository normalization and optional directory behavior.

Thanks for the feature update — would you add table-driven coverage for: default repository, trailing slash trimming, whitespace-only rejection, and omitted directory defaulting to project name? This should lock in the intended CLI UX and prevent regressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/crossplane/project/init.go` around lines 50 - 83, Add table-driven unit
tests for initCmd.Run to validate repository normalization and directory
defaulting: create test cases for (1) default repository value (empty repo
should error with the same message as currently returned for repo == ""), (2)
repository with trailing slash gets normalized (strings.TrimRight) and appears
in generated content, (3) whitespace-only repository is rejected, and (4)
omitted Directory results in c.Directory being set to c.Name and used to create
projectFileName content; instantiate initCmd with appropriate fields, call Run
with a no-op SpinnerPrinter or wrap the inner logic (refer to initCmd.Run,
c.Repository, c.Directory, checkTargetDirectory, and projectFileName) and assert
expected errors or generated file/content behavior for each table row.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@cmd/crossplane/project/init.go`:
- Around line 65-68: The current validation trims only trailing slashes and
allows all-whitespace repository values to pass; update the handling of
c.Repository by applying strings.TrimSpace (and still TrimRight for slashes if
needed) to produce repo, then validate repo == "" after trimming so that inputs
like "--repository \"   \"" are rejected; ensure the rest of the function (where
repo is used to set spec.repository) uses this trimmed repo variable
(referencing c.Repository, repo) so downstream parsing no longer sees
whitespace-only values.

---

Nitpick comments:
In `@cmd/crossplane/project/init.go`:
- Around line 50-83: Add table-driven unit tests for initCmd.Run to validate
repository normalization and directory defaulting: create test cases for (1)
default repository value (empty repo should error with the same message as
currently returned for repo == ""), (2) repository with trailing slash gets
normalized (strings.TrimRight) and appears in generated content, (3)
whitespace-only repository is rejected, and (4) omitted Directory results in
c.Directory being set to c.Name and used to create projectFileName content;
instantiate initCmd with appropriate fields, call Run with a no-op
SpinnerPrinter or wrap the inner logic (refer to initCmd.Run, c.Repository,
c.Directory, checkTargetDirectory, and projectFileName) and assert expected
errors or generated file/content behavior for each table row.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 93e17c21-4531-4195-950c-bdee283d8b13

📥 Commits

Reviewing files that changed from the base of the PR and between 3943268 and 92b63fa.

📒 Files selected for processing (1)
  • cmd/crossplane/project/init.go

Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>
@bobh66

bobh66 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Docs PR crossplane/docs#1108

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant