-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcreate-forks-on-github.sh
More file actions
executable file
·84 lines (71 loc) · 1.87 KB
/
create-forks-on-github.sh
File metadata and controls
executable file
·84 lines (71 loc) · 1.87 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
#!/usr/bin/env bash
# Default settings
PATH_TO_REPOSITORIES="$(dirname "${BASH_SOURCE[0]}")/../../../DiffDetectiveMining"
DRY_RUN=n
# Override settings
#PATH_TO_REPOSITORIES="absolute/path/to/directory/containing/the/respositories"
# uncomment to following line, to actually run th 'gh' commands
#DRY_RUN=n
continue-with() {
echo
read -p "Do you want to continue with $1? [y/N] " answer
[ "$answer" == "y" ]
}
run() {
echo
echo "\$ $*"
if [ "$DRY_RUN" = "n" ]
then
"$@"
fi
}
repos() {
find "$PATH_TO_REPOSITORIES" -mindepth 1 -maxdepth 1 -type d "$@"
}
PATH_TO_REPOSITORIES="$(realpath "$PATH_TO_REPOSITORIES")"
cd "$PATH_TO_REPOSITORIES"
echo "The following repos in '$PATH_TO_REPOSITORIES' will be forked:"
repos
continue-with "these $(repos -print0 | tr -d -c '\0' | tr '\0' '\n' | wc -l) repos" || exit 1
if gh auth status |& grep -q 'You are not logged into any GitHub hosts.' &>/dev/null
then
run gh auth login || exit 1
was_logged_in=0
else
echo
gh auth status
continue-with "this account" ||
{
run gh auth logout &&
run gh auth login || exit 1
}
was_logged_in=1
fi
repos -print0 |
while IFS= read -d '' -r repository
do
echo
run cd "$repository"
url="$(git remote get-url origin)"
if [[ "$url" =~ github.com ]]
then
echo "$repository is a github repo"
run gh repo fork --remote || echo "already forked"
run git push -f origin
else
echo "$repository is not a github repo"
run git remote rename origin upstream &>/dev/null
run gh repo create "DiffDetective/$(basename "$repository")" -d "Fork of $url" --push --public --source .
fi
echo "repo succesful"
done
if [ "$was_logged_in" = "1" ]
then
cat <<EOF
Warning: 'gh' is still logged in, to log out use
gh auth logout
EOF
else
echo
run gh auth logout
fi