-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.ts
41 lines (32 loc) · 1.47 KB
/
index.ts
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
import {Application} from 'probot';
import {getTouchedSourceFilesRequireTests, getTouchedTestFiles} from './fileFilters';
export = (app: Application) => {
app.on('pull_request.opened', async (context) => {
const config = await context.config('tests_checker.yml', {
comment: 'Could you please add tests to make sure this change works as expected?',
fileExtensions: ['.php', '.ts', '.js', '.c', '.cs', '.cpp', '.rb', '.java'],
testDir: 'tests',
});
const issue = context.issue();
context.log('PR=' + 'https://github.com/' + issue.owner + '/' + issue.repo + '/pull/' + issue.number);
const allFiles = await context.github.paginate(
context.github.pullRequests.getFiles(issue),
(res) => res.data,
);
const sourceFilesRequireTests = getTouchedSourceFilesRequireTests(allFiles, config.fileExtensions);
if (sourceFilesRequireTests.length === 0) {
context.log('PR does not have files that require tests. Skipping...');
return;
}
const testFiles = getTouchedTestFiles(allFiles, config.testDir);
context.log('testFiles=', testFiles);
if (testFiles.length === 0) {
context.log('Adding a comment about tests.');
context.github.pullRequests.createReview({
...issue,
body: config.comment,
event: 'REQUEST_CHANGES',
});
}
});
};