Skip to content

Can't delete or query packages with forward slash in their names #9798

Description

@Skarlso

Describe the bug

Can't delete or query packages with forward slash in their names

Steps to reproduce the behavior

List packages:

gh api /users/skarlso/packages\?package_type=container --jq '.[].name'
...
ocm/v0.0.1/component-descriptors/github.com/skarlso/ocm-test
ocm/v0.0.2/component-descriptors/github.com/skarlso/ocm-workflow-class
ocm-workflow-class/v0.0.1
ocm/v0.0.1/component-descriptors/github.com/skarlso/ocm-workflow-class
ocm-destination/v0.0.1/component-descriptors/github.com/skarlso/ocm-workflow-class
ocm/component-descriptors/github.com/skarlso/ocm-workflow-class
ocm-destination/component-descriptors/github.com/skarlso/ocm-workflow-class
ocm-replication-test/component-descriptors/github.com/skarlso/ocm-replication-test
ocm-replication-test-example/v0.0.1
ocm-replication/component-descriptors/github.com/skarlso/ocm-replication
ocm-destination/skarlso/ocm-replication-test-example/v0.0.1
ocm-destination/component-descriptors/github.com/skarlso/ocm-replication
ocm-delivery/weaveworksdemos/carts
ocm-delivery/gardener-project/test/jensh007/mongo
ocm-delivery/component-descriptors/github.com/weaveworks/carts
ocm-delivery/weaveworksdemos/catalogue
ocm-delivery/weaveworksdemos/catalogue-db
ocm-delivery/component-descriptors/github.com/weaveworks/catalogue
ocm-delivery/weaveworksdemos/front-end
ocm-delivery/component-descriptors/github.com/weaveworks/front-end
ocm-delivery/weaveworksdemos/orders
ocm-delivery/component-descriptors/github.com/weaveworks/orders
ocm-delivery/weaveworksdemos/payment
ocm-delivery/component-descriptors/github.com/weaveworks/payment
ocm-delivery/weaveworksdemos/queue-master
ocm-delivery/library/rabbitmq
ocm-delivery/kbudde/rabbitmq-exporter
ocm-delivery/library/redis
ocm-delivery/component-descriptors/github.com/weaveworks/queue-master
ocm-delivery/weaveworksdemos/shipping

Query:

gh api -H "Accept: application/vnd.github+json" /users/skarlso/packages/container/ocm-delivery/weaveworksdemos/shipping
...
gh: Not Found (HTTP 404)
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest",
  "status": "404"
}


## Or

gh api \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /user/packages/container/ocm-delivery/weaveworksdemos/shipping


gh: Not Found (HTTP 404)
{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest",
  "status": "404"
}

Expected vs actual behavior

A clear and concise description of what you expected to happen and what actually happened.

Logs

Paste the activity from your command line. Redact if needed.

