-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: suppport repo ls sub-namespace #768
Conversation
I have two design questions:
i.e. :
currently the
currently:
or
|
|
I think the latter is out-of-option. Consider the scenario: How can the result of |
cmd/oras/repository/ls.go
Outdated
hostname, namespace, _ := strings.Cut(args[0], "/") | ||
opts.hostname = hostname | ||
opts.namespace = namespace | ||
// namespace is invalid if a tag is provided | ||
if strings.Contains(namespace, ":") { | ||
return fmt.Errorf("invalid namespace") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we refactor this part into a function so that we can unit test it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing can be simplified in an easier way.
If args[0]
contains /
, we can parse it using ParseReference(). Otherwise, it is a hostname.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used ParseReference
and created the function parseRepoPath
to use in RunE
.
cmd/oras/repository/ls.go
Outdated
before, after, found := strings.Cut(repopath, requestedNamespace) | ||
if !found || after == "" || before != "" { | ||
return false | ||
} | ||
return after[0] == '/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It partially works and is not readable. Can we choose a simpler implementation?
The reason why it partially works is that the inNamespace("foo", "foo")
returns false
, which should be true
. You need unit tests to ensure code quality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be a UX issue other than a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used strings.HasPrefix(repopath, opts.namespace+"/")
here after discussion.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #768 +/- ##
==========================================
- Coverage 62.71% 55.86% -6.86%
==========================================
Files 20 23 +3
Lines 802 929 +127
==========================================
+ Hits 503 519 +16
- Misses 257 368 +111
Partials 42 42 ☔ View full report in Codecov by Sentry. |
This is a good question. I would suggest the latter one: $ oras repo ls example-registry/engineering
bestpractices
newhires/onboarding
newhires/teamoverview In this way, it is more consistent with the UNIX namespace=example-registry/engineering
oras repo ls $namespace | while read repo; do
repo=$namespace/$repo
echo Tags in $repo:
oras repo tags $repo
echo
done |
@wangxiaoxuan273 I vote for the latter one and agree with @shizhMSFT 's suggestion. |
Then |
@@ -60,15 +68,34 @@ Example - List the repositories under the registry that include values lexically | |||
return cmd | |||
} | |||
|
|||
func parseRepoPath(opts *repositoryOptions, arg string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add unit tests for this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added unit tests.
cmd/oras/repository/ls.go
Outdated
return err | ||
} | ||
opts.hostname = reference.Registry | ||
opts.namespace = reference.Repository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opts.namespace = reference.Repository | |
opts.namespace = reference.Repository + "/" |
so that we don't need to calculate it multiple time in a loop at line 96.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed accordingly.
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Resolves #733
Test output on terminal:
Signed-off-by: wangxiaoxuan273 wangxiaoxuan119@gmail.com