Skip to content

Commit 1368330

Browse files
committed
refactor: disable fetch milestone
1 parent cde8b16 commit 1368330

File tree

4 files changed

+69
-126
lines changed

4 files changed

+69
-126
lines changed

README.org

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#+TITLE: Zig Milestone Monitor
22
#+DATE: 2024-03-28T21:12:54+0800
3-
#+LASTMOD: 2024-04-18T21:56:25+0800
3+
#+LASTMOD: 2025-11-20T08:58:30+0800
44
#+AUTHOR: Jiacai Liu
55

66
[[https://github.com/zigcc/zig-milestone/actions/workflows/ci.yml][https://github.com/zigcc/zig-milestone/actions/workflows/ci.yml/badge.svg]]
@@ -49,6 +49,7 @@ CREATE TABLE IF NOT EXISTS repo_histories (
4949
#+end_src
5050

5151
* Note
52+
- Only track stars/forks/watchers for the Zig repo since 2024-11-20.
5253
- All metrics are collected since 2024-03-28.
5354
* License
5455
MIT

app.mjs

Lines changed: 66 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/usr/bin/env node
22

33
import { createClient } from "@libsql/client";
4-
import ejs from 'ejs';
5-
import fs from 'fs';
4+
import ejs from "ejs";
5+
import fs from "fs";
66

77
const client = createClient({
88
url: process.env.TURSO_DB_URL ?? "file:./zig-milestone.db",
99
authToken: process.env.TURSO_TOKEN,
1010
});
1111
const GITHUB_HEADERS = {
1212
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
13-
Accept: 'application/json',
13+
Accept: "application/json",
1414
};
1515

1616
async function initDatabase() {
17-
let sqls = fs.readFileSync('schema.sql', 'utf8').split(';');
17+
let sqls = fs.readFileSync("schema.sql", "utf8").split(";");
1818
sqls = sqls.filter((sql) => sql.trim().length > 0);
1919
console.log(sqls, sqls.length);
20-
const ret = await client.batch(sqls, 'write');
20+
const ret = await client.batch(sqls, "write");
2121
console.log(ret);
2222
}
2323

@@ -47,16 +47,16 @@ query {
4747
}
4848
}
4949
`;
50-
const r = await fetch('https://api.github.com/graphql', {
51-
method: 'POST',
50+
const r = await fetch("https://api.github.com/graphql", {
51+
method: "POST",
5252
headers: GITHUB_HEADERS,
53-
body: JSON.stringify({query: graphql})
53+
body: JSON.stringify({ query: graphql }),
5454
});
55-
if(!r.ok) {
55+
if (!r.ok) {
5656
throw new Error(await r.text());
5757
}
5858
const body = JSON.parse(await r.text());
59-
const repoInfo = await body['data']['repository'];
59+
const repoInfo = await body["data"]["repository"];
6060
const sqlRet = await client.execute({
6161
sql: `
6262
INSERT INTO repo_histories (
@@ -74,30 +74,33 @@ INSERT INTO repo_histories (
7474
`,
7575
args: [
7676
Date.now(),
77-
repoInfo['forkCount'],
78-
repoInfo['stargazerCount'],
79-
repoInfo['watchers']['totalCount'],
80-
repoInfo['openPulls']['totalCount'],
81-
repoInfo['closedPulls']['totalCount'],
82-
repoInfo['mergedPulls']['totalCount'],
83-
repoInfo['openIssues']['totalCount'],
84-
repoInfo['closedIssues']['totalCount'],
77+
repoInfo["forkCount"],
78+
repoInfo["stargazerCount"],
79+
repoInfo["watchers"]["totalCount"],
80+
repoInfo["openPulls"]["totalCount"],
81+
repoInfo["closedPulls"]["totalCount"],
82+
repoInfo["mergedPulls"]["totalCount"],
83+
repoInfo["openIssues"]["totalCount"],
84+
repoInfo["closedIssues"]["totalCount"],
8585
],
8686
});
8787
console.log(`insert repo history result`, sqlRet);
8888
}
8989

9090
async function fetchMilestoneHistories() {
9191
const result = await client.execute(
92-
"select id from milestones where state = 'open'"
92+
"select id from milestones where state = 'open'",
9393
);
9494
const now = Date.now();
9595
let firstErr = null;
9696
for (const row of result.rows) {
97-
const mid = row['id'];
98-
const resp = await fetch(`https://api.github.com/repos/ziglang/zig/milestones/${mid}`, {
99-
headers: GITHUB_HEADERS,
100-
});
97+
const mid = row["id"];
98+
const resp = await fetch(
99+
`https://api.github.com/repos/ziglang/zig/milestones/${mid}`,
100+
{
101+
headers: GITHUB_HEADERS,
102+
},
103+
);
101104
const milestone = await resp.json();
102105
try {
103106
const r = await client.execute({
@@ -108,8 +111,8 @@ INSERT INTO milestone_histories (created_at, mid, open_issues, closed_issues)
108111
args: {
109112
created_at: now,
110113
mid: mid,
111-
open_issues: milestone['open_issues'],
112-
closed_issues: milestone['closed_issues'],
114+
open_issues: milestone["open_issues"],
115+
closed_issues: milestone["closed_issues"],
113116
},
114117
});
115118
console.log(`insert milestone history`, r);
@@ -128,15 +131,16 @@ INSERT INTO milestone_histories (created_at, mid, open_issues, closed_issues)
128131

129132
async function fetchMilestones() {
130133
// https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28
131-
const url = 'https://api.github.com/repos/ziglang/zig/milestones?state=all&per_page=100';
134+
const url =
135+
"https://api.github.com/repos/ziglang/zig/milestones?state=all&per_page=100";
132136
const resp = await fetch(url, {
133137
headers: GITHUB_HEADERS,
134138
});
135139
if (!resp.ok) {
136140
throw new Error(await resp.text());
137141
}
138142
const milestones = await resp.json();
139-
for(const m of milestones) {
143+
for (const m of milestones) {
140144
const r = await client.execute({
141145
sql: `
142146
INSERT INTO milestones (id, created_at, updated_at, state, title, description)
@@ -146,26 +150,20 @@ ON CONFLICT (id)
146150
updated_at = excluded.updated_at, state = excluded.state, title = excluded.title, description = excluded.description
147151
`,
148152
args: {
149-
id: m['number'],
150-
created_at: m['created_at'],
151-
updated_at: m['updated_at'],
152-
state: m['state'],
153-
title: m['title'],
154-
description: m['description'],
153+
id: m["number"],
154+
created_at: m["created_at"],
155+
updated_at: m["updated_at"],
156+
state: m["state"],
157+
title: m["title"],
158+
description: m["description"],
155159
},
156160
});
157161
console.log(`insert milestone result`, r);
158162
}
159163
}
160164

161165
async function GenerateHtml() {
162-
const fileOpts = { 'encoding': 'utf8', 'flags': 'w' };
163-
const idToTitle = {
164-
'19': '0.15.0',
165-
'20': '0.14.0',
166-
'23': '0.12.0',
167-
'25': '0.13.0',
168-
};
166+
const fileOpts = { encoding: "utf8", flags: "w" };
169167
let repoHistories = [];
170168
{
171169
const rs = await client.execute(
@@ -185,78 +183,47 @@ FROM
185183
ORDER BY
186184
created_at desc
187185
limit 1000
188-
`
186+
`,
189187
);
190188
for (const row of rs.rows) {
191189
repoHistories.push([
192-
row['created_at'],
193-
row['forks'],
194-
row['stars'],
195-
row['watchers'],
196-
row['open_pulls'],
197-
row['closed_pulls'],
198-
row['merged_pulls'],
199-
row['open_issues'],
200-
row['closed_issues'],
190+
row["created_at"],
191+
row["forks"],
192+
row["stars"],
193+
row["watchers"],
194+
row["open_pulls"],
195+
row["closed_pulls"],
196+
row["merged_pulls"],
197+
row["open_issues"],
198+
row["closed_issues"],
201199
]);
202200
}
203201
}
204202

205-
const idsToShow = [
206-
// '25', // 0.13.0
207-
// '23', // 0.12.0
208-
// '20', // '0.14.0',
209-
'19', // '0.15.0',
210-
];
211-
212-
const sqls = idsToShow.map((id) => {
213-
return { sql: `
214-
SELECT
215-
created_at,
216-
open_issues,
217-
closed_issues
218-
FROM
219-
milestone_histories
220-
where mid = ?
221-
ORDER BY
222-
created_at desc
223-
limit 1000
224-
`, args: [id] };
225-
});
226-
const histories = await client.batch(sqls, 'read');
227-
let historiesById = {}; // id -> [[timestamp, open, closed], ...]
228-
idsToShow.forEach((id, idx) => {
229-
historiesById[id] = histories[idx].rows.map((row) =>
230-
[row['created_at'], row['open_issues'], row['closed_issues']]);
231-
});
232203
let tmpl = fs.readFileSync(`template.ejs`, fileOpts);
233204
let body = ejs.render(tmpl, {
234-
now: new Date().toLocaleString('en-GB'),
235-
historiesById: historiesById,
236-
historiesByIdStr: JSON.stringify(historiesById),
205+
now: new Date().toLocaleString("en-GB"),
237206
repoHistoriesStr: JSON.stringify(repoHistories),
238-
idToTitle: idToTitle,
239-
idsToShow: idsToShow,
240207
});
241-
fs.writeFileSync('web/raw.html', body, fileOpts);
208+
fs.writeFileSync("web/raw.html", body, fileOpts);
242209
}
243210

244211
const args = process.argv.slice(2);
245212
const cmd = args[0];
246-
switch(cmd) {
247-
case 'fetch-history':
248-
await fetchRepoHistories();
249-
await fetchMilestoneHistories();
250-
break;
251-
case 'fetch-milestone':
252-
await fetchMilestones();
253-
break;
254-
case 'gen-html':
255-
await GenerateHtml();
256-
break;
257-
case 'init-db':
258-
await initDatabase();
259-
break;
260-
default:
261-
console.error("unknown cmd", cmd);
213+
switch (cmd) {
214+
case "fetch-history":
215+
await fetchRepoHistories();
216+
// await fetchMilestoneHistories();
217+
break;
218+
case "fetch-milestone":
219+
await fetchMilestones();
220+
break;
221+
case "gen-html":
222+
await GenerateHtml();
223+
break;
224+
case "init-db":
225+
await initDatabase();
226+
break;
227+
default:
228+
console.error("unknown cmd", cmd);
262229
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zig-milestone",
33
"version": "1.0.0",
4-
"description": "",
4+
"description": "Fetch Zig milestone and generate HTML report",
55
"main": "db.mjs",
66
"scripts": {
77
"init-db": "./app.mjs init-db",

template.ejs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
<link rel="stylesheet" href="https://unpkg.com/magick.css">
1111
<link rel="stylesheet" href="app.css">
1212
<script>
13-
const historiesById = <%- historiesByIdStr %>;
1413
const repoHistories = <%- repoHistoriesStr %>;
1514
window.onload = function() {
1615
const charts = [
1716
renderRepoChart(repoHistories, "repo-chart"),
18-
<% for(const id of idsToShow) { %>
19-
renderMilestoneChart(historiesById, <%= id %>),
20-
<% } %>
2117
];
2218
window.addEventListener('resize', (event) => {
2319
charts.forEach((chart) => {
@@ -33,27 +29,6 @@
3329
<h1><a href="https://github.com/ziglang/zig/milestones">Zig Milestone</a> Monitor</h1>
3430
<h3><a href="https://github.com/ziglang/zig">Zig repository</a></h3>
3531
<div class="chart" id="repo-chart"></div>
36-
<% for(const id of idsToShow) { %>
37-
<section>
38-
<h3><a href="https://github.com/ziglang/zig/milestone/<%= id %>"><%= idToTitle[id] %></a></h3>
39-
<div class="chart" id="chart-<%= id %>"></div>
40-
<table>
41-
<caption>Latest 10 histories</caption>
42-
<tr>
43-
<th>Date</th>
44-
<th>Open issues</th>
45-
<th>Closed issues</th>
46-
</tr>
47-
<% for(const row of historiesById[id].slice(0, 10)) { %>
48-
<tr>
49-
<td><%= new Date(row[0]).toLocaleString('en-GB') %></td>
50-
<td><%= row[1] %></td>
51-
<td><%= row[2] %></td>
52-
</tr>
53-
<% } %>
54-
</table>
55-
</section>
56-
<% } %>
5732

5833
<footer> &copy; 2024 - 2025 <a href="https://ziglang.cc">ZigCC</a>
5934
| <a href="https://github.com/zigcc/zig-milestone">GitHub</a>

0 commit comments

Comments
 (0)