Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ You can also specify a `--config <file>` where *file* is a JSON file containing
"rules": [{
"event": "push",
"match": "ref == \"refs/heads/master\" && repository.name == \"myrepo\"",
"exec": "echo yay!"
"exec": "echo yay!",
"report": "echo \"${gh_report}\" | mail -s 'Deployed ${gh_repository_name}' \"${gh_pusher_name} <${gh_pusher_email}>\""
}]
}
```
Expand Down
34 changes: 28 additions & 6 deletions 34 github-webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

const http = require('http')
const fs = require('fs')
const spawn = require('child_process').spawn
const childProcess = require('child_process')
const PassThrough = require('stream').PassThrough
const createHandler = require('github-webhook-handler')
const debug = require('debug')
const matchme = require('matchme')
const split2 = require('split2')
const through2 = require('through2')
const bl = require('bl')
const argv = require('minimist')(process.argv.slice(2))
const serverDebug = debug('github-webhook:server')
const eventsDebug = debug('github-webhook:events')
Expand Down Expand Up @@ -200,12 +202,14 @@ function handleRules (logStream, rules, event) {
const startTs = Date.now()
const eventStr = `event="${rule.event}", match="${rule.match}", exec="${rule.exec}"`
const exec = Array.isArray(rule.exec) ? rule.exec : ['sh', '-c', rule.exec]
const past = new PassThrough()

eventsDebug('Matched rule for %s', eventStr)

const cp = spawn(exec.shift(), exec, {
const childOpts = {
env: Object.assign(envFromPayload(event.payload, 'gh_'), process.env)
})
}

const cp = childProcess.spawn(exec.shift(), exec, childOpts)

cp.on('error', (err) => {
return eventsDebug('Error executing command [%s]: %s', rule.exec, err.message)
Expand All @@ -227,9 +231,27 @@ function handleRules (logStream, rules, event) {
}
})

if (logStream || rule.report) {
cp.stdout.pipe(past)
prefixStream(cp.stderr, '! ').pipe(past)
}

if (logStream) {
prefixStream(cp.stdout, 'stdout: ').pipe(logStream, { end: false })
prefixStream(cp.stderr, 'stderr: ').pipe(logStream, { end: false })
past.pipe(logStream, { end: false })
}
if (rule.report) {
past.pipe(bl((err, data) => {
if (err) {
console.error('Cannot buffer executed command output', err)
} else {
childOpts.env.gh_report = data.toString()
childProcess.exec(rule.report, childOpts, function (err) {
if (err) {
eventsDebug('Error executing report [%s]: %s', rule.report, err.message)
}
})
}
}))
}
}

Expand Down
1 change: 1 addition & 0 deletions 1 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"tape": "~4.11.0"
},
"dependencies": {
"bl": "~4.0.0",
"debug": "~4.1.1",
"github-webhook-handler": "~1.0.0",
"matchme": "~2.0.1",
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.