-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·57 lines (46 loc) · 1.55 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
const REGEX_MAIN = /^main$/g;
const REGEX_FEATURE = /^feature\/[A-Z0-9]{1,10}-[0-9]{1,4}$/g;
const REGEX_HOTFIX = /^hotfix\/[A-Z0-9]{1,10}-[0-9]{1,4}$/g;
const REGEX_RELEASE = /^release\/\d+\.\d+\.\d+$/g;
const BRANCHING_MODEL_MAP = new Map();
BRANCHING_MODEL_MAP.set(REGEX_RELEASE, [REGEX_FEATURE]);
BRANCHING_MODEL_MAP.set(REGEX_MAIN, [REGEX_RELEASE, REGEX_HOTFIX]);
// branch we are opening the PR from...
const HEAD_REF = process.env.GITHUB_HEAD_REF;
// branch we are merging into...
const BASE_REF = process.env.GITHUB_BASE_REF;
console.log(`head branch is ${HEAD_REF}.`);
console.log(`base branch is ${BASE_REF}.`);
for (const patternBaseRef of BRANCHING_MODEL_MAP.keys()) {
const matches = BASE_REF.match(patternBaseRef);
if (matches) {
console.log(
`Base branch is matching a definition in our branching-model => `,
patternBaseRef
);
const allowedHeadRefs = BRANCHING_MODEL_MAP.get(patternBaseRef);
console.log(
`Allowed head branches for this base branch are =>`,
allowedHeadRefs
);
for (const allowedHeadRef of allowedHeadRefs) {
const matches = HEAD_REF.match(allowedHeadRef);
if (matches) {
console.log(
`Head branch is matching this regular expression =>`,
allowedHeadRef
);
process.exit(0);
}
console.log(
`Head branch is not matching this regular expression =>`,
allowedHeadRef
);
}
}
}
console.error(
`Branches of the pull request aren't matching our branching model!`
);
process.exit(1);