-
-
Save rossbulat/e91891c53efbe417ad00e8765d3f5d90 to your computer and use it in GitHub Desktop.
Create 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'); | |
/* 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