3
3
# Supported parts are conventional commit types (`type`) and ticket numbers (`123` or `GH-123`)
4
4
# The branch name will result in a commit message template like this:
5
5
# - type-some-description -> type:
6
- # - type-GH-123-description -> type: [GH-123]
7
- # - type-123-description -> type: [#123]
8
- # - 123-description -> [#123]
6
+ # - type-GH-123-description -> type: GH-123
7
+ # - type-123-description -> type: #123
8
+ # - 123-description -> #123
9
+ # - 123-GH-124-description -> #123 GH-124
9
10
# - some-description ->
10
11
12
+
11
13
set -l COMMIT_MSG_FILE $argv [1]
12
14
13
15
set -l EXCLUDE_BRANCHES master main dev
@@ -23,29 +25,32 @@ if test -n (head -n 1 $COMMIT_MSG_FILE)
23
25
exit 0
24
26
end
25
27
26
- set -l PARTS (string split --max 3 ' -' $BRANCH )
28
+ set -l PARTS (string split ' -' $BRANCH )
27
29
28
30
# building list of conventional commit types
29
31
set CONVENTIONAL_COMMIT_TYPES build chore ci docs feat fix perf refactor revert style test
30
32
for TYPE in $CONVENTIONAL_COMMIT_TYPES
31
- set -a CONVENTIONAL_COMMIT_TYPES " $TYPE !"
33
+ set --append CONVENTIONAL_COMMIT_TYPES " $TYPE !"
32
34
end
33
35
34
36
# checking if it includes conventional commit (scope not supported)
35
37
if contains $PARTS [1] $CONVENTIONAL_COMMIT_TYPES
36
- set CC_TYPE " $PARTS [1]: "
37
- set -e PARTS[1]
38
- else
39
- set CC_TYPE ' '
38
+ set --append MESSAGE " $PARTS [1]:"
39
+ set --erase PARTS[1]
40
40
end
41
41
42
42
# checking if it includes ticket number
43
- if string match -q -r ' ^[A-Z]+$' $PARTS [1] && string match -q -r ' ^[0-9]+$' $PARTS [2]
44
- set TICKET " [$PARTS [1]-$PARTS [2]]"
45
- else if string match -q -r ' ^[0-9]+$' $PARTS [1]
46
- set TICKET " [#$PARTS [1]] "
47
- else
48
- set TICKET ' '
43
+ while test (count $PARTS ) -ge 2
44
+ echo $PARTS
45
+ if string match -q -r ' ^[A-Z]+$' $PARTS [1] && string match -q -r ' ^[0-9]+$' $PARTS [2]
46
+ set --append MESSAGE " $PARTS [1]-$PARTS [2]"
47
+ set --erase PARTS[1 2]
48
+ else if string match -q -r ' ^[0-9]+$' $PARTS [1]
49
+ set --append MESSAGE " #$PARTS [1]"
50
+ set --erase PARTS[1]
51
+ else
52
+ break
53
+ end
49
54
end
50
55
51
- sed -i " 1s/.*/$CC_TYPE$TICKET /" $COMMIT_MSG_FILE
56
+ sed -i " 1s/.*/$MESSAGE /" $COMMIT_MSG_FILE
0 commit comments