Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vilmibm
Copy link
Contributor

@vilmibm vilmibm commented Aug 7, 2020

This PR adds gh auth refresh, a command for adding new scopes to an existing token.

image

image

It errors if GITHUB_TOKEN is set in the environment, if no hosts are authenticated, if --hostname is specified for a host gh doesn't know about, or if gh is not connected to a TTY.

Part of #1413

@vilmibm vilmibm marked this pull request as ready for review August 11, 2020 20:57
@vilmibm vilmibm changed the title WIP auth refresh gh auth refresh Aug 11, 2020
@vilmibm vilmibm requested review from ampinsk and mislav August 11, 2020 20:57
@mislav mislav mentioned this pull request Aug 11, 2020
4 tasks
@vilmibm vilmibm changed the base branch from auth-status to trunk August 12, 2020 14:23
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.

Works great on this end! 🎉

I only have nitpicks about edge-cases and docs

},
}

cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "The GitHub host to use for authentication")
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be appropriate to list github.com here as a default value for this flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted people to interactively select a host if none was passed and this seemed like the correct approach. if this default is specified, in refreshRun it would not be possible to tell if a user passed nothing (and thus I should prompt when multiple hosts are configured).

In an old style command I'd just check .Changed(), but we make a point of not accessing the flags directly in the run portion of commands.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense! BTW, in cases when we still need to check Changed(), we do and save that information to an Options struct

opts.TitleProvided = cmd.Flags().Changed("title")
opts.BodyProvided = cmd.Flags().Changed("body")

But you have a good point about the interactive selection for a host happening, and in that case github.com is not the "default" (except that it likely appears first in the list).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was a valid path too (adding a *Provided) but I was seeing how not cluttering up the opts struct felt.


candidates, err := cfg.Hosts()
if err != nil {
return fmt.Errorf("not logged in to any hosts. Use 'gh auth login' to authenticate with a host")
Copy link
Contributor

Choose a reason for hiding this comment

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

If I have explicitly chosen a host, would it make sense that the operation continues instead of erroring out when there is no pre-existing hosts configuration?

$ rm ~/.config/gh/hosts.yml
$ gh auth refresh -h github.com
not logged in to any hosts. Use 'gh auth login' to authenticate with a host

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed wrong to have refresh replace login, here. If a user does the initial authentication here they won't get the git_protocol prompt nor any additional "first auth" setup we add later. I preferred refresh and login having distinct purposes.

@ampinsk what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, I prefer keeping them distinct too! 👍

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.

:shipit:

@vilmibm vilmibm merged commit 544746e into trunk Aug 13, 2020
@mislav mislav deleted the auth-refresh branch September 2, 2020 11:15
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.

3 participants