-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_all_gh_repos_private.sh
executable file
·52 lines (45 loc) · 1.21 KB
/
make_all_gh_repos_private.sh
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
#!/bin/bash
# Function to check for required tools
check_tools() {
required_tools=("gh" "jq")
for tool in "${required_tools[@]}"; do
if ! command -v "$tool" &> /dev/null && [[ ! -x "$tool" ]]; then
echo "Error: $tool is not installed, not in your PATH, or not executable."
exit 1
fi
done
}
# Step 1: Ensure required tools are installed
check_tools
# Step 2: Fetch all public repositories
echo "Fetching all public repositories..."
public_repos=$(gh api graphql -f query='
query {
viewer {
repositories(first: 100, privacy: PUBLIC, isFork: false) {
nodes {
name
owner {
login
}
url
}
pageInfo {
hasNextPage
endCursor
}
}
}
}' | jq -c '.data.viewer.repositories.nodes[]')
if [ -z "$public_repos" ]; then
echo "No public repositories found or failed to fetch repositories."
exit 0
fi
# Step 3: Iterate over the repositories and prompt for each one
echo "Processing repositories..."
for repo in $public_repos; do
repo_url=$(echo "$repo" | jq -r '.url')
# Call the existing make_repo_private.sh script for each repository
./make_gh_repo_private.sh "$repo_url"
done
echo "Finished processing repositories."