Skip to content
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

Fixes #178 #203

Merged
merged 5 commits into from
Apr 14, 2022
Merged

Fixes #178 #203

merged 5 commits into from
Apr 14, 2022

Conversation

converge
Copy link
Contributor

@converge converge commented Apr 9, 2022

- What I did

Fix one of the bugs reported by #178 and improve error handling for the repository deletion. The repository cannot be deleted if Docker Hub username is not provided.

how to reproduce the issue:

# 1
hub-tool repo rm test
# 2
the output is a successful message because the HTTP response is not validated.

- How I did it

  1. The fix includes the username to the repository deletion endpoint
  2. Adds new error handler for HTTP Not Found
  3. In case the repository doesn't exist, there is a proper error response: Error: resource not found
  4. Improves the error message, making it clear which repository was deleted
  5. Improve how URL is built before requesting the API

- How to verify it

The impacted changes can be tested via:

./hub-tool repo rm repository-name

- Description for the changelog

Allow repository deletion by using repository name only (without username) and add error handler for resource/repository not found.

p.s: this PR doesn't fix one of the reported errors:

Error: operation not permitted error

Since this is an ongoing discussion: #172

- A picture of a cute animal (not mandatory)

converge added 3 commits April 9, 2022 23:46
Signed-off-by: João Vanzuita <joaovanzuita@me.com>
Signed-off-by: João Vanzuita <joaovanzuita@me.com>
Signed-off-by: João Vanzuita <joaovanzuita@me.com>
@converge converge changed the title Fixes #178 issue Fixes #178 Apr 9, 2022
@converge converge marked this pull request as ready for review April 9, 2022 22:23
@@ -77,12 +76,17 @@ func (c *Client) GetRepositories(account string) ([]Repository, int, error) {

//RemoveRepository removes a repository on Hub
func (c *Client) RemoveRepository(repository string) error {
req, err := http.NewRequest("DELETE", c.domain+fmt.Sprintf(DeleteRepositoryURL, repository), nil)
repositoryUrl := fmt.Sprintf("%s%s%s/%s/", c.domain, RepositoriesURL, c.account, repository)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to point out that prefixing the user account to the repository name by default won't work. You can be part of many organizations, and so you may need to specify the full repository name <org>/<repo>.
With this code it will result with <user>/<org>/<repo>.
Maybe we should parse the repository argument, check if an org (or user) is already specified, and if not prefix with user account ? WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@silvin-lubecki tks for the review. That's true, I don't have access to a /paid account, and I couldn't test this use-case. I'll look for a paid account, and follow up with your comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@silvin-lubecki I slept on that, and I believe the cleanest way to solve is to follow a pattern for the deletion. Allowing the user to not provide a prefix(username), and request the user to provide the organization name could be confusing.

My last commit makes it clear the user needs to always provide a prefix (username or organization name) together with the repository name. WDYT?

p.s: it was tested with user repo. and organization repo. Lint issue was also fixed, I wasn't aware of the linting 🙈

Copy link
Collaborator

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

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

Hello @converge, thank you for your PR 🙏
The new error handling is good to me, but not the account info part (see my other comment) 👍

@silvin-lubecki
Copy link
Collaborator

By the way @converge the linter is complaining 🦁
https://github.com/docker/hub-tool/runs/5968337414?check_suite_focus=true#step:5:11

Signed-off-by: João Vanzuita <joaovanzuita@me.com>
@converge converge requested a review from silvin-lubecki April 12, 2022 18:30
@@ -47,7 +47,7 @@ type rmOptions struct {
func newRmCmd(streams command.Streams, hubClient *hub.Client, parent string) *cobra.Command {
var opts rmOptions
cmd := &cobra.Command{
Use: rmName + " [OPTIONS] REPOSITORY",
Use: rmName + " [OPTIONS] USERNAME(OR)ORGANIZATION NAME/REPOSITORY",
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: I wonder 🤔 if we should just rephrase to:

NAMESPACE/REPOSITORY

WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tks again for the guidance, it's great to have your support!

Signed-off-by: João Vanzuita <joaovanzuita@me.com>
@converge converge requested a review from silvin-lubecki April 13, 2022 19:36
Copy link
Collaborator

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

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

LGTM

@silvin-lubecki silvin-lubecki merged commit 89d966e into docker:main Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants