From 9a67cee2c6f2b3f718598fd398a8a1971d80fa34 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 8 Apr 2017 12:46:11 -0500 Subject: [PATCH 1/8] Ensure node version is satisfied --- bin/probot | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/probot b/bin/probot index 7a9d76f5..c871f9a2 100755 --- a/bin/probot +++ b/bin/probot @@ -1,5 +1,13 @@ #!/usr/bin/env node +const semver = require('semver'); +const version = require('../package').engines.node; + +if (!semver.satisfies(process.version, version)) { + console.log(`Node.js version ${version} is required. You have ${process.version}.`); + process.exit(1); +} + require('commander') .version(require('../package').version) .usage(' [options]') From 3805b0d4bf2c15735a234f1ef0a98a49187aadd5 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 8 Apr 2017 16:52:53 -0500 Subject: [PATCH 2/8] Setup tunnel using localtunnel --- bin/probot-run | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bin/probot-run b/bin/probot-run index 34046e9b..30b14cda 100755 --- a/bin/probot-run +++ b/bin/probot-run @@ -17,6 +17,7 @@ program process.exit(1); } }, process.env.PRIVATE_KEY) + .option('-t, --tunnel ', 'Expose your local bot to the internet', process.env.NODE_ENV != 'production') .parse(process.argv); if(!program.integration) { @@ -36,6 +37,34 @@ if(!program.privateKey) { } } +if(program.tunnel) { + try { + setupTunnel(); + } catch(err) { + console.warn('Run `npm install --save-dev localtunnel` to enable localtunnel.'); + } +} + +function setupTunnel() { + const localtunnel = require('localtunnel'); + const subdomain = typeof program.tunnel == 'string' ? + program.tunnel : + require('os').userInfo().username; + + const tunnel = localtunnel(program.port, {subdomain}, function (err, tunnel) { + if (err) { + console.warn('Could not open tunnel: ', err.message); + } else { + console.log('Listening on ' + tunnel.url); + tunnel.url; + } + }); + + tunnel.on('close', function() { + console.warn('Local tunnel closed'); + }); +} + const pkgConf = require('pkg-conf'); const resolve = require('resolve').sync; const createProbot = require('../'); From 4ef44acd7aac350aba69bfce1f1014adecc0a846 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 8 Apr 2017 17:09:03 -0500 Subject: [PATCH 3/8] Add subdomain option --- .env.example | 3 +++ bin/probot-run | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 6dd400b5..ef9c345b 100644 --- a/.env.example +++ b/.env.example @@ -4,3 +4,6 @@ WEBHOOK_SECRET=development # Uncomment this to get verbose logging # LOG_LEVEL=trace # or `info` to show less + +# Subdomain to use for localtunnel server. Defaults to your local username. +# SUBDOMAIN= diff --git a/bin/probot-run b/bin/probot-run index 30b14cda..d0e36aef 100755 --- a/bin/probot-run +++ b/bin/probot-run @@ -49,7 +49,7 @@ function setupTunnel() { const localtunnel = require('localtunnel'); const subdomain = typeof program.tunnel == 'string' ? program.tunnel : - require('os').userInfo().username; + process.env.SUBDOMAIN || require('os').userInfo().username; const tunnel = localtunnel(program.port, {subdomain}, function (err, tunnel) { if (err) { From dc7800125424a08c70a5b00f4f35f9c6cb67dc9a Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 8 Apr 2017 17:09:34 -0500 Subject: [PATCH 4/8] Update docs to use localtunnel --- docs/development.md | 13 ++++--------- docs/plugins.md | 2 -- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/docs/development.md b/docs/development.md index 9f728427..136b03f9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -3,23 +3,18 @@ To run a plugin locally, you'll need to create a GitHub Integration and configure it to deliver webhooks to your local machine. 1. Make sure you have a recent version of [Node.js](https://nodejs.org/) installed -1. Install [ngrok](https://ngrok.com/download) (`$ brew cask install ngrok` on a mac), which will expose the local server to the internet so GitHub can send webhooks -1. Run `$ ngrok http 3000` to start ngrok, which should output something like `Forwarding https://4397efc6.ngrok.io -> localhost:3000` 1. [Create a new GitHub Integration](https://github.com/settings/integrations/new) with: - - **Callback URL** and **Webhook URL**: The full ngrok url above. For example: `https://4397efc6.ngrok.io/` + - **Webhook URL**: Set to `https://example.com/` and we'll update it in a minute. - **Webhook Secret:** `development` - **Permissions & events** needed will depend on how you use the bot, but for development it may be easiest to enable everything. 1. Download the private key and move it to the project directory 1. Edit `.env` and set `INTEGRATION_ID` to the ID of the integration you just created. -1. With `ngrok` still running, open another terminal and run `$ npm start` to start the server on http://localhost:3000 +1. Run `$ npm start` to start the server, which will output `Listening on https://yourname.localtunnel.me`; +1. Update the **Webhook URL** in the [integration settings](https://github.com/settings/integrations) to use the `localtunnel.me` URL. You'll need to create a test repository and install your Integration by clicking the "Install" button on the settings page. -Whenever you com back to work on the app after you've already had it running once, then you need to: - -1. Run `$ npm start` -1. Run `$ ngrok http 3000` in another terminal window -1. `ngrok` will use a different URL every time it is restarted, so you will have to go into the [settings for your Integration](https://github.com/settings/integrations) and update all the URLs. +Whenever you com back to work on the app after you've already had it running once, you should only need to run `$ npm start`. ## Debugging diff --git a/docs/plugins.md b/docs/plugins.md index 80fcfb25..40036084 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -107,8 +107,6 @@ $ probot run -i 9999 -P private-key.pem ./autoresponder.js Listening on http://localhost:3000 ``` -Once your bot is running, you'll need to use `ngrok` to receive GitHub webhooks as described in the [development](development.md) documentation. - ## Publishing your bot Plugins can be published in NPM modules, which can either be deployed as stand-alone bots, or combined with other plugins. From dba5ba8fbb34a38092019af02054cbf306ce549d Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 8 Apr 2017 17:16:17 -0500 Subject: [PATCH 5/8] Move subdomain config --- bin/probot-run | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/probot-run b/bin/probot-run index d0e36aef..8505c5b1 100755 --- a/bin/probot-run +++ b/bin/probot-run @@ -17,7 +17,7 @@ program process.exit(1); } }, process.env.PRIVATE_KEY) - .option('-t, --tunnel ', 'Expose your local bot to the internet', process.env.NODE_ENV != 'production') + .option('-t, --tunnel ', 'Expose your local bot to the internet', process.env.SUBDOMAIN || process.env.NODE_ENV != 'production') .parse(process.argv); if(!program.integration) { @@ -49,7 +49,7 @@ function setupTunnel() { const localtunnel = require('localtunnel'); const subdomain = typeof program.tunnel == 'string' ? program.tunnel : - process.env.SUBDOMAIN || require('os').userInfo().username; + require('os').userInfo().username; const tunnel = localtunnel(program.port, {subdomain}, function (err, tunnel) { if (err) { From ad7efd7d6934d7241392600df085db7aba137bd5 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 8 Apr 2017 17:17:31 -0500 Subject: [PATCH 6/8] Remove tunnel script --- script/tunnel | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 script/tunnel diff --git a/script/tunnel b/script/tunnel deleted file mode 100755 index b2ba4f8e..00000000 --- a/script/tunnel +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -ngrok http -bind-tls=true 3000 From 64814d2592f17e32ff9741fb620f46d3006d2c72 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 8 Apr 2017 17:35:29 -0500 Subject: [PATCH 7/8] Update log for local server --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 9f3758c7..665673ab 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ module.exports = options => { start() { server.listen(options.port); - console.log('Listening on http://localhost:' + options.port); + robot.log.trace('Listening on http://localhost:' + options.port); }, load(plugin) { From c7393aa604fd6bd964137c7be1a0845c8f745b80 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 8 Apr 2017 17:35:48 -0500 Subject: [PATCH 8/8] Release v0.4.0. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f403c889..ce2086e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "probot", - "version": "0.3.2", + "version": "0.4.0", "description": "a trainable robot that responds to activity on GitHub", "repository": "https://github.com/probot/probot", "main": "index.js",