-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.js
72 lines (60 loc) · 2.08 KB
/
actions.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
require('es6-promise').polyfill();
var Reflux = require('reflux');
var xr = require('xr');
var Immutable = require('immutable');
xr.configure({
headers: {
'accept': 'application/vnd.github.moondragon+json',
'authorization': 'Token GITHUB_TOKEN'
}
});
function xrp (x, accumulator) {
return new Promise(function (resolve, reject) {
x.then(function (res) {
var link_header = res.xhr.getResponseHeader('link'),
link_match = link_header && link_header.match(/<([^>]+)>; rel="next"/),
data = Immutable.fromJS(res.data);
if (accumulator) {
data = accumulator.concat(data);
}
if (link_match) {
resolve(xrp(xr.get(link_match[1]), data));
}
else {
resolve(data);
}
}).catch(function (res) {
reject(res.status);
});
});
}
var actions = Reflux.createActions({
"init": {},
"updateRepoList": { asyncResult: true },
"updateAllPRLists": { asyncResult: true },
"updatePRList": { asyncResult: true },
"updatePRStatus": { asyncResult: true },
"filterByOwner": {},
"selectOwner": {},
});
actions.init.listen(actions.updateRepoList);
actions.updateRepoList.listenAndPromise(function () {
return xrp(xr.get('https://api.github.com/user/repos'));
});
actions.updateRepoList.completed.listen(actions.updateAllPRLists);
actions.updateAllPRLists.listenAndPromise(function (repos) {
return repos.map(function (repo) {
return actions.updatePRList(repo.get('owner').get('login'), repo.get('name'));
}).toJS();
});
/*
actions.updateAllPRLists.completed.listen(function () {
console.log("finished loading PRs for all repositories");
});
*/
actions.updatePRList.listenAndPromise(function (owner, repo) {
return xrp(xr.get('https://api.github.com/repos/' + owner + '/' + repo + '/pulls'));
});
actions.selectOwner.listen(actions.filterByOwner);
actions.selectOwner.listen(function (owner) { console.log("Owner " + owner + " selected");});
module.exports = actions;