forked from cypress-io/cypress-test-tiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
early-stop.js
30 lines (27 loc) · 1009 Bytes
/
early-stop.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
// exits with 1 if the last commit subject includes a given string
// $ node ./early-stop.js foo
// examples using this script with "|| <some other command>"
//
// 1) failed to find substring
// $ node ./early-stop "foo" || echo "yes"
// cannot find string "foo" in commit subject "trying a node script on Window
//
// 2) finds substring
// $ node ./early-stop "foo" && echo "yes"
// cannot find string "foo" in commit subject "trying a node script on Windows
// yes
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const substring = process.argv[2]
if (!substring) {
throw new Error('Expected: string to find in the commit subject')
}
exec('git show -s --pretty=%s').then(result => {
const subject = result.stdout.trim()
if (subject.includes(substring)) {
console.log('found "%s" in commit subject "%s"', substring, subject)
process.exit(1)
} else {
console.log('cannot find string "%s" in commit subject "%s"', substring, subject)
}
})