Skip to content

Conversation

@jelaniwoods
Copy link
Contributor

@jelaniwoods jelaniwoods commented Jun 23, 2021

Related to #45

Problem

One of the big reasons we use web_git is to avoid teaching CLI stuff. Heroku CLI is much simpler to use than git, but since they are very much connected there should also be some web interface for the Heroku commands that are common.

Solution

This branch adds Heroku "login" functionality.
web-git-heroku-ui-2

Screen Shot 2021-06-29 at 9 52 10 AM

This also adds the dependency on expect, which seems to be the only reliable way to auto-login to Heroku CLI.

Concerns

Mentioned also in #45 , but I'm not sure what the best place is to add this in the UI. There are already a lot of forms going on so I opted for a collapse to try and not clutter things up. I know eventually we've talked about a redesign, but I think this is more important than that. Bootstrap tabs are an improvement over a collapse and allow space for further Heroku features in the future.

Setup

  1. Add gem to Gemfile
gem "web_git", git: "https://github.com/firstdraft/web_git", branch: "45-jw-add-heroku-auth"
  1. Run install command (now installs expect if it isn't already installed)
rails g web_git:install
  1. Run rails s
  2. Visit /git

References

@raghubetina
Copy link
Contributor

raghubetina commented Jun 28, 2021

@jelaniwoods Excellent work. Notes as I am testing:

  1. I agree with you that a UI overhaul is needed but not higher-priority than just getting this in.

    In order to reduce clutter, perhaps we could make a separate path for this, e.g. /heroku, and add a navbar across the top.

    Or, since this is already working, if we want to keep it all on /git (and if performance seems to be fine doing so), perhaps we could use justified Bootstrap tabs to separate the Git stuff from the Heroku stuff.

  2. Good thinking to make the Heroku email field an <input> of type email. That already caught and prevented a typo from me.

  3. When I deliberately entered wrong password/email combo, the error message that was displayed is a little intimidating/not very informative that it was caused by wrong/email password:

    Screen Shot 2021-06-28 at 9 26 34 AM

  4. This is not important but: I was able to sign in okay with my demo student account and password, but when I tried to sign in with my real [email protected] account (which has 2FA enabled) and API token (which usually works when signing in to CLI) it failed. Again, not important right now, but I thought I'd log it here for future.

  5. Once I signed in successfully, I still see the Sign In button. Should it be replaced with my username?

    Screen Shot 2021-06-28 at 9 35 39 AM

@jelaniwoods
Copy link
Contributor Author

@raghubetina

  1. When I deliberately entered wrong password/email combo, the error message that was displayed is a little intimidating/not very informative that it was caused by wrong/email password:

🤔 I'm not able to reproduce this but I imagine that maybe the latest version of this branch was not installed. The changes should handle that with a proper message:

Screen Shot 2021-06-28 at 11 10 42 AM

  1. Once I signed in successfully, I still see the Sign In button. Should it be replaced with my username?

Correct, if heroku whoami returns an email it should be displayed. This looks like maybe expect is not installed. Ah, I didn't actually include that in the setup instructions. The script requires a CMD tool to run and apparently web_git doesn't fail if it's not installed, so that should be handled better. rps-html, rps-css, and rps-bootstrap each have it installed if you want to test with those repos.

I can also try doing what we talked about earlier and detecting if expect is installed or not.

I also have a snapshot here of it working: https://gitpod.io/#snapshot/eca1efee-a409-41e5-8e68-de16db85da59

@raghubetina
Copy link
Contributor

I can also try doing what we talked about earlier and detecting if expect is installed or not.

This seems like a good idea; also I did run rails g web_git:install, I was expecting that to install expect. Is it possible to include that in web_git:install?

@raghubetina
Copy link
Contributor

This is unrelated to this patch probably but the "Show last commit" window doesn't seem to be rendering the diff right anymore:

Screen Shot 2021-06-28 at 11 50 03 AM

@raghubetina
Copy link
Contributor

but I imagine that maybe the latest version of this branch was not installed.

Hmm, I just did a bundle update a second ago and same thing. I'll use the snapshot to test, but I don't see why it wouldn't get the latest?

@jelaniwoods
Copy link
Contributor Author

This seems like a good idea; also I did run rails g web_git:install, I was expecting that to install expect. Is it possible to include that in web_git:install?

I can add it to the install command. I'm not entirely sure if I could that part reversible though.

@raghubetina
Copy link
Contributor

@jelaniwoods Okay when testing on the snapshot:

  • the wrong credentials error message is friendly
  • my username appeared after signing in successfully
  • signing in with my API token for 2FA worked

@jelaniwoods
Copy link
Contributor Author

Hmm, I just did a bundle update a second ago and same thing. I'll use the snapshot to test, but I don't see why it wouldn't get the latest?

I'm not sure why that would happen, but it did happen to me today when I was trying to reproduce the behavior. I bundle u web_git which should have gotten the latest SHA but it installed a9549ba instead of 65b23e4. Perhaps it also just related to expect not being installed.

@raghubetina
Copy link
Contributor

I might tweak the message a bit;

Failed to log in to Heroku successfully. Error: Invalid credentials provided.

seems to contain a bit of redundancy, no? I tried signing in with wrong password at Heroku and they say:

Screen Shot 2021-06-28 at 11 56 42 AM

I guess they don't want to leak whether it's email or password that's wrong, i.e. whether there's an account with that email or not. Maybe we could say something with more humanity, e.g.

There was a problem logging into Heroku. Are you sure you used the right email and password?

@jelaniwoods
Copy link
Contributor Author

jelaniwoods commented Jun 28, 2021

I don't think the message is redundant since login could fail for a reason besides entering incorrect credentials. When testing the email/password could be blank or the script could timeout. Both of these cases are handled.

The message comes straight from heroku login -i, which apparently is different than the UI message on heroku.com.

Screen Shot 2021-06-28 at 12 01 25 PM

@raghubetina
Copy link
Contributor

raghubetina commented Jun 28, 2021

I don't think it's redundant since login could fail for a reason besides entering incorrect credentials.

The message comes straight from heroku login -i, which apparently is different than the UI message on heroku.com.

Screen Shot 2021-06-28 at 12 01 25 PM

Ah, by redundancy, I just meant both "Failed" and "...successfully". And trying to humanize the message a bit. But now I see that you're passing the error message straight through from the CLI, which is a good idea. How about:

There was a problem logging into Heroku. Error: Invalid credentials provided.

@jelaniwoods
Copy link
Contributor Author

Ah, by redundancy, I just meant both "Failed" and "...successfully". And trying to humanize the message a bit. But now I see that you're passing the error message straight through from the CLI, which is a good idea. How about:

There was a problem logging into Heroku. Error: Invalid credentials provided.

Oh I see. Yes, I agree the message could be clarified and I like your suggestion.

@raghubetina
Copy link
Contributor

raghubetina commented Jun 30, 2021

@jelaniwoods Since I imagine that the Heroku-related functionality may grow beyond only logging in (is that right?), what do you think about tabs across the top of the page so that we're not just constrained to the branches area?

web_git tabs

It feels like, conceptually, that's what the options are; tabbing between an interface to git ... command and the heroku ... command. Not between git checkout branch... and heroku .... What do you think?

Eventually I can imagine:

  • Creating Heroku remotes
  • Renaming Heroku remotes
  • Deploying a particular branch to a particular remote
  • Adding domains
  • Enabling auto certs
  • Migrate database
  • Resetting databases (maybe)
  • Rollback last deploy
  • Restarting dynos
  • Adding environment variables
    • Could offer the option to send a variable from .env with a single click, or all en masse forgot we're talking about public Gitpods here
  • Look at the logs
  • Commands to copy-paste for rails console on each remote
  • Heroku scheduler
  • Heroku redis
  • Upgrade Heroku postgres

@raghubetina
Copy link
Contributor

@jelaniwoods Looking great. What do you think about filling the entire width with the tabs? They feel a little small to me at present.

@raghubetina
Copy link
Contributor

When I tried to rails g web_git:install in a base-rails-based Gitpod, I got the below error message. Snapshot:

https://gitpod.io#snapshot/68d150dd-2f4b-416a-a054-dd48915de313

=> Booting Puma
=> Rails 6.0.3.2 application starting in development 
=> Run `rails server --help` for more startup options
Exiting
Traceback (most recent call last):
        38: from bin/rails:3:in `<main>'
        37: from bin/rails:3:in `load'
        36: from /workspace/base-rails/bin/spring:15:in `<top (required)>'
        35: from /home/gitpod/.rvm/rubies/ruby-2.6.6/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        34: from /home/gitpod/.rvm/rubies/ruby-2.6.6/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        33: from /home/gitpod/.rvm/ruby-2.6.6/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
        32: from /home/gitpod/.rvm/ruby-2.6.6/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
        31: from /home/gitpod/.rvm/ruby-2.6.6/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
        30: from /home/gitpod/.rvm/ruby-2.6.6/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
        29: from /home/gitpod/.rvm/ruby-2.6.6/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
        28: from /home/gitpod/.rvm/ruby-2.6.6/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
        27: from /home/gitpod/.rvm/ruby-2.6.6/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
        26: from /workspace/base-rails/bin/rails:9:in `<top (required)>'
        25: from /home/gitpod/.rvm/ruby-2.6.6/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `require'
        24: from /home/gitpod/.rvm/ruby-2.6.6/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:291:in `load_dependency'
        23: from /home/gitpod/.rvm/ruby-2.6.6/gems/activesupport-6.0.3.2/lib/active_support/dependencies.rb:324:in `block in require'
        22: from /home/gitpod/.rvm/ruby-2.6.6/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        21: from /home/gitpod/.rvm/ruby-2.6.6/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        20: from /home/gitpod/.rvm/ruby-2.6.6/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        19: from /home/gitpod/.rvm/ruby-2.6.6/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        18: from /home/gitpod/.rvm/ruby-2.6.6/gems/bootsnap-1.4.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        17: from /home/gitpod/.rvm/ruby-2.6.6/gems/railties-6.0.3.2/lib/rails/commands.rb:18:in `<main>'
        16: from /home/gitpod/.rvm/ruby-2.6.6/gems/railties-6.0.3.2/lib/rails/command.rb:46:in `invoke'
        15: from /home/gitpod/.rvm/ruby-2.6.6/gems/railties-6.0.3.2/lib/rails/command/base.rb:69:in `perform'
        14: from /home/gitpod/.rvm/ruby-2.6.6/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
        13: from /home/gitpod/.rvm/ruby-2.6.6/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
        12: from /home/gitpod/.rvm/ruby-2.6.6/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
        11: from /home/gitpod/.rvm/ruby-2.6.6/gems/railties-6.0.3.2/lib/rails/commands/server/server_command.rb:138:in `perform'
        10: from /home/gitpod/.rvm/ruby-2.6.6/gems/railties-6.0.3.2/lib/rails/commands/server/server_command.rb:138:in `tap'
         9: from /home/gitpod/.rvm/ruby-2.6.6/gems/railties-6.0.3.2/lib/rails/commands/server/server_command.rb:147:in `block in perform'
         8: from /home/gitpod/.rvm/ruby-2.6.6/gems/railties-6.0.3.2/lib/rails/commands/server/server_command.rb:37:in `start'
         7: from /home/gitpod/.rvm/ruby-2.6.6/gems/railties-6.0.3.2/lib/rails/commands/server/server_command.rb:77:in `log_to_stdout'
         6: from /home/gitpod/.rvm/ruby-2.6.6/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'
         5: from /home/gitpod/.rvm/ruby-2.6.6/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'
         4: from /home/gitpod/.rvm/ruby-2.6.6/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'
         3: from /home/gitpod/.rvm/ruby-2.6.6/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'
         2: from /home/gitpod/.rvm/ruby-2.6.6/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'
         1: from /home/gitpod/.rvm/ruby-2.6.6/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'
/home/gitpod/.rvm/ruby-2.6.6/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval': config.ru:15: syntax error, unexpected end, expecting end-of-input (SyntaxError)

@jelaniwoods
Copy link
Contributor Author

When I tried to rails g web_git:install in a base-rails-based Gitpod, I got the below error message.

@raghubetina looks like this is an issue that happens when the installer is run more than once. It adds an extra end to config.ru which messes everything up.

Screen Shot 2021-07-07 at 5 28 11 PM

Not sure why yet, but I guess not all of the methods check if the file needs to be modified.

@jelaniwoods
Copy link
Contributor Author

@jelaniwoods Looking great. What do you think about filling the entire width with the tabs? They feel a little small to me at present.

Oh this is nice! I didn't really understand how this worked from the documentation example since it's in a smaller width.

web_git-nav-fill

@raghubetina
Copy link
Contributor

Nice! LGTM now

Currently when the installer is run multiple times, additional ends or other Ruby is injected into config.ru which causes app breaking errors.

This commit updates the installer to conditionally modify config.ru when it doesn't contain the required Ruby for web_git and allows for the installer to be run multiple times without issue.
@jelaniwoods jelaniwoods merged commit a2be64e into spring2020 Jul 12, 2021
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