wordpress-mobile / release-toolkit-gutenberg-mobile

Automation Scripts for Releasing Gutenberg-Mobile Updates to the WordPress Mobile Apps.
Mozilla Public License 2.0
5 stars 2 forks source link

[CLI] Fix Github Token handling #229

Closed jhnstn closed 8 months ago

jhnstn commented 8 months ago

This uses the same function go-gh uses to find the users Github auth token when cloning repos. Previously it was only looking for GITHUB_TOKEN. This change will allow users to just run gh auth login to use the tool or it will work by supplying a github token via GH_TOKEN or GITHUB_TOKEN if gh is not installed

Testing

With out gh

  1. Uninstall gh ( brew uninstall gh)
  2. Make sure gh has not added anything to ~/.gitconfig look for something like
    [credential "https://github.com"]
    helper = !/opt/homebrew/bin/gh auth git-credential
  3. Make sure ~/.config/gh/hosts.yml does not have an oauth_token
  4. Try creating a test release go run main.go release prepare gb <version> --no-tag
  5. Note that the command fails
  6. Try using a github PAT by adding that as an env :
    GH_TOKEN=<your github token> go run main.go release prepare gb <version> --no-tag
    // or
    GITHUB_TOKEN=<your gitub token> go run main.go release prepare gb <version> --no-tag
  7. Verify that the changes can be pushed to github and that the PR is created

With gh installed

  1. re-install gh
  2. Try without logging in by repeating steps 5 and 6 above
  3. Login in via gh auth login and make sure to not run gh auth setup-git
  4. Verify that gh has not modified ~./gitconfig
  5. Try creating a test release without the exported token: go run main.go release prepare gb <version> --no-tag
  6. Verify that the changes can be pushed and that the PR is created