Browse Source

Add webhooks into the server directly.

master
Zed A. Shaw 1 month ago
parent
commit
56202923d7
5 changed files with 34 additions and 21 deletions
  1. +1
    -0
      __tests__/fixtures/secrets.js
  2. +14
    -14
      lib/gitea.js
  3. +16
    -7
      package-lock.json
  4. +1
    -0
      package.json
  5. +2
    -0
      src/server.js

+ 1
- 0
__tests__/fixtures/secrets.js View File

@@ -48,6 +48,7 @@ exports.webtorrent = {
}

exports.webhook_hash = 'nunyabuziness';
exports.webhook_url = 'nunyabuziness';

exports.admin_email = 'zed@learnjsthehardway.com';



scripts/services/webhook.js → lib/gitea.js View File

@@ -1,33 +1,33 @@
const secrets = require('../../lib/secrets');
const http = require('http')
const secrets = require('../lib/secrets');
const createHandler = require('gitea-webhook-handler')
const handler = createHandler({ path: '/webhook', secret: secrets.webhook })
const handler = createHandler({ path: secrets.webhook_url, secret: secrets.webhook_hash })
const Queue = require('bull');
const { log } = require('../lib/logging');

const gitQ = new Queue('ci.git', secrets.bull_config);

http.createServer(function (req, res) {
handler(req, res, function (err) {
res.statusCode = 404
res.end('no such location')
})
}).listen(7790);

handler.on('error', function (err) {
handler.on('error', (err) => {
console.error('Error:', err.message)
});

handler.on('push', function (event) {
handler.on('push', (event) => {
console.log('Received a push event for %s to %s',
event.payload.repository.name,
event.payload.ref);
gitQ.add({gitpush: event});
gitQ.add({gitpush: event});
});

handler.on('issues', function (event) {
handler.on('issues', (event) => {
console.log('Received an issue event for %s action=%s: #%d %s',
event.payload.repository.name,
event.payload.action,
event.payload.issue.number,
event.payload.issue.title)
});

exports.gitea = (req, res) => {
handler(req, res, () => {
res.statusCode = 404
res.end('no such location')
})
}

+ 16
- 7
package-lock.json View File

@@ -3065,8 +3065,7 @@
"base64-js": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz",
"integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==",
"dev": true
"integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g=="
},
"basic-auth": {
"version": "2.0.1",
@@ -3320,7 +3319,6 @@
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.0.2.tgz",
"integrity": "sha512-j4OH8f6Qg2bGuWfRiltT2HYGx0e1QcBTrK9KAHNMwMZdQnDZFk0ZSYIpADjYCB3U12nicC5tVJwSIhwOWjb4RQ==",
"dev": true,
"requires": {
"buffer": "^5.5.0",
"inherits": "^2.0.4",
@@ -3331,7 +3329,6 @@
"version": "3.6.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
"integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
"dev": true,
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
@@ -3572,7 +3569,6 @@
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.5.0.tgz",
"integrity": "sha512-9FTEDjLjwoAkEwyMGDjYJQN2gfRgOKBKRfiglhvibGbpeeU/pQn1bJxQqm32OD/AIeEuHxU9roxXxg34Byp/Ww==",
"dev": true,
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4"
@@ -3605,6 +3601,11 @@
"integrity": "sha1-WWFrSYME1Var1GaWayLu2j7KX74=",
"dev": true
},
"buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
},
"buffer-fill": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz",
@@ -6527,6 +6528,15 @@
"assert-plus": "^1.0.0"
}
},
"gitea-webhook-handler": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/gitea-webhook-handler/-/gitea-webhook-handler-1.0.6.tgz",
"integrity": "sha512-I5VIsLQXGd8zLsv1G4KRF3gCHwCsBVN3nzFvnzuw1AcVXo8IL+nXvws4B5wN7rG2SExJpe3ZmF+l2xXzCOqVyQ==",
"requires": {
"bl": "~4.0.0",
"buffer-equal-constant-time": "^1.0.1"
}
},
"github-from-package": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz",
@@ -8164,8 +8174,7 @@
"ieee754": {
"version": "1.1.13",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz",
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==",
"dev": true
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
},
"ignore": {
"version": "5.1.4",


+ 1
- 0
package.json View File

@@ -27,6 +27,7 @@
"eslint": "^7.10.0",
"express-session": "^1.17.0",
"form-urlencoded": "^4.1.3",
"gitea-webhook-handler": "^1.0.6",
"html-pdf": "^2.2.0",
"knex": "^0.20.12",
"knex-paginate": "^1.2.3",


+ 2
- 0
src/server.js View File

@@ -7,6 +7,7 @@ import morgan from 'morgan';
import polka from 'polka';
import requestIp from 'request-ip';
import { serverauth } from '../lib/serverauth';
import { gitea } from '../lib/gitea';
import sirv from 'sirv';

const { PORT, NODE_ENV, LOG_ALL } = process.env;
@@ -20,6 +21,7 @@ if(LOG_ALL) {

app.use(bodyParser.json());
app.use(requestIp.mw());
app.use('/webhook', gitea);

// be sure to change secret to keygrip
app.use(cookieSession({


Loading…
Cancel
Save