Skip to content

gh cs delete should support a flag like --org for user-owned repos #7315

Closed

Description

@cmbrose

Describe the feature or problem you’d like to solve

Pretty frequently I've got codespaces in a few repos I own and have wanted to wipe them all at once. If the repos were in an org, I could use --org, but since I own them that flag doesn't work (it ends up trying to hit /orgs/cmbrose/members/cmbrose/codespaces which 404s). So the best I can do in that case is to delete all codespaces by repo, for each repo.

It would be nice if there was a flag I could use to delete all codespaces in repos I own.

Proposed solution

[Edit] As pointed out by @kousikmitra - an option used by other commands is to have a --owner parameter for this case - in that case --owner could be a user or an org name. This has some apparent overlap with the existing --org parameter, but that flag is meant only for admins and can't be used by normal users so really they support distinct scenarios.

Another option is to support wildcards in --repo - e.g. --repo cmbrose/*. I think that this just entails switching the repo filter from exact match to supporting the wildcard.

Alternatively, we could overload the --org flag to support passing usernames in addition to orgs, but that will likely make the code convoluted because the --org flag is already only used in an org admin context and has some special behaviors.

Finally, if it's not desirable to change the usage of --repo we could add a new flag like --repo-like to make it explicit that the user wants to use a wildcard. This feels unnecessary though.

Additional context

n/a

Activity

  1. kousikmitra commented on Apr 19, 2023

    @kousikmitra
    Contributor

    I have seen other commands to use --owner for targeting user owned repos, can that be an option here?

  2. cmbrose commented on Apr 19, 2023

    @cmbrose
    MemberAuthor

    I have seen other commands to use --owner for targeting user owned repos, can that be an option here?

    Oh nice, yeah that's a great idea - it also captures the "delete all of my repos in this org" scenario without needing org admin permissions required for --org

  3. kousikmitra commented on Apr 20, 2023

    @kousikmitra
    Contributor

    Great, would like to work on this if it's up for grab.

  4. cmbrose commented on Apr 20, 2023

    @cmbrose
    MemberAuthor

    Sounds great! I'm happy to review when it's ready

  5. kousikmitra commented on Apr 20, 2023

    @kousikmitra
    Contributor

    @cmbrose Sorry for the confusion, but don't think --owner would be an ideal flag name here. In github's term any codespace that I create the owner would be me.
    For example,
    If I create codespace both in cli/cli and kousikmitra/cli both will have kousikmitra as owner.

    "codespaces": [
        {
          "name": "xyz",
          "created_at": "2023-04-20T22:33:20+05:30",
          "display_name": "opulent space doodle",
          "last_used_at": "2023-04-20T22:33:20+05:30",
          "owner": {
            "login": "kousikmitra",
            "type": "User"
          },
          "repository": {
            "id": 123,
            "full_name": "cli/cli",
            "default_branch": ""
          },
          "state": "Available",
          ....
      },
      {
          "name": "abc",
          "created_at": "2023-04-20T22:46:16+05:30",
          "display_name": "automatic space xylophone",
          "last_used_at": "2023-04-20T22:46:16+05:30",
          "owner": {
            "login": "kousikmitra",
            "type": "User"
          },
          "repository": {
            "id": 789,
            "full_name": "kousikmitra/cli",
            "default_branch": ""
          },
          "state": "Provisioning",
          ...
       }
    ]
    

    Now using gh cs delete --owner kousikmitra to delete codespaces related kousikmitra/* would be misleading.

    Let me know your thoughts or if I am missing something here.

  6. cmbrose commented on Apr 21, 2023

    @cmbrose
    MemberAuthor

    @kousikmitra yeah makes sense - the term owner applies to a couple things here - repo owner and codespace owner. Maybe the parameter could be called --repo-owner instead to avoid confusion? WDYT?

  7. kousikmitra commented on Apr 21, 2023

    @kousikmitra
    Contributor

    Yeah, Sounds good to me.

    @kousikmitra yeah makes sense - the term owner applies to a couple things here - repo owner and codespace owner. Maybe the parameter could be called --repo-owner instead to avoid confusion? WDYT?

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions