Skip to content

Commit 5c8c201

Browse files
committed
feat(jira): make jira types an option
1 parent 833c0d2 commit 5c8c201

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

validator.bats

+8-8
Original file line numberDiff line numberDiff line change
@@ -499,23 +499,23 @@ LUM-2345'
499499
}
500500

501501
@test "features and fixes commits need jira reference" {
502-
[[ `need_jira "feat"` -eq 1 ]]
503-
[[ `need_jira "fix"` -eq 1 ]]
502+
need_jira "feat"
503+
need_jira "fix"
504504
}
505505

506506
@test "features and fixes commits need jira reference if env empty" {
507-
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "feat"` -eq 1 ]]
508-
[[ `COMMIT_VALIDATOR_NO_JIRA= need_jira "fix"` -eq 1 ]]
507+
COMMIT_VALIDATOR_NO_JIRA= need_jira "feat"
508+
COMMIT_VALIDATOR_NO_JIRA= need_jira "fix"
509509
}
510510

511511
@test "features and fixes commits don't need jira reference if env non empty" {
512-
[[ `COMMIT_VALIDATOR_NO_JIRA=1 need_jira "feat"` -eq 0 ]]
513-
[[ `COMMIT_VALIDATOR_NO_JIRA=1 need_jira "fix"` -eq 0 ]]
512+
! COMMIT_VALIDATOR_NO_JIRA=1 need_jira "feat"
513+
! COMMIT_VALIDATOR_NO_JIRA=1 need_jira "fix"
514514
}
515515

516516
@test "other commits don't need jira reference" {
517-
[[ `need_jira "docs"` -eq 0 ]]
518-
[[ `need_jira "test"` -eq 0 ]]
517+
! need_jira "docs"
518+
! need_jira "test"
519519
}
520520

521521
@test "feat without jira ref should be rejected" {

validator.sh

+11-12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ readonly ERROR_REVERT=10
2929
GLOBAL_HEADER=""
3030
GLOBAL_BODY=""
3131
GLOBAL_JIRA=""
32+
GLOBAL_JIRA_TYPES="${GLOBAL_JIRA_TYPES:-feat fix}"
3233
GLOBAL_FOOTER=""
3334

3435
GLOBAL_TYPE=""
@@ -212,26 +213,24 @@ need_jira() {
212213
local TYPE=$1
213214

214215
if [[ ! -z "${COMMIT_VALIDATOR_NO_JIRA:-}" ]]; then
215-
echo 0
216+
return 1
216217
else
217-
case $TYPE in
218-
feat)
219-
echo 1
220-
;;
221-
fix)
222-
echo 1
223-
;;
224-
*)
225-
echo 0
226-
esac
218+
for type in ${GLOBAL_JIRA_TYPES}; do
219+
if [[ "${TYPE}" == "${type}" ]]; then
220+
return 0
221+
fi
222+
done
223+
return 1
227224
fi
228225
}
229226

230227
validate_jira() {
231228
local TYPE=$1
232229
local JIRA=$2
233230

234-
if [[ "$(need_jira "$TYPE")" -eq "1" && -z "${JIRA:-}" ]]; then
231+
232+
233+
if need_jira "$TYPE" && [[ -z "${JIRA:-}" ]]; then
235234
echo -e "commits with type '${TYPE}' need to include a reference to a JIRA ticket, by adding the project prefix and the issue number to the commit message, this could be done easily with: git commit -m 'feat(widget): add a wonderful widget' -m LUM-1234"
236235
exit $ERROR_JIRA
237236
fi

0 commit comments

Comments
 (0)