Skip to content

Commit

Permalink
Adds ability to run script with parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
maccyber committed Jan 29, 2017
1 parent f0a0f55 commit 0bf92b6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (request, reply) => {
const hooks = require('../scripts')
const token = request.params.token
const payload = request.payload
let err
let err = false

if (token !== config.token) {
err = 'Invalid token'
Expand Down Expand Up @@ -39,9 +39,11 @@ module.exports = (request, reply) => {
runScript(options)
.then(dockerhubCallback)
.then((data) => {
console.log(data)
request.log(['debug'], data.script.result)
request.log(['debug'], data.callback)
}).catch((err) => {
console.log(err)
request.log(['err'], err)
})
}
Expand Down
11 changes: 6 additions & 5 deletions lib/run-script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const path = require('path')
const pathJoin = require('path').join
const fileExists = require('file-exists')
const exec = require('child_process').exec

Expand All @@ -12,11 +12,12 @@ module.exports = (options) => {
if (!options.script) {
throw Error('Missing required input: options.script')
}
const scriptPath = path.resolve('scripts/' + options.script)
if (!fileExists(scriptPath)) {
throw Error(`File: ${scriptPath} does not exist`)
const scriptsPath = pathJoin('scripts/')
const filePath = scriptsPath + options.script.split(' ')[0]
if (!fileExists(filePath)) {
throw Error(`File: ${filePath} does not exist`)
}
exec(scriptPath, (err, stdout, stderr) => {
exec(scriptsPath + options.script, (err, stdout, stderr) => {
if (err || stderr) {
options.state = 'error'
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

module.exports = {
'testhook': 'hello.sh', // Name of reponame : Script
'testhook': 'hello.sh asd 1', // Name of reponame : Script
'maccyber.io': 'maccyber.io.sh',
'fail': 'fail.sh'
}

0 comments on commit 0bf92b6

Please sign in to comment.