Skip to content

Instantly share code, notes, and snippets.

@rossbulat

rossbulat/test-webhook.js Secret

Created Jul 26, 2019
Embed
What would you like to do?
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