-
Notifications
You must be signed in to change notification settings - Fork 142
feat(repo): Implement Repository Update Command #714
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
85aa514
7f4f12a
5299a21
0858010
c6dc1f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| title: harbor repo update | ||
| weight: 55 | ||
| --- | ||
| ## harbor repo update | ||
|
|
||
| ### Description | ||
|
|
||
| ##### Update a repository | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Update the description of a repository. | ||
|
|
||
| This command updates the description associated with a repository | ||
| within a Harbor project. | ||
|
|
||
| Examples: | ||
| # Update repository description using project/repository format | ||
| harbor repository update library/nginx --description "Official nginx image" | ||
|
|
||
| ```sh | ||
| harbor repo update [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ```sh | ||
| -d, --description string Repository description | ||
| -h, --help help for update | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ```sh | ||
| -c, --config string config file (default is $HOME/.config/harbor-cli/config.yaml) | ||
| -o, --output-format string Output format. One of: json|yaml | ||
| -v, --verbose verbose output | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [harbor repo](harbor-repo.md) - Manage repositories | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| .nh | ||
| .TH "HARBOR" "1" "Harbor Community" "Harbor User Manuals" | ||
|
|
||
| .SH NAME | ||
| harbor-repo-update - Update a repository | ||
|
|
||
|
|
||
| .SH SYNOPSIS | ||
| \fBharbor repo update [flags]\fP | ||
|
|
||
|
|
||
| .SH DESCRIPTION | ||
| Update the description of a repository. | ||
|
|
||
| .PP | ||
| This command updates the description associated with a repository | ||
| within a Harbor project. | ||
|
|
||
| .PP | ||
| Examples: | ||
| # Update repository description using project/repository format | ||
| harbor repository update library/nginx --description "Official nginx image" | ||
|
|
||
|
|
||
| .SH OPTIONS | ||
| \fB-d\fP, \fB--description\fP="" | ||
| Repository description | ||
|
|
||
| .PP | ||
| \fB-h\fP, \fB--help\fP[=false] | ||
| help for update | ||
|
|
||
|
|
||
| .SH OPTIONS INHERITED FROM PARENT COMMANDS | ||
| \fB-c\fP, \fB--config\fP="" | ||
| config file (default is $HOME/.config/harbor-cli/config.yaml) | ||
|
|
||
| .PP | ||
| \fB-o\fP, \fB--output-format\fP="" | ||
| Output format. One of: json|yaml | ||
|
|
||
| .PP | ||
| \fB-v\fP, \fB--verbose\fP[=false] | ||
| verbose output | ||
|
|
||
|
|
||
| .SH SEE ALSO | ||
| \fBharbor-repo(1)\fP |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ package api | |
| import ( | ||
| "github.com/goharbor/go-client/pkg/sdk/v2.0/client/repository" | ||
| "github.com/goharbor/go-client/pkg/sdk/v2.0/client/search" | ||
| "github.com/goharbor/go-client/pkg/sdk/v2.0/models" | ||
| "github.com/goharbor/harbor-cli/pkg/utils" | ||
| log "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
@@ -107,3 +108,25 @@ func SearchRepository(query string) (search.SearchOK, error) { | |
|
|
||
| return *response, nil | ||
| } | ||
|
|
||
| func UpdateRepository(projectName, repoName string, description string) error { | ||
| ctx, client, err := utils.ContextWithClient() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| repo := &models.Repository{ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you are creating a new blank repository object without fetching the info of the already existing repo from the api. I would expect that this could lead to some issues. I think the correct behavior would be something like getting the repo object from the api, updating the description and then calling the update request to the api. |
||
| Description: description, | ||
| } | ||
|
|
||
| _, err = client.Repository.UpdateRepository(ctx, &repository.UpdateRepositoryParams{ | ||
| ProjectName: projectName, | ||
| RepositoryName: repoName, | ||
| Repository: repo, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return 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.
It would be great to make the flag not mandatory but optional. In harbor-cli we usually open a small user tui for entering the information needed. For example see other update commands.