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
40
41
41
42
CURL_RES=$( ${CURL} -s \
42
43
-H " Accept: application/vnd.github.v3+json" \
43
- https://api.github.com/repos/${ACCOUNT} /lab0-c /actions/workflows)
44
+ https://api.github.com/repos/${ACCOUNT} /${REPO_NAME} /actions/workflows)
44
45
45
46
TOTAL_COUNT=$( echo ${CURL_RES} | sed -e ' s/.*"total_count": \([^,"]*\).*/\1/' )
46
47
case ${TOTAL_COUNT} in
47
48
* " Not Found" * )
48
- throw " Check your repository. It should be located at https://github.com/${ACCOUNT} /lab0-c "
49
+ throw " Check your repository. It should be located at https://github.com/${ACCOUNT} /${REPO_NAME} "
49
50
esac
50
51
51
52
# 3. Ensure this repository is frok from sysprog21/lab0-c'.
52
53
(( CURRENT_STEP++ ))
53
54
progress " $CURRENT_STEP " " $TOTAL_STEPS "
54
55
55
56
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
57
+ RESPONSE =$( ${CURL} -s -H " Accept: application/vnd.github.v3+json " \
58
+ " https://api .github.com/repos/ ${ACCOUNT} / ${REPO_NAME} " )
59
+
60
+ IS_FORK= $( echo " $RESPONSE " | sed -n ' s/.*"fork": \(true\|false\).*/\1/p ' | head -n1 )
61
+ PARENT_NAME= $( echo " $RESPONSE " | awk -F ' " ' ' /"parent": \{/{flag=1} flag && /"full_name":/{print $4; exit} ' )
62
+
63
+ if [[ " $IS_FORK " != " true " || " $PARENT_NAME " != " sysprog21/lab0-c " ]] ; then
64
+ throw " Your repository MUST be forked from 'sysprog21/lab0-c'."
65
+ fi
65
66
fi
66
67
67
68
# 4. Check GitHub Actions
@@ -72,13 +73,13 @@ if [ ${TOTAL_COUNT} -eq "0" ]; then
72
73
printf " \n[!] GitHub Actions MUST be activated."
73
74
case ${OSTYPE} in
74
75
" linux" * )
75
- xdg-open https://github.com/${ACCOUNT} /lab0-c /actions > /dev/null 2>&1
76
+ xdg-open https://github.com/${ACCOUNT} /${REPO_NAME} /actions > /dev/null 2>&1
76
77
;;
77
78
" darwin" * )
78
- open https://github.com/${ACCOUNT} /lab0-c /actions
79
+ open https://github.com/${ACCOUNT} /${REPO_NAME} /actions
79
80
;;
80
81
* )
81
- echo " Please activate at https://github.com/${ACCOUNT} /lab0-c /actions"
82
+ echo " Please activate at https://github.com/${ACCOUNT} /${REPO_NAME} /actions"
82
83
;;
83
84
esac
84
85
throw " Check this article: https://docs.github.com/en/actions/managing-workflow-runs/disabling-and-enabling-a-workflow\n\
0 commit comments