(nameOrID, endpoint string)
| 56 | } |
| 57 | |
| 58 | func resolveRepository(nameOrID, endpoint string) (string, error) { |
| 59 | if nameOrID == "" { |
| 60 | return "", fmt.Errorf("missing repository name or ID") |
| 61 | } |
| 62 | entityID, err := uuid.Parse(nameOrID) |
| 63 | if err == nil { |
| 64 | return entityID.String(), nil |
| 65 | } |
| 66 | |
| 67 | parts := strings.SplitN(nameOrID, "/", 2) |
| 68 | if len(parts) < 2 { |
| 69 | // format of friendly name is invalid for a repository. |
| 70 | // Return the string as is. |
| 71 | return nameOrID, nil |
| 72 | } |
| 73 | |
| 74 | listReposReq := apiClientRepos.NewListReposParams() |
| 75 | listReposReq.Owner = &parts[0] |
| 76 | listReposReq.Name = &parts[1] |
| 77 | if endpoint != "" { |
| 78 | listReposReq.Endpoint = &endpoint |
| 79 | } |
| 80 | response, err := apiCli.Repositories.ListRepos(listReposReq, authToken) |
| 81 | if err != nil { |
| 82 | return "", err |
| 83 | } |
| 84 | if len(response.Payload) == 0 { |
| 85 | return "", fmt.Errorf("repository %s was not found", nameOrID) |
| 86 | } |
| 87 | |
| 88 | if len(response.Payload) > 1 { |
| 89 | return "", fmt.Errorf("multiple repositories with the name %s exist, please use the repository ID or specify the --endpoint parameter", nameOrID) |
| 90 | } |
| 91 | return response.Payload[0].ID, nil |
| 92 | } |
| 93 | |
| 94 | func resolveOrganization(nameOrID, endpoint string) (string, error) { |
| 95 | if nameOrID == "" { |
no test coverage detected