Activity

  1. Skarlso commented on Oct 21, 2024

    @Skarlso
    Author

    For the record, deleting and retrieving a package that doesn't have a slash in its name, does work:

    gh api /user/packages/container/cert-manager-webhook
    
    {
      "id": 5684160,
      "name": "cert-manager-webhook",
      "package_type": "container",
      "owner": {
        "login": "Skarlso",
        "id": 182850,
        "node_id": "MDQ6VXNlcjE4Mjg1MA==",
        "avatar_url": "https://avatars.githubusercontent.com/u/182850?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/Skarlso",
        "html_url": "https://github.com/Skarlso",
        "followers_url": "https://api.github.com/users/Skarlso/followers",
        "following_url": "https://api.github.com/users/Skarlso/following{/other_user}",
        "gists_url": "https://api.github.com/users/Skarlso/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/Skarlso/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/Skarlso/subscriptions",
        "organizations_url": "https://api.github.com/users/Skarlso/orgs",
        "repos_url": "https://api.github.com/users/Skarlso/repos",
        "events_url": "https://api.github.com/users/Skarlso/events{/privacy}",
        "received_events_url": "https://api.github.com/users/Skarlso/received_events",
        "type": "User",
        "user_view_type": "public",
        "site_admin": false
      },
      "version_count": 6,
      "visibility": "public",
      "url": "https://api.github.com/users/Skarlso/packages/container/cert-manager-webhook",
      "created_at": "2023-10-03T15:10:54Z",
      "updated_at": "2023-10-03T15:28:33Z",
      "html_url": "https://github.com/users/Skarlso/packages/container/package/cert-manager-webhook"
    }
    
  2. Skarlso commented on Oct 22, 2024

    @Skarlso
    Author

    The name has to be URL encoded with %2F.

  3. williammartin commented on Oct 23, 2024

    @williammartin
    Member

    @Skarlso,

    Looking at this it sort of seems like we should be URL encoding this on the client? What you've discovered seems like a pretty terrible experience. I suspect it hasn't come up before just because for the most part names don't have these characters.

    What do you think about reopening this to get a better experience here?

  4. Skarlso commented on Oct 23, 2024

    @Skarlso
    Author

    Yeah sure. Let's do that. It would be super nice indeed. 😊

  5. williammartin commented on Oct 23, 2024

    @williammartin
    Member

    Acceptance Criteria

    When I target a resource using gh api that has characters that have special meaning and should be percent-encoded
    Then the request is made successfully

  6. added
    enhancementa request to improve CLI
    gh-apirelating to the gh api command
    and removed
    bugSomething isn't working
    on Oct 23, 2024
  7. self-assigned this
    on Feb 25, 2025
  8. Skarlso commented on Feb 27, 2025

    @Skarlso
    Author

    Thank you for doing this! :) <3

  9. williammartin commented on Mar 18, 2025

    @williammartin
    Member

    Sorry @Skarlso, I've reverted the PR that fixed this because it caused some other issues. I'm reopening it so another attempt can be made, but it's likely there will be a release today that breaks you again: #10630

  10. added
    discussFeature changes that require discussion primarily among the GitHub CLI team
    and removed on Mar 18, 2025
  11. Skarlso commented on Mar 18, 2025

    @Skarlso
    Author

    No worries. :D Thank you for letting me know. :)

  12. andyfeller commented on Mar 18, 2025

    @andyfeller
    Contributor

    @Skarlso : Nice to meet you! I'd like to ask you a few questions to figure out how we can help you in light of all of this. 🙇

    Questions

    1. What operating systems were you using gh for working with these endpoints?
    2. What other alternatives to encoding URLs did you explore?
    3. Are there any concerns using a specialized tool for encoding and decoding?

    Thoughts

    This need completely makes sense as most programming languages provide libraries to help developers address this issue natively, however there are few standalone Linux/Windows/Mac utilities for shell and scripting use:

    However, I genuinely believe this problem needs a different approach:

    • this is a general HTTP request need, not just GitHub APIs
    • I don't know where the Unix principle line gets drawn here in terms of responsibility
    • I don't know how intelligent gh should be in this situation

    Seeing several homegrown tools on GitHub that people have put together to call Go url.PathEscape(), perhaps we have a standalone cli tool that does something similar if not a standalone gh command. 🤔

  13. Skarlso commented on Mar 18, 2025

    @Skarlso
    Author

    @andyfeller Thank you very much! It's really not that big of a problem :) I just adjusted my own pathing and that's it. :)

    1. osx
    2. yes, a simple bash script where I escape what I do "by hand"
        if [[ $found -eq 1 ]]; then
          name=${1//\//%2F}
          echo "deleting package with name: $name"
          gh api -X DELETE "/user/packages/container/$name" --silent
        fi
    1. I'd like to limit the number of tools I use to a bare minimum
  14. AdamuKaapan commented on Apr 24, 2026

    @AdamuKaapan

    Something else to contribute here - the %2F fix works for getting/deleting specific packages. However, packages with slashes in the name also are not appearing in list responses, and this has no way to fix locally. e.g. if we do gh api orgs/<org name>/packages?package_type=container, packages with a slash in the name are not returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussFeature changes that require discussion primarily among the GitHub CLI teamenhancementa request to improve CLIgh-apirelating to the gh api command

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions