Skip to content

Commit

Permalink
Refactor: githooks 修整
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi committed Jul 10, 2022
1 parent 2db84e5 commit 53672a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
22 changes: 11 additions & 11 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@

. "$(dirname "$0")/_/husky.sh"

if [ $3 -ne 1 ]; then
if [ "$3" -ne 1 ]; then
exit 0
fi

function die(){
local STATUS=$?
echo $1 >&2
exit $STATUS
die(){
_die_STATUS=$?
echo "$1" >&2
exit $_die_STATUS
}

if !(type gh > /dev/null 2>&1); then
if ! (type gh > /dev/null 2>&1); then
exit 0
fi

BRANCH=$(git rev-parse --abbrev-ref HEAD)

if [[ "${BRANCH}" =~ ^(HEAD|main|develop)$ ]]; then
exit 0
fi
case "${BRANCH}" in
HEAD|main|develop) exit 0;
esac

ISSUES=$(echo "${BRANCH}" | grep -oE '#[0-9]+' | tr -d '#' | sort -nr || :)

if [[ ! ${ISSUES[@]} ]]; then
if [ -z "$ISSUES" ]; then
die "💡 issue が連携されていません。"
fi

for issue in $ISSUES; do
gh --repo uchikoshi-fes/uchikoshi-fes.jp-2022 issue view $issue || die "🚨 issue $issue を見つけられませんでした。[uchikoshi-fes/uchikoshi-fes.jp-2022]"
gh --repo uchikoshi-fes/uchikoshi-fes.jp-2022 issue view "$issue" || die "🚨 issue $issue を見つけられませんでした。[uchikoshi-fes/uchikoshi-fes.jp-2022]"
done
19 changes: 9 additions & 10 deletions .husky/post-index-change
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

. "$(dirname "$0")/_/husky.sh"

if [ $2 -eq 1 ]; then
if [ "$2" -eq 1 ]; then
exit 0
fi

PACKAGE_FILE_REGEX="^(package\.json|pnpm-lock\.yaml)"
PACKAGES="$(git diff --cached --name-only | grep -E "$PACKAGE_FILE_REGEX" || :)"
if [[ ${PACKAGES[@]} ]]; then
echo "📦 $(echo $PACKAGES | tr '\n' ' ')が変更されました。pnpm install を実行します..."
pnpm install --frozen-lockfile && :
if [ $? -ne 0 ]; then
echo "🚨 pnpm install に失敗しました。restore を実行します..."
git restore --staged .
exit 1
fi
else
if [ -z "$PACKAGES" ]; then
echo "🧊 依存関係は変更されていません。"
exit 0
fi
echo "📦 $(echo "$PACKAGES" | tr '\n' ' ')が変更されました。pnpm install を実行します..."
if ! pnpm install --frozen-lockfile; then
echo "🚨 pnpm install に失敗しました。restore を実行します..."
git restore --staged .
exit 1
fi

0 comments on commit 53672a6

Please sign in to comment.