forked from sap-tutorials/Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-last-commit.js
49 lines (42 loc) · 1.07 KB
/
test-last-commit.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
'use strict';
const gitLog = require('gitlog');
const testTool = require('./test-tool/src');
const { NODE_ENV } = process.env;
const isProduction = NODE_ENV === 'production';
const options = {
repo: __dirname,
number: 1,
execOptions: {
maxBuffer: 1024 * 1024,
},
};
gitLog(options, function (error, commits) {
if (error) {
console.log(error);
process.exit(1);
}
if (commits.length === 0) {
console.log('No commits. Exiting.');
process.exit(0);
}
const [lastCommit] = commits;
const { files } = lastCommit;
const mdFiles = files.filter(f => f.toLowerCase().endsWith('.md') && !f.includes('work-in-progress'));
if (mdFiles.length > 0) {
return testTool
.runSpecific(mdFiles, __dirname, isProduction)
.then(result => {
if (result.passed) {
process.exit(0);
} else {
process.exit(1);
}
}).catch((error) => {
console.log(error);
process.exit(1);
});
} else {
console.log('No .md files were changed in the last commit. Exiting.');
process.exit(0);
}
});