Skip to content

Instantly share code, notes, and snippets.

@rossbulat
Created July 26, 2019 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossbulat/412b81fad4dc94f7f664fc14d29bdbfb to your computer and use it in GitHub Desktop.
Save rossbulat/412b81fad4dc94f7f664fc14d29bdbfb to your computer and use it in GitHub Desktop.
Test a Webhook with Octokit
const Octokit = require('@octokit/rest');
const minimist = require('minimist');
/* Script to Test a Github Webhook
*
* Expects a hook_id argument
* E.g. node test.js --hook_id '123456'
*/
// configuration
const personalAccessToken = "" // personal access token
const repoOwner = ""; // your username
const repoName = ""; // username/repo-name or organisation/repo-name
const argv = minimist(process.argv.slice(2));
if (argv['hook_id'] === undefined) {
console.log("stopping execution: no hook_id provided. Use --hook_id 'your_hook_id'");
return;
}
async function testWebhook (conf) {
const octokit = new Octokit({
auth: personalAccessToken
});
const res = await octokit.repos.testPushHook({
owner: conf.owner,
repo: conf.repo,
hook_id: conf.hook_id
})
.catch(e => {
console.log(e);
});
console.log(res);
}
testWebhook({
owner: repoOwner,
repo: repoName,
hook_id: process.argv[3]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment