Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/probot homepage #279

Merged
merged 34 commits into from
Oct 17, 2017
Merged

/probot homepage #279

merged 34 commits into from
Oct 17, 2017

Conversation

JasonEtco
Copy link
Member

@JasonEtco JasonEtco commented Oct 8, 2017

As we discussed in #262, it would be really cool to have something if someone visits the / path of a running Probot App. @gr2m had a good suggestion to have it redirect to /probot if there isn't any other set route, which makes a lot of sense. Unfortunately, that creates the challenge of somehow identifying if another route handler for / has in fact been created.

This PR adds a veeeeeery basic /probot page (needs work), and the relevant tests to:

  1. Make sure that /probot responds correctly
  2. Make sure that / redirects to /probot
  3. / can be overwritten to no longer redirect to /probot.

1-2 work perfectly, but 3 is a challenge. I've passed one of two relevant tests:

If the newer .get() is registered against the Probot App's server, it'll work just fine. However, if the new route is registered as part of a new express.Router then it is totally ignored 😭 This is made clear in @anglinb's test from #255, which I've copied into this PR.

I'd appreciate some help here; I'm stuck on how else to identify if a path has been registered across both the central express app and any nested routers. I thought of writing some methods into the robot class that would add new routes to an array and then checking that, but that adds a lot of complication around just writing routes.

Let me know if you have any questions 💖 Note that this PR is WIP because I'm stuck and need help 🍕 I want your opinions on the way I'm solving this.


UPDATE:

I've found a way to overwrite the / route by creating a Set() of routes, and adding all routes in new routers (as a part of the load() method) to the Set. Then, when / is requested, it checks the Set to see if it has a route. If it does, next(), otherwise redirect to /probot.

