Closed begedin closed 9 years ago
@venkatd: I did some refactoring which was made possible by switching from using System.call
to System.result
(we don't want the configuration retrieval calls to get printed out to the standard output anyway, in my opinion).
I decided not to switch to the additional layer of a config object, for two simple reasons:
If we end up having more in the future, then we'd have a case for adding a different layer, but for now, it seems like it would add complexity - mostly due to the special error case.
@begedin do you prefer solution A or solution B? If you present several solutions, it will be a good habit to explain which option you prefer and why.
Sorry, I meant to add a comment. I went with solution A because it seems more straightforward and typical of command line behavior. The user is explained they need to call "code authorize" once, but isn't prompted for credentials directly.
Description
Branching off of PR #8 to avoid potential trouble and to have something to make a PR out of (for testing). Nothing is implemented yet. In hindsight, this wasn't actually necessary.
The actuall changes are in
Gemfile
- new gembin/code
- newauthorize
command, modification of thepublish
commandlib/github_api.rb
- new class for communicating with the GitHub API via the octokit gem.Unfortunately, there is no simple way to find a PR from the command-line or via
hub
. The only way this seems to be possible is through the GitHub API.I actually contacted github and was promptly answered that this is exactly the case:
Since that would mean we'd have to handle authentication on code side instead of relying on
hub
authentication, I found a gem called github_api as well as one called octokit.After some testing, I decided to go with the second one. It seems more developed and more robust than the first.
Issues
Unfortunately, I have difficulties with code due to using linux, which I haven't realized I had before.
open
console command does something on linux different compared to mac. The correct command to be used on my system is ˙xdg-open, but some linux systems also have
gnome-open` and other variations.code pr
to create a new pull request, hub prompts for username and password, it seems, but there's no actual prompt in the console for me. It just hangs there, allowing input, but not indicating what that input is. If I try typing in my credentials, I get various errors, but I haven't yet figured out how and what to type in to get past it.Basically, code has issues on linux :)
Flow
To elaborate, with this feature, the user is required to log in once, using
After that an oauth token will be created and stored into the global .gitconfig file. The token will be used to fetch and the proper pull request url and open it in browser.
I don't see a way around this, but I'm thinking there should also be a prompt in that case, to ask for credentials if
code pr
was called beforecode authorize
being called first. Either that, or we makecode pr
accept a--username
and--password
option to and callauthorize
internally if it's needed and the options are provided, displaying an error otherwise.Basically
code pr
--username
and--password
withcode pr
. Authorization runs. If options are not passed in, code shows an error with the instruction to pass them in.NOTE: I decided to go with Solution A for the time being. It's faster to implement and more typical of command line behavior.