-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_json.sh
executable file
路139 lines (114 loc) 路 4.17 KB
/
gen_json.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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
cd "$(dirname "$0")"
DELAY=180
# Start fresh
if [[ -f tmp.db ]]; then
rm tmp.db
fi
curl \
https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml \
| yq '[to_entries[] | {lang: .key, color: .value.color}]' \
| sqlite-utils insert tmp.db linguist -
sleep $DELAY
gh api --paginate \
-H "Accept: application/vnd.github.mercy-preview+json" \
'https://api.github.com/users/cljoly/repos?page=1&sort=pushed' \
| jq -s 'flatten(1)' \
| sqlite-utils insert tmp.db repo -
sleep $DELAY
gh api --paginate \
-H "Accept: application/vnd.github.mercy-preview+json" \
-q '.items' \
'https://api.github.com/search/issues?q=type:pr+author:cljoly' \
| jq -s 'flatten(1)' \
| sqlite-utils insert tmp.db prs -
echo "data retrieved"
sqlite-utils create-view tmp.db topic "SELECT DISTINCT \
repo.rowid as rid, json_each.value as t \
FROM repo, json_each(topics)"
sqlite-utils create-view tmp.db featured_repo "SELECT DISTINCT \
repo.rowid AS rowid, private, pushed_at, name, html_url, topics, description, \
stargazers_count, homepage, archived, language, color \
FROM repo \
JOIN linguist ON lang = repo.language \
WHERE \
(fork <> 1 OR rowid IN (SELECT rid FROM topic WHERE t = 'maintained-fork')) \
AND stargazers_count > 0 AND rowid NOT IN (SELECT rid FROM topic WHERE t = 'internal') \
AND private == 0"
echo "views created"
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
* \
FROM featured_repo \
WHERE rowid NOT IN (SELECT rid FROM topic WHERE t = 'archived') \
AND rowid NOT IN (SELECT rid FROM topic WHERE t = 'wip') \
AND archived == 0 \
ORDER BY pushed_at DESC" > unarchived_repos.json
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
* \
FROM featured_repo \
WHERE rowid NOT IN (SELECT rid FROM topic WHERE t = 'archived') \
AND rowid NOT IN (SELECT rid FROM topic WHERE t = 'wip') \
AND archived == 0 \
ORDER BY stargazers_count DESC" > unarchived_most_stars_repos.json
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
* \
FROM featured_repo \
WHERE rowid IN (SELECT rid FROM topic WHERE t = 'archived') \
OR archived == 1 \
ORDER BY pushed_at DESC" > archived_repos.json
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
* \
FROM featured_repo \
WHERE rowid IN (SELECT rid FROM topic WHERE t = 'wip') \
AND archived == 0 \
ORDER BY pushed_at DESC" > wip_repos.json
# -------
# Special requests
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
* \
FROM featured_repo \
WHERE rowid NOT IN (SELECT rid FROM topic WHERE t = 'archived') \
AND rowid NOT IN (SELECT rid FROM topic WHERE t = 'wip') \
AND rowid IN (SELECT rid FROM topic WHERE t = 'neovim-plugin') \
AND archived == 0 \
ORDER BY stargazers_count DESC" > unarchived_nvim_most_stars_repos.json
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
* \
FROM featured_repo \
WHERE rowid IN (SELECT rid FROM topic WHERE t = 'wip') \
AND rowid IN (SELECT rid FROM topic WHERE t = 'neovim-plugin') \
AND archived == 0 \
ORDER BY pushed_at DESC" > wip_nvim_repos.json
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
* \
FROM featured_repo \
WHERE rowid IN (SELECT rid FROM topic WHERE t = 'hugo-module') \
AND archived == 0 \
ORDER BY pushed_at DESC" > hugo_modules_repos.json
# -------
sqlite-utils create-view tmp.db featured_prs "SELECT DISTINCT \
created_at, title, html_url, state, repository_url \
FROM prs \
WHERE author_association <> 'OWNER' \
AND title NOT LIKE '%typo%' \
AND html_url NOT LIKE '%/joly122u/%' \
AND created_at > '2018-12-31T00:00:00Z' \
ORDER BY created_at DESC"
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
created_at, title, html_url, state \
FROM featured_prs \
ORDER BY created_at DESC" > prs.json
sqlite-utils query tmp.db --json-cols "SELECT DISTINCT \
'https://github.com/' || substr(repository_url, 30) as repo_url, COUNT(*) pr_count \
FROM featured_prs \
GROUP BY repository_url \
ORDER BY pr_count DESC" > contributed_repos.json
# =========
curl 'https://webmention.io/api/mentions.jf2?target=https://cj.rs'>webmentions.json
echo "JSONs created"