-
-
Save rossbulat/412b81fad4dc94f7f664fc14d29bdbfb to your computer and use it in GitHub Desktop.
Test a Webhook with Octokit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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