-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfips_timeline_tracker.py
More file actions
531 lines (451 loc) · 17.3 KB
/
Copy pathfips_timeline_tracker.py
File metadata and controls
531 lines (451 loc) · 17.3 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#!/usr/bin/env python3
"""
Script to track FIP status changes month-on-month using GitHub commit history
"""
import urllib.request
import base64
import json
import re
from collections import defaultdict
from datetime import datetime, timedelta
from typing import Dict, List, Tuple
from fip_utils import get_status_class, parse_fip_table, html_escape, make_github_request
GITHUB_API_BASE = 'https://api.github.com/repos/filecoin-project/FIPs'
README_PATH = 'README.md'
def fetch_commits_since_date(since_date: str = None):
"""Fetch commits to README.md since a given date"""
url = f"{GITHUB_API_BASE}/commits?path={README_PATH}&per_page=100"
if since_date:
url += f"&since={since_date}"
try:
return make_github_request(url)
except Exception as e:
print(f"Error fetching commits: {e}")
return []
def get_readme_at_commit(sha: str):
"""Get README content at a specific commit"""
url = f"{GITHUB_API_BASE}/contents/{README_PATH}?ref={sha}"
try:
content = make_github_request(url)
return base64.b64decode(content['content']).decode('utf-8')
except Exception as e:
print(f"Error fetching README at commit {sha}: {e}")
return None
def parse_fips_from_text(text: str):
"""Parse FIPs from README text, returning a dict keyed by FIP number."""
return {fip['number']: fip for fip in parse_fip_table(text)}
def get_monthly_snapshots():
"""Get monthly snapshots of FIP statuses"""
# Get commits from the last 12 months
since_date = (datetime.now() - timedelta(days=365)).isoformat()
commits = fetch_commits_since_date(since_date)
if not commits:
print("No commits found, fetching current version...")
# Fallback: just get current version
try:
with urllib.request.urlopen(f"https://raw.githubusercontent.com/filecoin-project/FIPs/master/{README_PATH}") as response:
text = response.read().decode('utf-8')
fips = parse_fips_from_text(text)
return {datetime.now().strftime('%Y-%m'): fips}
except Exception as e:
print(f"Error: {e}")
return {}
# Group commits by month
monthly_commits = defaultdict(list)
for commit in commits:
commit_date = datetime.fromisoformat(commit['commit']['committer']['date'].replace('Z', '+00:00'))
month_key = commit_date.strftime('%Y-%m')
monthly_commits[month_key].append({
'sha': commit['sha'],
'date': commit_date,
'message': commit['commit']['message']
})
# For each month, get the latest commit's README
monthly_snapshots = {}
for month, month_commits in sorted(monthly_commits.items()):
# Use the latest commit of the month
latest_commit = max(month_commits, key=lambda x: x['date'])
print(f"Fetching snapshot for {month} (commit {latest_commit['sha'][:7]})...")
readme_text = get_readme_at_commit(latest_commit['sha'])
if readme_text:
fips = parse_fips_from_text(readme_text)
monthly_snapshots[month] = {
'fips': fips,
'date': latest_commit['date'],
'commit': latest_commit['sha'][:7]
}
# Also get current version
try:
with urllib.request.urlopen(f"https://raw.githubusercontent.com/filecoin-project/FIPs/master/{README_PATH}") as response:
text = response.read().decode('utf-8')
fips = parse_fips_from_text(text)
current_month = datetime.now().strftime('%Y-%m')
if current_month not in monthly_snapshots:
monthly_snapshots[current_month] = {
'fips': fips,
'date': datetime.now(),
'commit': 'HEAD'
}
except Exception as e:
print(f"Error fetching current version: {e}")
return monthly_snapshots
def track_status_changes(monthly_snapshots: Dict):
"""Track status changes between months"""
changes = []
sorted_months = sorted(monthly_snapshots.keys())
for i in range(len(sorted_months)):
month = sorted_months[i]
fips = monthly_snapshots[month]['fips']
if i == 0:
# First month - all FIPs are "new" or initial status
continue
prev_month = sorted_months[i-1]
prev_fips = monthly_snapshots[prev_month]['fips']
month_changes = {
'month': month,
'date': monthly_snapshots[month]['date'],
'new_fips': [],
'status_changes': [],
'removed_fips': []
}
# Check for new FIPs
for fip_num, fip_data in fips.items():
if fip_num not in prev_fips:
month_changes['new_fips'].append({
'number': fip_num,
'title': fip_data['title'],
'status': fip_data['status']
})
elif prev_fips[fip_num]['status'] != fip_data['status']:
month_changes['status_changes'].append({
'number': fip_num,
'title': fip_data['title'],
'from': prev_fips[fip_num]['status'],
'to': fip_data['status']
})
# Check for removed FIPs (shouldn't happen, but track anyway)
for fip_num in prev_fips:
if fip_num not in fips:
month_changes['removed_fips'].append({
'number': fip_num,
'title': prev_fips[fip_num]['title'],
'status': prev_fips[fip_num]['status']
})
if month_changes['new_fips'] or month_changes['status_changes'] or month_changes['removed_fips']:
changes.append(month_changes)
return changes, sorted_months
def generate_timeline_html(monthly_snapshots: Dict, changes: List, sorted_months: List):
"""Generate HTML dashboard with timeline view"""
# Generate timeline HTML
timeline_html = []
for change in changes:
month_date = change['date'].strftime('%B %Y') if isinstance(change['date'], datetime) else change['month']
change_items = []
if change['new_fips']:
for fip in change['new_fips']:
change_items.append(f'''
<div class="change-item new">
<span class="change-icon">➕</span>
<span class="change-text">
<strong>New:</strong> <a href="https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-{fip['number']}.md" target="_blank">FIP-{fip['number']}</a> - {html_escape(fip['title'][:60])}{'...' if len(fip['title']) > 60 else ''}
<span class="status-badge {get_status_class(fip['status'])}">{fip['status']}</span>
</span>
</div>''')
if change['status_changes']:
for fip in change['status_changes']:
change_items.append(f'''
<div class="change-item status-change">
<span class="change-icon">🔄</span>
<span class="change-text">
<strong>Status Change:</strong> <a href="https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-{fip['number']}.md" target="_blank">FIP-{fip['number']}</a> - {html_escape(fip['title'][:50])}{'...' if len(fip['title']) > 50 else ''}
<span class="status-change-arrow">{fip['from']} → {fip['to']}</span>
</span>
</div>''')
if change['removed_fips']:
for fip in change['removed_fips']:
change_items.append(f'''
<div class="change-item removed">
<span class="change-icon">➖</span>
<span class="change-text">
<strong>Removed:</strong> FIP-{fip['number']} - {html_escape(fip['title'][:60])}{'...' if len(fip['title']) > 60 else ''}
</span>
</div>''')
if change_items:
timeline_html.append(f'''
<div class="timeline-month">
<div class="timeline-header">
<h3>{month_date}</h3>
<span class="change-count">{len(change['new_fips']) + len(change['status_changes']) + len(change['removed_fips'])} changes</span>
</div>
<div class="timeline-changes">
{''.join(change_items)}
</div>
</div>''')
# Generate current status summary
current_month = sorted_months[-1] if sorted_months else datetime.now().strftime('%Y-%m')
current_fips = monthly_snapshots[current_month]['fips'] if current_month in monthly_snapshots else {}
status_summary = defaultdict(int)
for fip in current_fips.values():
status_summary[fip['status']] += 1
summary_html = '<div class="status-summary-grid">'
for status, count in sorted(status_summary.items(), key=lambda x: x[1], reverse=True):
summary_html += f'''
<div class="summary-card">
<div class="summary-status {get_status_class(status)}">{status}</div>
<div class="summary-count">{count}</div>
</div>'''
summary_html += '</div>'
html = f'''<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FIP Status Timeline Tracker</title>
<style>
* {{
margin: 0;
padding: 0;
box-sizing: border-box;
}}
body {{
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}}
.container {{
max-width: 1400px;
margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
overflow: hidden;
}}
.header {{
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
color: white;
padding: 30px;
text-align: center;
}}
.header h1 {{
font-size: 2.5em;
margin-bottom: 10px;
}}
.header p {{
opacity: 0.9;
font-size: 1.1em;
}}
.content {{
padding: 30px;
}}
.section {{
margin-bottom: 40px;
}}
.section h2 {{
color: #333;
margin-bottom: 20px;
font-size: 1.8em;
border-bottom: 3px solid #667eea;
padding-bottom: 10px;
}}
.status-summary-grid {{
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 15px;
margin-bottom: 30px;
}}
.summary-card {{
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
text-align: center;
border: 2px solid #e0e0e0;
}}
.summary-status {{
font-size: 0.85em;
font-weight: 600;
margin-bottom: 8px;
padding: 4px 8px;
border-radius: 4px;
display: inline-block;
}}
.summary-count {{
font-size: 2em;
font-weight: 700;
color: #667eea;
}}
.timeline {{
position: relative;
padding-left: 30px;
}}
.timeline::before {{
content: '';
position: absolute;
left: 10px;
top: 0;
bottom: 0;
width: 2px;
background: #667eea;
}}
.timeline-month {{
position: relative;
margin-bottom: 30px;
padding-left: 30px;
}}
.timeline-month::before {{
content: '';
position: absolute;
left: 2px;
top: 10px;
width: 16px;
height: 16px;
border-radius: 50%;
background: #667eea;
border: 3px solid white;
box-shadow: 0 0 0 2px #667eea;
}}
.timeline-header {{
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}}
.timeline-header h3 {{
color: #333;
font-size: 1.4em;
}}
.change-count {{
background: #667eea;
color: white;
padding: 4px 12px;
border-radius: 12px;
font-size: 0.9em;
font-weight: 600;
}}
.timeline-changes {{
background: #f8f9fa;
border-radius: 8px;
padding: 15px;
}}
.change-item {{
padding: 10px;
margin-bottom: 8px;
border-radius: 6px;
display: flex;
align-items: flex-start;
gap: 10px;
}}
.change-item.new {{
background: #d4edda;
border-left: 4px solid #28a745;
}}
.change-item.status-change {{
background: #fff3cd;
border-left: 4px solid #ffc107;
}}
.change-item.removed {{
background: #f8d7da;
border-left: 4px solid #dc3545;
}}
.change-icon {{
font-size: 1.2em;
}}
.change-text {{
flex: 1;
line-height: 1.6;
}}
.change-text a {{
color: #667eea;
text-decoration: none;
font-weight: 600;
}}
.change-text a:hover {{
text-decoration: underline;
}}
.status-badge {{
display: inline-block;
padding: 4px 8px;
border-radius: 12px;
font-size: 0.75em;
font-weight: 600;
margin-left: 8px;
}}
.status-final {{ background: #d4edda; color: #155724; }}
.status-draft {{ background: #fff3cd; color: #856404; }}
.status-accepted {{ background: #cce5ff; color: #004085; }}
.status-deferred {{ background: #ffeaa7; color: #856404; }}
.status-rejected {{ background: #f8d7da; color: #721c24; }}
.status-withdrawn {{ background: #e2e3e5; color: #383d41; }}
.status-active {{ background: #d1ecf1; color: #0c5460; }}
.status-last-call {{ background: #f0ad4e; color: #fff; }}
.status-superseded {{ background: #e7e7e7; color: #555; }}
.status-change-arrow {{
display: inline-block;
margin-left: 8px;
padding: 2px 8px;
background: white;
border-radius: 4px;
font-size: 0.85em;
font-weight: 600;
}}
.no-changes {{
text-align: center;
padding: 40px;
color: #666;
font-style: italic;
}}
.last-updated {{
text-align: center;
padding: 20px;
color: #666;
font-size: 0.9em;
}}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>📅 FIP Status Timeline Tracker</h1>
<p>Month-on-Month Status Change Tracking</p>
</div>
<div class="content">
<div class="section">
<h2>Current Status Summary</h2>
{summary_html}
</div>
<div class="section">
<h2>Status Changes Timeline</h2>
<div class="timeline">
{''.join(timeline_html) if timeline_html else '<div class="no-changes">No status changes tracked yet. Historical data will appear here as FIPs change status over time.</div>'}
</div>
</div>
</div>
<div class="last-updated">
Last updated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
</div>
</div>
</body>
</html>'''
return html
def main():
print("Fetching monthly snapshots from GitHub...")
monthly_snapshots = get_monthly_snapshots()
if not monthly_snapshots:
print("Failed to fetch snapshots")
return
print(f"Found snapshots for {len(monthly_snapshots)} month(s)")
print("Tracking status changes...")
changes, sorted_months = track_status_changes(monthly_snapshots)
print(f"Found {len(changes)} months with changes")
if sorted_months and len(monthly_snapshots[sorted_months[-1]]['fips']) == 0:
print("Error: Latest month has 0 FIPs. Aborting.")
return
print("Generating timeline HTML...")
html = generate_timeline_html(monthly_snapshots, changes, sorted_months)
output_file = 'fips-timeline-tracker.html'
with open(output_file, 'w', encoding='utf-8') as f:
f.write(html)
print(f"Timeline tracker generated successfully: {output_file}")
print(f"Open {output_file} in your browser to view the timeline")
if __name__ == '__main__':
main()