-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (24 loc) · 858 Bytes
/
index.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
'use strict'
const gitIsBranchProtected = require('git-is-branch-protected')
module.exports = async ({ branches, silent }) => {
if (typeof branches !== 'string') {
throw new TypeError(`Expected a comma-separated list for "branches", got ${typeof branches}`)
}
// 1. Check allowed branches
let allowedBranches = []
if (branches) {
// create an Array of Strings from comma-separated list and remove any whitespaces
allowedBranches = branches.split(',').map(b => b.trim())
}
// 2. Check whether branch is protected
// We let "gitIsBranchProtected" check which branch we are on, hence, passing "undefined"
const isProtected = await gitIsBranchProtected(undefined, allowedBranches)
if (isProtected) {
if (!silent) {
console.error('Branch is protected')
}
process.exit(1)
} else {
process.exit(0)
}
}