-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
69 lines (63 loc) · 1.94 KB
/
example.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
58
59
60
61
62
63
64
65
66
67
68
/*
* https://octokit.github.io/rest.js/v18
* https://github.com/octokit/rest.js
* https://github.com/octokit/rest.js/issues/1666
*/
const { Octokit } = require("@octokit/rest");
const base64 = require('base-64');
const CHIENWEN_ROBOT_AUTH_TOKEN = process.env.npm_config_CHIENWEN_ROBOT_AUTH_TOKEN;
const octokit = new Octokit({
auth: CHIENWEN_ROBOT_AUTH_TOKEN
});
var filePath = 'pizza/hut/hey7.py';
var content = "hello world\nnoway3\nkerker";
octokit.repos.getContent({
owner: "chienwen",
repo: "blahblah",
path: filePath,
}).then((olddata) => {
console.log(olddata);
octokit.repos.createOrUpdateFileContents({
owner: 'chienwen',
repo: 'blahblah',
path: filePath,
message: 'updating ' + (new Date).getTime(),
content: base64.encode(content),
sha: olddata.data.sha
}).then((data) => {
console.log(data);
}).catch((err) => {
console.log(err)
});
}).catch((err) => {
console.log(err);
if (err.status === 404) {
octokit.repos.createOrUpdateFileContents({
owner: 'chienwen',
repo: 'blahblah',
path: filePath,
message: 'creating ' + (new Date).getTime(),
content: base64.encode(content),
}).then((data) => {
console.log(data);
console.log('created', data.data.content.sha);
testsha = data.data.content.sha;
/*
octokit.repos.createOrUpdateFileContents({
owner: 'chienwen',
repo: 'blahblah',
path: filePath,
message: 'updating ' + (new Date).getTime(),
content: base64.encode('bingo'),
sha: testsha
}).then((data) => {
console.log(data);
}).catch((err) => {
console.log(err)
});
*/
}).catch((err) => {
console.log(err)
});
}
});