-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.sh
More file actions
executable file
·75 lines (63 loc) · 2.21 KB
/
Copy pathmain.sh
File metadata and controls
executable file
·75 lines (63 loc) · 2.21 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
#!/bin/bash
all_stars_file=$(mktemp)
in_lists_file=$(mktemp)
trap 'rm "$all_stars_file" "$in_lists_file"' EXIT
error() { echo -e "\033[31m$1\033[0m"; }
info() { echo -e "\033[34m$1\033[0m"; }
success() { echo -e "\033[32m$1\033[0m"; }
warn() { echo -e "\033[33m$1\033[0m"; }
# Check for gh
if ! command -v gh &>/dev/null; then
error "Error: 'gh' is not installed."
exit 1
fi
# Check if gh is authenticated and can reach the GitHub API
if ! gh auth status &>/dev/null; then
error "Error: 'gh' is not authenticated or cannot reach the GitHub API."
info "Please run 'gh auth login' to set up your credentials."
exit 1
fi
info "Fetching ALL stars (Takes some time if a lot of stars)"
gh api /user/starred --paginate --jq '.[].html_url' >>$all_stars_file
success "Found $(wc -l <"$all_stars_file") total stars."
info "Finding stars in GitHub Lists"
lists=$(gh api graphql -f query='{
viewer {
lists(first: 100) {
nodes {
name
items(first: 100) {
nodes {
... on Repository {
url
}
}
}
}
}
}
}')
echo "$lists" | jq -r '.data.viewer.lists.nodes[] | "\(.name):::\(.items.nodes[].url)"' >"$in_lists_file"
if [[ -s "$in_lists_file" ]]; then
# Extract unique list names in their original order
awk -F':::' '!seen[$1]++ {print $1}' "$in_lists_file" | while IFS= read -r list_name; do
info "\n[$list_name]"
# Filter and format repos for the current list
awk -F':::' -v list="$list_name" '$1 == list {print $2}' "$in_lists_file"
done
else
echo "No repositories found in selected lists."
fi
info "\n----------------------------------"
info "REPOS STARRED BUT NOT IN ANY LIST:"
info "----------------------------------"
# Sort and deduplicate the files
sort -u "$all_stars_file" -o "$all_stars_file"
awk -F':::' '{print $2}' "$in_lists_file" | sort -u -o "$in_lists_file"
# Show items in 'all_stars' that are NOT in 'in_lists'
results=$(comm -23 "$all_stars_file" "$in_lists_file")
if [[ -z "$results" ]]; then
info "Everything is organized! No unlisted stars found."
else
echo "$results"
fi