Added shell execution

This commit is contained in:
Thomas Cole 2022-01-17 21:50:27 -05:00
parent 7342fd8cb0
commit 71ffc9b6c1
2 changed files with 18 additions and 7 deletions

View File

@ -1 +1,3 @@
SECRET_KEY="" PORT="5000"
SECRET_KEY=""
EXECUTE_SCRIPT=""

View File

@ -1,11 +1,14 @@
// The base for this script was shameless copied from https://discourse.gitea.io/t/how-to-write-a-webhook-in-gitea-in-node-js-javascript/1907
const express = require('express') const express = require('express')
const crypto = require('crypto') const crypto = require('crypto')
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
const { exec } = require('child_process')
require('dotenv').config() require('dotenv').config()
const SECRET = process.env.SECRET_KEY const SECRET = process.env.SECRET_KEY
const app = express() const app = express()
const port = 9000 const port = process.env.PORT
const options = { const options = {
inflate: true, inflate: true,
@ -14,7 +17,7 @@ const options = {
} }
app.use(bodyParser.raw(options)) app.use(bodyParser.raw(options))
app.post('/buildhook', (req, res) => { app.post('/', (req, res) => {
const signature = req.headers['x-gitea-signature'] const signature = req.headers['x-gitea-signature']
if (!signature) { if (!signature) {
console.error('x-gitea-signature missing') console.error('x-gitea-signature missing')
@ -31,12 +34,18 @@ app.post('/buildhook', (req, res) => {
} }
const json = JSON.parse(req.body.toString()) const json = JSON.parse(req.body.toString())
console.log('json') console.log(json.repository.clone_url)
console.log(json)
// SIGNATURES MATCHES, do your thing here. // SIGNATURES MATCHES, do your thing here.
var buildscript = exec('sh ' + process.env.EXECUTE_SCRIPT, (error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
res.send('success') res.sendStatus(200);
}) })
app.listen(port, () => { app.listen(port, () => {