-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (57 loc) · 1.62 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
const Bitbucket = require('./src/resource/bitbucket');
const bitbucket = new Bitbucket();
function loadPackage(repo) {
const { slug, project} = repo;
return bitbucket
.getFile(project.key, slug, 'package.json')
.catch((e)=>{});
}
function loadProjectPage(start) {
return bitbucket
.getAllRepositories(100, start)
.then((res) => {
const { nextPageStart, isLastPage, values } = res;
return {
nextPageStart,
isLastPage,
values: values.map((item) => {
const { project, slug, links } = item;
return { project, slug, links };
})
};
})
}
loadProjectPage(0)
.then((repos) => {
const result = [];
const promises = repos.values.map((repo) => {
const { links } = repo;
return loadPackage(repo)
.then(data => {
if (data) {
result.push({
data,
repo: links.self
});
}
})
});
return Promise
.all(promises)
.then(() => {
return result;
})
})
.then(res => {
console.log(`OK`);
res.forEach((file) => {
console.log(file);
})
})
.catch((err) => {
console.log(err);
// console.log(`ERROR`, err.response.status);
// console.log(err.config);
// console.log(err.response.headers);
// console.log(err);
});