31
31
(( CURRENT_STEP++ ))
32
32
progress " $CURRENT_STEP " " $TOTAL_STEPS "
33
33
34
- ACCOUNT=$( git config -l | grep -w remote.origin.url | sed -e ' s/^.*github.com[\/:]\(.*\)\/lab0-c.*/\1/' )
34
+ ACCOUNT=$( git config --get remote.origin.url | awk -F' [:/]' ' {print $(NF-1)}' )
35
+ REPO_NAME=$( git config --get remote.origin.url | awk -F' [:/]' ' {gsub(/\.git$/, "", $NF); print $NF}' )
35
36
36
37
CURL=$( which curl)
37
38
if [ $? -ne 0 ]; then
@@ -43,25 +44,24 @@ CURL_RES=$(${CURL} -s \
43
44
https://api.github.com/repos/${ACCOUNT} /lab0-c/actions/workflows)
44
45
45
46
TOTAL_COUNT=$( echo ${CURL_RES} | sed -e ' s/.*"total_count": \([^,"]*\).*/\1/' )
46
- case ${TOTAL_COUNT} in
47
- * " Not Found" * )
48
- throw " Check your repository. It should be located at https://github.com/${ACCOUNT} /lab0-c"
49
- esac
47
+ if [[ " $REPO_NAME " != " lab0-c" || " $TOTAL_COUNT " == * " Not Found" * ]]; then
48
+ throw " Check your repository. It should be located at https://github.com/${ACCOUNT} /lab0-c"
49
+ fi
50
50
51
51
# 3. Ensure this repository is frok from sysprog21/lab0-c'.
52
52
(( CURRENT_STEP++ ))
53
53
progress " $CURRENT_STEP " " $TOTAL_STEPS "
54
54
55
55
if [[ " ${ACCOUNT} " != " sysprog21" ]]; then
56
- REPO_FORKED =$( ${CURL} -s \
57
- -H " Accept: application/vnd .github.v3+json " \
58
- https://api.github.com/repos/ ${ACCOUNT} /lab0-c | grep -m 1 fork )
59
- case ${REPO_FORKED} in
60
- * true * )
61
- ;;
62
- * )
63
- throw " Your repository MUST be forked from 'sysprog21/lab0-c'."
64
- esac
56
+ RESPONSE =$( ${CURL} -s -H " Accept: application/vnd.github.v3+json " \
57
+ " https://api .github.com/repos/ ${ACCOUNT} /lab0-c " )
58
+
59
+ IS_FORK= $( echo " $RESPONSE " | sed -n ' s/.*"fork": \(true\|false\).*/\1/p ' | head -n1 )
60
+ PARENT_NAME= $( echo " $RESPONSE " | awk -F ' " ' ' /"parent": \{/{flag=1} flag && /"full_name":/{print $4; exit} ' )
61
+
62
+ if [[ " $IS_FORK " != " true " || " $PARENT_NAME " != " sysprog21/lab0-c " ]] ; then
63
+ throw " Your repository MUST be forked from 'sysprog21/lab0-c'."
64
+ fi
65
65
fi
66
66
67
67
# 4. Check GitHub Actions
0 commit comments