-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerate-migration-guide.js
50 lines (44 loc) · 1.12 KB
/
generate-migration-guide.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
/** Copyright (c) 2017 Uber Technologies, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
const pattern = /(\d{5})\.md/;
module.exports = async function generateMigrationGuide(context, prs) {
const {github} = context;
let migrations;
try {
migrations = await github.repos.getContent(
context.repo({
path: 'docs/migrations',
}),
);
} catch (err) {
if (err.code === 404) {
return '';
} else {
throw new Error('unexpected error getting docs/migrations');
}
}
const files = migrations.data.filter(file => {
if (file.type === 'file') {
const results = file.name.match(pattern);
if (results) {
const number = parseInt(results[1], 10);
return prs.has(number);
}
}
});
const contents = await Promise.all(
files.map(file =>
github.repos.getContent(
context.repo({
path: file.path,
}),
),
),
);
return contents
.map(res => Buffer.from(res.data.content, 'base64').toString())
.join('\n');
};