-
Notifications
You must be signed in to change notification settings - Fork 22
/
github.js
48 lines (43 loc) · 1.1 KB
/
github.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
import got from 'got';
import race from 'promise-rat-race';
function getChangelog({
githubRepo = {
user: '',
project: '',
path: '',
},
gitHead = 'master',
}) {
if (githubRepo === null) {
return { changelogFilename: null };
}
const { user, project, path } = githubRepo;
if (user.length < 1 || project.length < 1) {
return { changelogFilename: null };
}
const baseGithubURL = `https://raw.githubusercontent.com/${user}/${project}/${gitHead}/${`${path.replace('/tree/', '')}`}`;
const files = [
'CHANGELOG.md',
'ChangeLog.md',
'changelog.md',
'CHANGELOG',
'ChangeLog',
'changelog',
'CHANGES.md',
'changes.md',
'Changes.md',
'CHANGES',
'changes',
'Changes',
'HISTORY.md',
'history.md',
'HISTORY',
'history',
].map(file => [baseGithubURL.replace(/\/$/, ''), file].join('/'));
return race(files.map(got, { method: 'HEAD' }))
.then(({ url }) => ({ changelogFilename: url }))
.catch(() => ({ changelogFilename: null }));
}
export function getChangelogs(pkgs) {
return Promise.all(pkgs.map(getChangelog));
}