/
gh-ip-check.js
40 lines (34 loc) · 1.03 KB
/
gh-ip-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const http = require('http');
const express = require('express');
const { Octokit } = require("@octokit/rest");
const config = require('./config.json')
const octokit = new Octokit({
auth: config.githubAuth,
userAgent: 'angryproxy v0.0.1',
});
const publicIp = require('public-ip');
(async () => {
let currentIp = await publicIp.v4();
let hook = await octokit.request('GET /repos/{owner}/{repo}/hooks/{hook}', {
owner: config.repoOwner,
repo: config.repoName,
hook: 7892826
})
let configuredIp = new URL(hook.data.config.url).hostname;
if (configuredIp == currentIp) {
console.log("ip was the same");
} else {
console.log("ip changed from "+configuredIp+" to "+currentIp);
await octokit.request('PATCH /repos/{owner}/{repo}/hooks/{hook}', {
owner: config.repoOwner,
repo: config.repoName,
hook: 7892826,
config: {
content_type: 'json',
insecure_ssl: '0',
url: 'http://'+currentIp+':8080/ghprbhook/'
}
})
console.log("github was updated");
}
})();