Comparing version 0.6.0 to 0.7.0
@@ -40,3 +40,8 @@ #!/usr/bin/env node | ||
try { | ||
setupTunnel(); | ||
const setupTunnel = require('../lib/tunnel'); | ||
setupTunnel(program.tunnel, program.port).then(tunnel => { | ||
console.log('Listening on ' + tunnel.url); | ||
}).catch(err => { | ||
console.warn('Could not open tunnel: ', err.message); | ||
}); | ||
} catch (err) { | ||
@@ -47,22 +52,2 @@ console.warn('Run `npm install --save-dev localtunnel` to enable localtunnel.'); | ||
function setupTunnel() { | ||
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved | ||
const localtunnel = require('localtunnel'); | ||
const subdomain = typeof program.tunnel === 'string' ? | ||
program.tunnel : | ||
require('os').userInfo().username; | ||
const tunnel = localtunnel(program.port, {subdomain}, (err, tunnel) => { | ||
if (err) { | ||
console.warn('Could not open tunnel: ', err.message); | ||
} else { | ||
console.log('Listening on ' + tunnel.url); | ||
} | ||
}); | ||
tunnel.on('close', () => { | ||
console.warn('Local tunnel closed'); | ||
}); | ||
} | ||
const createProbot = require('../'); | ||
@@ -69,0 +54,0 @@ |
# Changelog | ||
## 7.7.0 | ||
Breaking Changes: | ||
- Callbacks passed to `robot.on` used to take two arguments—`event` and `context`. The second was pretty much just a fancy version of the first, and you really need the second to do anything useful, so the first argument has been dropped. (Technically, the second is passed as both arguments for now to preserve backward compatibility, but this won't be the case forever, so go update your plugins). You will see this warning when loading plugins: | ||
``` | ||
DEPRECATED: Event callbacks now only take a single `context` argument. | ||
at module.exports.robot (/path/to/your/plugin.js:3:9) | ||
``` | ||
Before: | ||
```js | ||
robot.on('issues.opened', async (event, context) => { | ||
log('Event and context? What is the difference?', events, context); | ||
}); | ||
``` | ||
After: | ||
```js | ||
robot.on('issues.opened', async context => { | ||
log('Sweet, just one arg', context, context.payload); | ||
}); | ||
``` | ||
Enhancements: | ||
- Fix issue where localtunnel would often not reconnect when you restart the probot process. ([#157](https://github.com/probot/probot/pull/157)) | ||
[View full changelog](https://github.com/probot/probot/compare/v0.6.0...v0.7.0) | ||
## v0.6.0 (2017-06-09) | ||
@@ -4,0 +38,0 @@ |
@@ -21,5 +21,5 @@ # Plugins | ||
module.exports = robot => { | ||
robot.on('push', async (event, context) => { | ||
robot.on('push', async context => { | ||
// Code was pushed to the repo, what should we do with it? | ||
robot.log(event); | ||
robot.log(context); | ||
}); | ||
@@ -35,3 +35,3 @@ }; | ||
module.exports = robot => { | ||
robot.on('issues.opened', async (event, context) => { | ||
robot.on('issues.opened', async context => { | ||
// An issue was just opened. | ||
@@ -52,3 +52,3 @@ }); | ||
module.exports = robot => { | ||
robot.on('issues.opened', async (event, context) => { | ||
robot.on('issues.opened', async context => { | ||
// `context` extracts information from the event, which can be passed to | ||
@@ -55,0 +55,0 @@ // GitHub API calls. This will return: |
@@ -6,10 +6,15 @@ /** | ||
* @property {github} github - An authenticated GitHub API client | ||
* @property {event} event - The webhook event | ||
* @property {payload} payload - The webhook event payload | ||
*/ | ||
class Context { | ||
constructor(event, github) { | ||
this.event = event; | ||
Object.assign(this, event); | ||
this.github = github; | ||
} | ||
get event() { | ||
console.warn('DEPRECATED: All properties of `context.event` are now directly available on `context` (e.g. `context.payload.sender`).'); | ||
return this; | ||
} | ||
/** | ||
@@ -28,3 +33,3 @@ * Return the `owner` and `repo` params for making API requests against a | ||
repo(object) { | ||
const repo = this.event.payload.repository; | ||
const repo = this.payload.repository; | ||
@@ -50,3 +55,3 @@ return Object.assign({ | ||
issue(object) { | ||
const payload = this.event.payload; | ||
const payload = this.payload; | ||
return Object.assign({ | ||
@@ -62,3 +67,3 @@ number: (payload.issue || payload.pull_request || payload).number | ||
get isBot() { | ||
return this.event.payload.sender.type === 'Bot'; | ||
return this.payload.sender.type === 'Bot'; | ||
} | ||
@@ -65,0 +70,0 @@ } |
@@ -39,7 +39,7 @@ const GitHubApi = require('github'); | ||
* | ||
* robot.on('push', (event, context) => { | ||
* robot.on('push', context => { | ||
* // Code was just pushed. | ||
* }); | ||
* | ||
* robot.on('issues.opened', (event, context) => { | ||
* robot.on('issues.opened', context => { | ||
* // An issue was just opened. | ||
@@ -49,2 +49,8 @@ * }); | ||
on(event, callback) { | ||
if (callback.length === 2) { | ||
const caller = (new Error()).stack.split('\n')[2]; | ||
console.warn('DEPRECATED: Event callbacks now only take a single `context` argument.'); | ||
console.warn(caller); | ||
} | ||
const [name, action] = event.split('.'); | ||
@@ -56,3 +62,4 @@ | ||
const github = await this.auth(event.payload.installation.id); | ||
return callback(event, new Context(event, github)); | ||
const context = new Context(event, github); | ||
return callback(context, context /* DEPRECATED: for backward compat */); | ||
} catch (err) { | ||
@@ -77,3 +84,3 @@ this.log.error(err); | ||
* module.exports = function(robot) { | ||
* robot.on('issues.opened', async (event, context) => { | ||
* robot.on('issues.opened', async context => { | ||
* const github = await robot.auth(); | ||
@@ -84,3 +91,3 @@ * }); | ||
* @param {number} [id] - ID of the installation, which can be extracted from | ||
* `event.payload.installation.id`. If called without this parameter, the | ||
* `context.payload.installation.id`. If called without this parameter, the | ||
* client wil authenticate [as the integration](https://developer.github.com/apps/authentication/#as-an-integration) | ||
@@ -153,10 +160,11 @@ * instead of as a specific installation, which means it can only be used for | ||
* @callback Robot~webhookCallback | ||
* @param {event} event - the event that was triggered, including `event.payload` which has | ||
* @param {Context} context - helpers for extracting information from the event, which can be passed to GitHub API calls | ||
* @param {Context} context - the context of the event that was triggered, | ||
* including `context.payload`, and helpers for extracting information from | ||
* the payload, which can be passed to GitHub API calls. | ||
* | ||
* ```js | ||
* module.exports = robot => { | ||
* robot.on('push', (event, context) => { | ||
* robot.on('push', context => { | ||
* // Code was pushed to the repo, what should we do with it? | ||
* robot.log(event); | ||
* robot.log(context); | ||
* }); | ||
@@ -168,7 +176,5 @@ * }; | ||
/** | ||
* A [GitHub webhook event](https://developer.github.com/webhooks/#events) | ||
* A [GitHub webhook event](https://developer.github.com/webhooks/#events) payload | ||
* | ||
* @typedef event | ||
* @property {string} event - the name of the event that was triggered | ||
* @property {object} payload - the payload from the webhook | ||
* @typedef payload | ||
*/ | ||
@@ -175,0 +181,0 @@ |
@@ -10,2 +10,4 @@ const http = require('http'); | ||
res.end('Something has gone terribly wrong.'); | ||
} else if (req.url.split('?').shift() === '/ping') { | ||
res.end('PONG'); | ||
} else { | ||
@@ -12,0 +14,0 @@ res.statusCode = 404; |
{ | ||
"name": "probot", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "a trainable robot that responds to activity on GitHub", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/probot/probot", |
@@ -21,2 +21,6 @@ const expect = require('expect'); | ||
it('inherits the payload', () => { | ||
expect(context.payload).toBe(event.payload); | ||
}); | ||
describe('repo', function () { | ||
@@ -23,0 +27,0 @@ it('returns attributes from repository payload', function () { |
@@ -57,4 +57,4 @@ const expect = require('expect'); | ||
expect(spy).toHaveBeenCalled(); | ||
expect(spy.calls[0].arguments[0]).toBe(event); | ||
expect(spy.calls[0].arguments[1]).toBeA(Context); | ||
expect(spy.calls[0].arguments[0]).toBeA(Context); | ||
expect(spy.calls[0].arguments[0].payload).toBe(event.payload); | ||
}); | ||
@@ -61,0 +61,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73084
41
1217
2