Skip to content

Commit ad2f611

Browse files
committed
refactor ( #13 ) : pre-commit
1 parent 1b6f54d commit ad2f611

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

.github/hooks/pre-commit

100644100755
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
#!/bin/bash
22

3-
# 커밋 메시지 유효성 검증
4-
commit_msg=$(cat "$1")
5-
regex="^(feat|fix|chore|docs|style|refactor|test|perf|ci|build|revert) \([[:space:]]*#[[:space:]]*[0-9]+[[:space:]]*\) : .+$"
3+
# Git 디렉토리 위치
4+
git_dir=$(git rev-parse --git-dir 2>/dev/null) || { echo "❌ Git 저장소만 지원한다."; exit 1; }
5+
6+
# 방금 작성된 커밋 메시지 읽기
7+
commit_msg="$(< "$git_dir/COMMIT_EDITMSG")"
8+
9+
# 메시지 패턴 정의
10+
regex="^(feat|fix|chore|docs|style|refactor|test|perf|ci|build|revert) *\([[:space:]]*#[[:space:]]*[0-9]+[[:space:]]*\) *: .+$"
611

712
if [[ "$commit_msg" =~ $regex ]]; then
8-
echo "✅ 커밋 메시지 형식이 올바릅니다."
13+
echo "✅ 커밋 메시지 형식이 올바릅니다."
914
else
10-
echo "❌ 커밋 메시지 형식이 잘못되었습니다."
11-
exit 1
12-
fi
13-
14-
# Git 루트 디렉토리 찾기
15-
if ! repo_root=$(git rev-parse --show-toplevel 2>/dev/null); then
16-
echo "❌ Git 루트 디렉토리를 찾을 수 없습니다. Git 저장소 안에서 실행해주세요."
17-
exit 1
15+
echo "❌ 커밋 메시지 형식이 잘못되었습니다."
16+
echo " 형식: 타입(#이슈번호) : 설명"
17+
exit 1
1818
fi
1919

20-
cd "$repo_root" || exit 1
21-
22-
# Gradle 빌드 검증
20+
# 기존에 하던 Gradle 빌드 검증도 이어서 실행
2321
echo "Gradle 빌드 검증 시작..."
2422
if ! ./gradlew clean build --no-daemon; then
25-
echo "❌ 빌드 실패! 커밋이 중단됩니다."
26-
exit 1
23+
echo "❌ 빌드 실패! 커밋 중단."
24+
exit 1
2725
else
28-
echo "✅ 빌드 성공! 커밋 계속 진행합니다."
29-
exit 0
30-
fi
26+
echo "✅ 빌드 성공! 커밋 계속."
27+
exit 0
28+
fi

0 commit comments

Comments
 (0)