Skip to content

Instantly share code, notes, and snippets.

@rossbulat
Created July 26, 2019 01:58
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/e91891c53efbe417ad00e8765d3f5d90 to your computer and use it in GitHub Desktop.
Save rossbulat/e91891c53efbe417ad00e8765d3f5d90 to your computer and use it in GitHub Desktop.
Create a Webhook with Octokit
const Octokit = require('@octokit/rest');
/* Script to Create a Github Webhook */
// configuration
const personalAccessToken = "" // personal access token
const webhookSecret = ""; // random string
const repoOwner = ""; // your username
const repoName = ""; // username/repo-name or organisation/repo-name
const webhookPayloadUrl = ""; // https://...
async function createPushWebhook (conf) {
const octokit = new Octokit({
auth: personalAccessToken
});
const res = await octokit.repos.createHook({
owner: conf.owner,
repo: conf.repo,
name: 'web',
config: {
url: conf.url,
content_type: 'json',
secret: webhookSecret,
insecure_ssl: 0,
},
events: [
'push'
]
}).catch(e => {
console.log(e);
});
console.log('success. Hook id: ' + res.data.id);
}
createPushWebhook({
owner: repoOwner,
repo: repoName,
url: webhookPayloadUrl
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment