Skip to content

Commit

Permalink
Improve git hook installer
Browse files Browse the repository at this point in the history
Before installing git hooks, ensure this repository is forked from
sysprog21/lab0-c properly.
  • Loading branch information
jserv committed Feb 4, 2023
1 parent 577b1a1 commit 85df7d6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion scripts/install-git-hooks
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ fi

ACCOUNT=$(git config -l | grep -w remote.origin.url | sed -e 's/^.*github.com[\/:]\(.*\)\/lab0-c.*/\1/')

CURL_RES=$(curl -s \
CURL=$(which curl)
if [ $? -ne 0 ]; then
echo "[!] curl not installed." >&2
exit 1
fi

CURL_RES=$(${CURL} -s \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${ACCOUNT}/lab0-c/actions/workflows)

Expand All @@ -18,8 +24,22 @@ case ${TOTAL_COUNT} in
exit 1
esac

if [[ "${ACCOUNT}" != "sysprog21" ]]; then
REPO_FORKED=$(${CURL} -s \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${ACCOUNT}/lab0-c | grep -m 1 fork)
case ${REPO_FORKED} in
*true*)
;;
*)
echo "Your repository MUST be forked from sysprog21/lab0-c"
exit 1
esac
fi

if [ ${TOTAL_COUNT} -eq "0" ]; then
echo "Fatal: GitHub Actions MUST be activated."
open https://github.com/${ACCOUNT}/lab0-c/actions
echo "Check this article: https://docs.github.com/en/actions/managing-workflow-runs/disabling-and-enabling-a-workflow"
echo "Then, execute 'make' again."
exit 1
Expand Down

0 comments on commit 85df7d6

Please sign in to comment.