-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathforked-repos
More file actions
executable file
·105 lines (94 loc) · 3.29 KB
/
forked-repos
File metadata and controls
executable file
·105 lines (94 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
echo "This script will add remotes for any of the HeliosLang repos you have forked."
[[ -f .fork-config ]] || {
echo
echo "ERROR: No .fork-config found." >&2
echo >&2
echo "Copy .fork-config.example to .fork-config and update your details there." >&2
exit 1
}
source ./.fork-config
source ./functions.sh
[[ -z $FORK_ORIGIN_NAME ]] && {
echo "FORK_ORIGIN_NAME is unset. Skipping fork setup."
exit 0
}
addRemote() {
WITH_PREFIX=${REPO_PREPEND}${REPO}
USER_REPO_P=${GITHUB_USERNAME}/${WITH_PREFIX}
USER_REPO=${GITHUB_USERNAME}/${REPO}
{
git remote | grep ${FORK_ORIGIN_NAME} >/dev/null && {
echo -e "git remote '${FORK_ORIGIN_NAME}' ${GREEN}already exists${NC}. Skipping..."
return
}
GITHUB_AUTHZ="--header \"Authorization: Bearer $GITHUB_TOKEN\""
[[ -z $GITHUB_TOKEN ]] && {
GITHUB_AUTHZ=""
}
echo "Checking for fork at https://api.github.com/repos/${USER_REPO_P}"
FOUND=$(
curl --silent --fail-with-body $GITHUB_AUTHZ \
"https://api.github.com/repos/${USER_REPO_P}"
)
RESULT=$?
# echo "RESULT: $RESULT"
# echo "FOUND: $FOUND"
echo "$FOUND" | grep "rate limit" >/dev/null && {
echo "Github API rate limit exceeded. Exiting..." >&2
exit 42
}
[[ $RESULT -ne 0 || -z $FOUND ]] || {
REPO_PARENT_FOUND=$(
echo "${FOUND}" | jq -r ".parent.full_name"
)
USER_REPO_FOUND="$USER_REPO_P"
if [[ "${REPO_PARENT_FOUND}" == "HeliosLang/${REPO}" ]] ; then
echo -e "${GREEN}Found your fork${NC} at https://github.com/${USER_REPO_P}"
REPO_FOUND="${USER_REPO_P}"
else
echo "${USER_REPO_P} is not a fork of HeliosLang/${REPO}. Skipping..."
FOUND=""
fi
}
[[ $RESULT -ne 0 || -z $FOUND ]] && {
echo "trying without prefix"
FOUND=$(
curl --silent --fail "https://api.github.com/repos/${USER_REPO}"
)
[[ $? -ne 0 || -z $FOUND ]] && {
echo "No fork found at https://github.com/${USER_REPO_P}"
echo -e " ... not at ${USER_REPO} either. ${YELLOW}Skipping${NC}..."
echo
return
}
REPO_PARENT_FOUND=$(
echo "${FOUND}" | jq -r ".parent.full_name"
)
if [[ "${REPO_PARENT_FOUND}" == "HeliosLang/${REPO}" ]] ; then
echo "Found your fork of HeliosLang/${REPO} at https://github.com/${USER_REPO}"
REPO_FOUND="${USER_REPO}"
else
echo "${USER_REPO} is not a fork of HeliosLang/${REPO}. Skipping..."
echo
return
fi
}
read -p "Add remote for ${REPO_FOUND}? [Y/n] " -e -iY ADD_REMOTE
[[ "${ADD_REMOTE}" != "Y" ]] && {
echo "Skipping add remote for ${REPO_FOUND} ..."
echo
return
}
echo git remote add -m main -f ${FORK_ORIGIN_NAME} "git@github.com:${REPO_FOUND}"
git remote add -m main -f ${FORK_ORIGIN_NAME} "git@github.com:${REPO_FOUND}"
echo
} > >(labeledOutput $LABEL)
}
eachRepo "adding remotes for your forks" addRemote
summarizeFork() {
git remote | grep ${FORK_ORIGIN_NAME} >/dev/null && {
echo " ✅ remote '${FORK_ORIGIN_NAME}' in ${DIR}/"
}
}
eachRepo "summarizing your remotes" summarizeFork