Github webhook failing

I encountered the same problem–response 200 but no further action as scripted–too but not asking for GitHub credentials. I invested a couple of hours and figured out that I didn’t set the secret in my github webhook. I made a little bit of workarounds and it works well. I hope my solution helps you:

  1. Set ‘Secret’ with your GitHub personal access token starting with ‘ghp_…’ in your repository’s webhook.

  2. Insert the personal access token in the webhook.js

The below is the code that I implemented in webhooks.js:

var secret = 'ghp_YOUR_PERSONAL_TOKEN; // Your secret key from Settings in GitHub
var repo = '/path/to/your/strapi/project'; // path to the root of your Strapi project on server

const http = require('http');
const crypto = require('crypto');
const exec = require('child_process').exec;

const PM2_CMD = 'sudo pm2 startOrRestart ecosystem.config.js';

http
  .createServer(function(req, res) {
    req.on('data', function(chunk) {
      let sig =
        'sha256=' +
        crypto
          .createHmac('sha256', secret)
          .update(chunk.toString())
          .digest('hex');

      if (req.headers['x-hub-signature-256'] == sig) {
        exec(`cd ${repo} && git pull && ${PM2_CMD}`, (error, stdout, stderr) => {
	  console.log('A Webhook received.')
	  if (error) {
            console.error(`exec error: ${error}`);
            return;
          }
          console.log(`stdout: ${stdout}`);
          console.log(`stderr: ${stderr}`);
        });
      }
    });

    res.end();
  })
  .listen(8565);  //port changed to 8565

I made a minor change in the code such as changing sha1 to sha256, port change and readability.