Skip to content

Commit

Permalink
syncs
Browse files Browse the repository at this point in the history
  • Loading branch information
StanleyMasinde committed Jun 26, 2021
1 parent bba25f6 commit 3bbc42f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const logger = require('morgan')

const authRouter = require('./routes/auth')
const appsRouter = require('./routes/applications')
const webhooksRouter = require('./routes/webhooks')

const app = express()

Expand All @@ -30,6 +31,7 @@ app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())

app.use(webhooksRouter)
app.use('/auth', authRouter)
app.use('/applications', appsRouter)

Expand Down
25 changes: 25 additions & 0 deletions backend/app/controllers/webhookController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable camelcase */
const { exec } = require('child_process')
const Controller = require('./controller')

class WebhookController extends Controller {
/**
* Handle the github webhook
* @param {import('express').Request} req
* @param {import('express').Response} res
* @param {import('express').NextFunction} next
*/
async github(req, res, next) {
const full_name = req.body.repository
const app = await this._DB('applications').where({ full_name }).first()
if (app) {
const deploy = exec(app.command)
deploy.stdout.on('data', (chunk) => {
console.log(chunk)
})
}
res.status(201).json('') // Return 201 to Github
}
}

module.exports = new WebhookController()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports.up = function (knex) {
table.bigIncrements('id')
table.string('name')
table.string('full_name')
table.string('deploy_branch').defaultTo('main')
table.text('command')
table.timestamps(true, true)
})
Expand Down
13 changes: 13 additions & 0 deletions backend/routes/webhooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const router = require('express').Router()
const webhookController = require('../app/controllers/webhookController')

router

/**
* Github hnadler
*/
.post('/github', (req, res, next) => {
webhookController.github(req, res, next)
})

module.exports = router
1 change: 1 addition & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default {
*/
serverMiddleware: {
'/api': '~/backend/app.js',
'/webhooks': '~/backend/app.js',
},
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
// ssr: false,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "3.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"dev": "DEBUG=express* nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate",
Expand Down

0 comments on commit 3bbc42f

Please sign in to comment.