-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.js
57 lines (46 loc) · 1.73 KB
/
release.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const util = require('util');
const { resolve } = require('path');
const dotenv = require('dotenv');
const fs = require('fs');
const exec = util.promisify(require('child_process').exec);
const readFile = (fileName) => util.promisify(fs.readFile)(fileName, 'utf8');
const writeFile = (fileName, data) => util.promisify(fs.writeFile)(fileName, data, 'utf8');
const readJson = (fileName) => readFile(fileName).then(JSON.parse);
const writeJson = (fileName, data) => writeFile(fileName, JSON.stringify(data, null, 4) + '\n');
dotenv.config();
const Octokit = require("@octokit/rest");
const octokit = Octokit({
auth: process.env.GH_TOKEN,
userAgent: 'karelhala',
previews: ['jean-grey', 'symmetra'],
timeZone: 'Europe/Prague',
baseUrl: 'https://api.github.com'
});
const randomValue = Math.random().toString(36).substring(Math.round(Math.random() * Math.floor(10)));
const encodeFile = async (filename) => Buffer.from(await readFile(filename)).toString('base64');
(async () => {
const dump = await readJson('./dump.json');
dump.value = randomValue;
await writeJson('./dump.json', dump);
let sha;
try {
const { data: contents } = await octokit.repos.getContents({
owner: 'karelhala',
repo: 'cinema_browser',
path: 'dump.json'
});
sha = contents && contents.sha;
} catch(e) {}
const content = await encodeFile('./dump.json');
console.log(sha);
console.log(content);
octokit.repos.createOrUpdateFile({
owner: 'karelhala',
repo: 'cinema_browser',
path: 'dump.json',
message: 'Update dump file from bot!',
content: content,
debug: true,
...sha && { sha }
}).then(() => { }, console.log)
})();