Skip to content

Support listing and removing user Codespaces secrets#4714

Merged
mislav merged 3 commits intocli:trunkfrom
joshmgross:joshmgross/codespaces-user-secrets
Nov 18, 2021
Merged

Support listing and removing user Codespaces secrets#4714
mislav merged 3 commits intocli:trunkfrom
joshmgross:joshmgross/codespaces-user-secrets

Conversation

@joshmgross
Copy link
Contributor

Supports #4698
Follow-up to #4699 which adds support for creating user secrets.

This PR adds support for listing and removing Codespaces user secrets. These APIs will require read:user and user scopes.

gh auth refresh -h github.com -s user

https://docs.github.com/en/rest/reference/codespaces#list-secrets-for-the-authenticated-user
https://docs.github.com/en/rest/reference/codespaces#delete-a-secret-for-the-authenticated-user

I've also updated the code that fetches the number of selected repositories for a secret to not run when outside the context of a TTY, since that information is only shown when in a TTY and requires extra API calls - 5b6827a

Testing

I validated that secrets were able to be listed and removed:

❯ bin/gh secret list  --user               
MY_PAT         Updated 2021-10-26  Visible to 0 selected repositories
COOL_SECRET    Updated 2021-11-11  Visible to 1 selected repository
JSON API response for comparison
{
  "total_count": 2,
  "secrets": [
    {
      "name": "MY_PAT",
      "created_at": "2021-10-26T19:17:07.000+00:00",
      "updated_at": "2021-10-26T19:17:07.000+00:00",
      "visibility": "selected",
      "selected_repositories_url": "https://api.github.com/user/codespaces/secrets/MY_PAT/repositories"
    },
    {
      "name": "COOL_SECRET",
      "created_at": "2021-11-07T20:55:53.000+00:00",
      "updated_at": "2021-11-11T03:34:15.000+00:00",
      "visibility": "selected",
      "selected_repositories_url": "https://api.github.com/user/codespaces/secrets/COOL_SECRET/repositories"
    }
  ]
}
❯ bin/gh secret remove cool_secret --user  
✓ Removed secret cool_secret from your user

When list secret is run outside the context of a tty, the selected
repository count is not shown.
Since fetching this information is an extra API call per secret,
we should skip fetching it when it's not needed.
@joshmgross joshmgross requested a review from a team as a code owner November 11, 2021 19:33
@joshmgross joshmgross requested review from mislav and removed request for a team November 11, 2021 19:33
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Fantastic! 🌟

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