Compare commits

..

2 Commits

Author SHA1 Message Date
71ffc9b6c1 Added shell execution 2022-01-17 21:50:27 -05:00
7342fd8cb0 Move nodemon to dev dependency 2022-01-17 21:44:10 -05:00
3 changed files with 21 additions and 8 deletions

View File

@ -1 +1,3 @@
PORT="5000"
SECRET_KEY="" 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, () => {

View File

@ -11,7 +11,9 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"dotenv": "^14.2.0", "dotenv": "^14.2.0",
"express": "^4.17.2", "express": "^4.17.2"
},
"devDependencies": {
"nodemon": "^2.0.15" "nodemon": "^2.0.15"
} }
} }