-
Notifications
You must be signed in to change notification settings - Fork 147
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
Add '--branch' to command 'repository add' #1287
Conversation
1bd7385
to
bf9d0e4
Compare
Codecov Report
@@ Coverage Diff @@
## main #1287 +/- ##
==========================================
+ Coverage 47.15% 47.61% +0.46%
==========================================
Files 72 72
Lines 10229 10259 +30
==========================================
+ Hits 4823 4885 +62
+ Misses 4980 4951 -29
+ Partials 426 423 -3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
Thanks for the PR! A couple of comments:
-
Could we implement internally using URL fragment identifiers (
#<refspec>
?
The--branch
flag is good to include in the CLI for discoverability, but I wonder if it would be better implemented internally using a#<branch>
suffix on the URL. This will clean up the API, make --verbose mode correct by default, allow added repository URLs to be canonical, and allow us to specify tags as well ([url]#v1.2.3
) without altering the code in any way. I am interested to hear anyone else's opinion. -
When listing repositories in verbose mode:
func repositories list --verbose
, it would be nice to also see the branch. As stated above this would just work if using a#<refspec>
URL fragment identifier suffix. -
The usage text of the command needs to be updated to include the new flag.
{{.Name}} repo add <name> <url> [--branch] [-r|--repositories] [-c|--confirm] [-v|--verbose]
- If we do go down the suggested route of supporting refspec as a URL fragment, that would be nice to be mentioned in the command's help text as well.
cmd/repository.go
Outdated
@@ -191,6 +191,7 @@ func NewRepositoryAddCmd(newClient ClientFactory) *cobra.Command { | |||
} | |||
|
|||
cmd.Flags().BoolP("confirm", "c", cfg.Confirm, "Prompt to confirm all options interactively (Env: $FUNC_CONFIRM)") | |||
cmd.Flags().StringP("branch", "", "main", "The repository branch to be added. Default is main branch") |
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.
The command help text automatically includes the default value, so there is no need for the second sentence here.
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.
Also, I do not think we should include a default, because cloning a repository automatically clones the default branch, and not everyone uses main
.
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.
Fixed in the new version.
cmd/repository.go
Outdated
@@ -317,7 +318,7 @@ func runRepositoryList(_ *cobra.Command, args []string, newClient ClientFactory) | |||
} | |||
|
|||
// Add | |||
func runRepositoryAdd(_ *cobra.Command, args []string, newClient ClientFactory) (err error) { | |||
func runRepositoryAdd(cmd *cobra.Command, args []string, newClient ClientFactory) (err 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.
The cmd
argument is not used, so it can either stay _
, or (perhaps better yet) change the method signature to completely remove the argument (which would require an update to lines 240-241)
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.
Fixed in the new version.
@@ -394,7 +397,7 @@ func runRepositoryAdd(_ *cobra.Command, args []string, newClient ClientFactory) | |||
|
|||
// Add repository | |||
var n string | |||
if n, err = client.Repositories().Add(params.Name, params.URL); err != nil { | |||
if n, err = client.Repositories().Add(params.Name, params.URL, params.Branch); err != nil { |
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.
I understand that, here in the CLI, it makes sense to also allow setting branch using a flag, so if we go down the route of using a #
in the URL to specify branch in the core library API, then it could be accomplished here with something like:
if cfg.Branch != "" {
params.URL = params.URL + "#" + cfg.Branch
}
.. and from that point on the core library API would remain the same, and with a test or two to ensure it works, we would be supporting any refspec
; not just branches.
cmd/repository_test.go
Outdated
@@ -47,6 +47,7 @@ func TestRepository_Add(t *testing.T) { | |||
|
|||
// add [flags] <old> <new> | |||
add.SetArgs([]string{ | |||
"--branch=main", |
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.
The addition of this argument to the test does not actually test anything, because it is set to the same value as the flag default.
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.
Fixed in the new version
@@ -166,14 +166,14 @@ func (r *Repositories) Get(name string) (repo Repository, err error) { | |||
// Add a repository of the given name from the URI. Name, if not provided, | |||
// defaults to the repo name (sans optional .git suffix). Returns the final | |||
// name as added. | |||
func (r *Repositories) Add(name, uri string) (string, error) { | |||
func (r *Repositories) Add(name, uri, branch string) (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.
As explained above, we may want to consider leaving this API the same, and expecting branch
to be provided as part of the optional uri.
@@ -125,12 +127,13 @@ type templateConfig = funcDefaults | |||
// the given URI. | |||
// URI (optional), the path either locally or remote from which to load | |||
// the repository files. If not provided, the internal default is assumed. | |||
func NewRepository(name, uri string) (r Repository, err error) { | |||
func NewRepository(name, uri, branch string) (r Repository, err 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.
Please update the doc string above this exported function with the new optional argument.
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.
Thanks. fixed.
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.
Thanks for the PR. Looks good but I think I tend to agree with @lkingland regarding the use of an optional #<branchname>
on the end of the URI. If that's the case, then you can ignore my two comments. :)
cmd/repository.go
Outdated
@@ -191,6 +191,7 @@ func NewRepositoryAddCmd(newClient ClientFactory) *cobra.Command { | |||
} | |||
|
|||
cmd.Flags().BoolP("confirm", "c", cfg.Confirm, "Prompt to confirm all options interactively (Env: $FUNC_CONFIRM)") | |||
cmd.Flags().StringP("branch", "", "main", "The repository branch to be added. Default is main branch") |
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.
Probably good to have $FUNC_BRANCH
in the environment as well, adding it to the bindEnv()
call on line 185.
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.
Thanks. Fixed in the new version.
cmd/repository.go
Outdated
}{} | ||
if len(args) > 0 { | ||
params.Name = args[0] | ||
} | ||
if len(args) > 1 { | ||
params.URL = args[1] | ||
} | ||
params.Branch, _ = cmd.Flags().GetString("branch") |
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.
Nit. Might be cleaner as
params.Branch, _ = cmd.Flags().GetString("branch") | |
params.Branch = viper.GetString("branch") |
But also below... can you add a survey question for branch here?
https://github.com/knative-sandbox/kn-plugin-func/blob/abc4de5b8f064ec318ff2a4fba27163d34a64aa3/cmd/repository.go#L367-L384
Thanks for the review. Just back from national holidays. working on a new version of PR now. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: daisy-ycguo The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov ReportBase: 47.20% // Head: 49.50% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1287 +/- ##
==========================================
+ Coverage 47.20% 49.50% +2.29%
==========================================
Files 74 77 +3
Lines 10409 10571 +162
==========================================
+ Hits 4914 5233 +319
+ Misses 5069 4895 -174
- Partials 426 443 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Hi @daisy-ycguo just checking in to see if you've had a chance to look into these test failures. |
@daisy-ycguo: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Hi @daisy-ycguo just checking in here - any progress? |
@daisy-ycguo gentle ping |
Changes
Fixes #1197