-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (80 loc) · 2.26 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var GitHubApi = require('github');
var request = require("request");
var github = new GitHubApi({});
exports.handler = function(event, context) {
var url = "http://www.lemonde.fr/webservice/decodex/updates";
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
github.authenticate({
type: 'oauth',
token: 'XXXX'
}, function(err, res) {
// console.log(err);
// console.log(res);
});
var ref_master_sha = '';
github.gitdata.getReference({
owner: 'mtparet',
repo: 'decodex-data',
ref: "heads/master"
}, function(err, res) {
// console.log(err);
// console.log(res);
ref_master_sha = res.object.sha;
});
github.gitdata.createTree({
owner: 'mtparet',
repo: 'decodex-data',
tree: [
{
"path": "decodex.json",
"mode": "100644",
"type": "blob",
"content": JSON.stringify(body, undefined, 2)
}
],
base_tree: 'master'
}, function(err, res) {
// console.log(err);
// console.log(res);
github.gitdata.createCommit({
owner: 'mtparet',
repo: 'decodex-data',
message: 'automatic update',
tree: res.sha,
parents: [ref_master_sha]
}, function(err, res) {
// console.log(err);
// console.log(res);
github.repos.getCommit({
owner: 'mtparet',
repo: 'decodex-data',
sha: res.sha
}, function(err, res) {
// console.log(err);
// console.log(res);
console.log(res.stats);
if (res.stats.total == 0){
console.log('nothing to modify');
} else {
github.gitdata.updateReference({
owner: 'mtparet',
repo: 'decodex-data',
ref: "heads/master",
sha: res.sha,
force: true
}, function(err, res) {
console.log(err);
console.log(res);
context.done;
});
}
});
});
});
}
});
};