Skip to content

Commit ad13636

Browse files
committed
feat(jira): jira ref in header
1 parent 36d53d3 commit ad13636

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

validator.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ ABC-1234"
9797
[[ $GLOBAL_FOOTER == "" ]]
9898
}
9999

100+
@test "structure: valid commit message with JIRA in header" {
101+
COMMIT="feat(abc): ABC-1234
102+
103+
plop"
104+
105+
GLOBAL_JIRA_IN_HEADER="allow" validate_overall_structure "$COMMIT"
106+
[[ $GLOBAL_HEADER == "feat(abc): ABC-1234" ]]
107+
[[ $GLOBAL_JIRA == "ABC-1234" ]]
108+
[[ $GLOBAL_BODY == "plop"$'\n' ]]
109+
[[ $GLOBAL_FOOTER == "" ]]
110+
}
111+
100112
@test "structure: valid commit message with header and multiple JIRA" {
101113
COMMIT="plop plop
102114

validator.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ readonly HEADER_PATTERN="^([^\(]+)\(([^\)]+)\): (.+)$"
88
readonly TYPE_PATTERN="^(feat|fix|docs|gen|lint|refactor|test|chore)$"
99
readonly SCOPE_PATTERN="^([a-z][a-z0-9]*)(-[a-z0-9]+)*$"
1010
readonly SUBJECT_PATTERN="^([a-z0-9].*[^ ^\.])$"
11-
readonly JIRA_PATTERN="^([A-Z]{2,4}-[0-9]{1,6} ?)+$"
11+
readonly JIRA_PATTERN="^([A-Z]{3,4}-[0-9]{1,6} ?)+$"
12+
readonly JIRA_HEADER_PATTERN="^.*([A-Z]{3,4}-[0-9]{1,6}).*$"
1213
readonly BROKE_PATTERN="^BROKEN:$"
1314
readonly TRAILING_SPACE_PATTERN=" +$"
1415
readonly REVERT_HEADER_PATTERN="^[R|r]evert[: ].*$"
@@ -29,9 +30,12 @@ readonly ERROR_REVERT=10
2930
GLOBAL_HEADER=""
3031
GLOBAL_BODY=""
3132
GLOBAL_JIRA=""
33+
GLOBAL_FOOTER=""
34+
35+
# Overridable variables
3236
GLOBAL_JIRA_TYPES="${GLOBAL_JIRA_TYPES:-feat fix}"
3337
GLOBAL_MAX_LENGTH="${GLOBAL_MAX_LENGTH:-70}"
34-
GLOBAL_FOOTER=""
38+
GLOBAL_JIRA_IN_HEADER="${GLOBAL_JIRA_IN_HEADER:-}"
3539

3640
GLOBAL_TYPE=""
3741
GLOBAL_SCOPE=""
@@ -54,6 +58,9 @@ validate_overall_structure() {
5458
if [[ $STATE -eq $WAITING_HEADER ]]; then
5559
GLOBAL_HEADER="$LINE"
5660
STATE="$WAITING_EMPTY"
61+
if [[ -n "${GLOBAL_JIRA_IN_HEADER:-}" ]] && [[ $LINE =~ $JIRA_HEADER_PATTERN ]]; then
62+
GLOBAL_JIRA=${BASH_REMATCH[1]}
63+
fi
5764

5865
elif [[ $STATE -eq $WAITING_EMPTY ]]; then
5966
if [[ $LINE != "" ]]; then

0 commit comments

Comments
 (0)