-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpl.sh
More file actions
117 lines (99 loc) · 3.44 KB
/
gpl.sh
File metadata and controls
117 lines (99 loc) · 3.44 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
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
set -euo pipefail
IGNORE_ORG=meshtastic
GITHUB_USER=
GITHUB_TOKEN=
# https://github.com/settings/tokens
# -----------------------------------------------------------------------------
# fetch_search_array <kind> <query> <outfile>
#
# kind = "commits" or "code"
# query = the GitHub search query (no URL-encoding)
# outfile = path to write the JSON array to
#
# Uses the GitHub API to page through all hits, streams each item
# into jq, then writes a single JSON array. Skips if <outfile> exists.
# -----------------------------------------------------------------------------
fetch_search_array() {
local kind="$1"
local query="$2"
local outfile="$3"
# pick the right API path and Accept header
local path accept
if [[ "$kind" == "commits" ]]; then
path="search/commits"
accept="application/vnd.github.cloak-preview"
else
path="search/code"
accept="application/vnd.github.v3+json"
fi
if [[ -f "$outfile" ]]; then
echo "$outfile exists; skipping."
return
fi
echo "Searching for $kind that contain $query"
local page=1
# stream each ".items[]" from every page
(
while :; do
resp=$(curl -s \
-H "Accept: $accept" \
-u "$GITHUB_USER:$GITHUB_TOKEN" \
"https://api.github.com/$path?q=${query// /+}+-org:${IGNORE_ORG}&per_page=100&page=$page")
local count
count=$(jq '.items | length' <<<"$resp")
(( count == 0 )) && break
jq -c '.items[]' <<<"$resp"
((page++))
done
) | jq -s '.' > "$outfile"
echo "Wrote $outfile (total items: $(jq length "$outfile"))"
}
fetch_search_array commits "meshtastic/protobufs" commits_array.json
fetch_search_array code "Meshtastic.Protobufs" results_array.json
fetch_search_array code "Config.LoRaConfig.ModemPreset" modempreset_array.json
fetch_search_array code "Config.LoRaConfig.RegionCode" regioncode_array.json
fetch_search_array code "proto::meshtastic" protomeshtastic_array.json
fetch_search_array code "protobufs/meshtastic" protobufsmeshtastic_array.json
# —————————————
# Extract, sort & dedupe repos
# —————————————
jq -r '.[].repository.full_name' \
commits_array.json \
results_array.json \
modempreset_array.json \
regioncode_array.json \
protomeshtastic_array.json \
protobufsmeshtastic_array.json \
| sort -u > repos.txt
echo "Found $(wc -l < repos.txt) unique repos"
mkdir -p licenses
while read -r repo; do
license_file="licenses/${repo//\//_}.json"
# only fetch if we haven't already
if [[ ! -e "$license_file" ]]; then
printf "\rFetching license for %-50s" "$repo" >/dev/tty
http_code=$(
curl -s -w '%{http_code}' \
-H "Accept: application/vnd.github.v3+json" \
-u "$GITHUB_USER:$GITHUB_TOKEN" \
"https://api.github.com/repos/$repo/license" \
-o "$license_file"
)
if [[ "$http_code" == "404" ]]; then
# no license file → record NONE
echo '{"license":null}' > "$license_file"
fi
else
printf "\rSkipping %-50s" "$repo" >/dev/tty
fi
done < repos.txt
printf "\r%65s" >/dev/tty
echo ""
# extract spdx_id (or “null”)
jq -r '.license.spdx_id // "NONE"' licenses/*.json > all_spdx.txt
# list repos that are NOT GPL v3, including “NONE”
paste repos.txt all_spdx.txt \
| awk '$2 !~ /^GPL-3\.0(-only|-or-later)?$/ {
printf("https://github.com/%s has license: %s\n", $1, $2)
}'