JasonEtco and others added 10 commits October 8, 2017 16:43
* origin/master:
  chore: Read version from package.json
  feat: Expose public stats about installations (#181)
  chore: remove changelog now that we are using semantic-release
  chore: update jsdoc to fix error
  party machen
  chore(travis): Run test on node 8
  chore: semantic-release setup
  Move note for robot.log before the @example
  Added NPM version badge to readme.
  Changes made in CONTRIBUTING.md according to #271
  Update output mentioned in 'Generating a new app' section
  Smaller image in the welcome PR comment
  docs: fix log statement
  Lint JS in examples
  Whitespace
  Add @example for using defaultConfig
@bkeepers bkeepers mentioned this pull request Oct 12, 2017
BREAKING CHANGE: `probot run` without any arguments will no longer autoload apps named `probot-*`.
* refactor-loading:
  Simplify resolver
  Update simulate command
  Look for `apps` key instead of `plugins`
  Move setup
  Remove autoloading of plugings
  Refactor app loading

# Conflicts:
#	index.js
Copy link
Contributor

@bkeepers bkeepers left a comment

Choose a reason for hiding this comment

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

@JasonEtco I merged in #284 extracted the default homepage to a built-in app. The diff should look a lot better once #284 is merged.

The page is looking pretty good. It'd be nice to link to documentation and maybe even the slack channel to point people toward places where they can find help building their app.

@JasonEtco
Copy link
Member Author

@bkeepers that's a great idea, I'll do that. What's the timeline looking like for #284? Can I do anything to help it get merged?

You had a real productive ✈️ ride huh?

@JasonEtco
Copy link
Member Author

/probot as of my latest commit:
image

* origin/master:
  chore(tests): Migrate to Jest
  chore(docs): Use GH_TOKEN for updating docs

# Conflicts:
#	package-lock.json
Copy link
Contributor

@bkeepers bkeepers left a comment

Choose a reason for hiding this comment

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

See installation stats

Since this is just a JSON dump right now, what would you think about removing this for now and revisiting in another PR that adds an HTML view of the installation stats?

@JasonEtco
Copy link
Member Author

@bkeepers that's not a bad idea, but EVEN BETTER IDEA: what about including those numbers in the page? Or is that too much for a basic welcome page? Could be done by including the /plugins/stats.js methods into the welcome page route and putting it into the .ejs template, or could have an in-browser fetch to the /probot/stats endpoint.

@gr2m
Copy link
Contributor

gr2m commented Oct 16, 2017

@JasonEtco I’d work/discuss showing stats in a follow up PR, this one is quite big already

@JasonEtco
Copy link
Member Author

JasonEtco commented Oct 16, 2017

Yeah I agree @gr2m. In that case, I'll pull down changes, fix CI and merge away?

@gr2m
Copy link
Contributor

gr2m commented Oct 16, 2017

I tested this PR on one of my Probot Test Apps on Glitch, but got this error

Error: Failed to lookup view "probot.ejs" in views directory "/app/views"
    at Function.render (/app/node_modules/express/lib/application.js:580:17)
    at ServerResponse.render (/app/node_modules/express/lib/response.js:1008:7)
    at app.get (/app/node_modules/probot/lib/plugins/default.js:14:40)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at next (/app/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at /app/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
    at next (/app/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/app/node_modules/express/lib/router/index.js:174:3)
    at router (/app/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
    at /app/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
    at next (/app/node_modules/express/lib/router/index.js:275:10)
    at /app/node_modules/express/lib/router/index.js:635:15
    at next (/app/node_modules/express/lib/router/index.js:260:14)
    at Function.handle (/app/node_modules/express/lib/router/index.js:174:3)
    at router (/app/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
    at /app/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/app/node_modules/express/lib/router/index.js:275:10)
    at Immediate._onImmediate (/app/node_modules/express/lib/router/index.js:635:15)
    at runCallback (timers.js:802:20)
    at tryOnImmediate (timers.js:762:5)
    at processImmediate [as _immediateCallback] (timers.js:733:5)

Are you still looking into it? Code wise it looks ok, but CI is failing, too. Let me know if you get stuck or when the PR is ready for review

@JasonEtco
Copy link
Member Author

@gr2m I'm not seeing that error locally, but I'm getting some different CI errors. I'm fairly certain the functionality itself works, its just a testing thing to figure out. I'll let you know if I'm having trouble, thanks 💖

@JasonEtco
Copy link
Member Author

It looks like the last failing test is due to the new .setup() method. Here's the error message I see:

 FAIL  test/index.js
  ● Probot › server › redirects to /probot from /

    secretOrPrivateKey must have a value

      at Object.<anonymous>.module.exports [as sign] (node_modules/jsonwebtoken/sign.js:70:20)
      at generateJwt (node_modules/github-app/index.js:39:16)
      at Object.asApp (node_modules/github-app/index.js:7:54)
      at Robot.auth (lib/robot.js:148:31)
      at getInstallations (lib/plugins/stats.js:29:32)
      at refresh (lib/plugins/stats.js:22:33)
      at Object.<anonymous>.module.exports (lib/plugins/stats.js:9:26)
      at load (index.js:79:5)
      at apps.concat.forEach.app (index.js:86:45)
          at Array.forEach (<anonymous>)
      at Object.setup (index.js:86:30)
      at Object.it (test/index.js:47:14)
          at Promise (<anonymous>)
          at <anonymous>
      at process._tickDomainCallback (internal/process/next_tick.js:228:7)

I'm guessing it has something to do with authenticating the probot instance, but I'm having trouble nailing down the fix. Any ideas @gr2m? cc @bkeepers.

By the by @gr2m I did fix your ejs bug in the latest commit, thanks for pointing it out.

@JasonEtco
Copy link
Member Author

JasonEtco commented Oct 17, 2017

Aha! It seems to be the /stats endpoint that throws when first creating an authed GitHub client and attempting to ping the installation API as a part of .setup(). I'm not sure of the best way to resolve this; commenting out the require for the stats plugin in the defaultApps array fixes this test case, but obviously that's not a real solution.

@JasonEtco
Copy link
Member Author

Alrighty, per a Slack conversation, it turns out that the reason the last failing test was failing isn't related to this PR and should not be a blocker.

The TL;DR of it is that we are missing a way of mocking Certs and things for default plugins, which was causing the stats plugin to throw an error. While this should probably be resolved, the particular test that I've removed was unrelated.

I think this is good to merge 🎉 Can I get one last look over @gr2m, @bkeepers, @probot/maintainers?

Copy link
Contributor

@bkeepers bkeepers left a comment

Choose a reason for hiding this comment

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

Sorry, my fault for breaking the tests. I'm not sure why it wasn't failing for me locally.

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.

None yet

3 participants