-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
256 lines (214 loc) · 9.36 KB
/
script.js
File metadata and controls
256 lines (214 loc) · 9.36 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
// Configuration
const DATA_URL = 'data/dashboard-data.json';
const STALENESS_THRESHOLD_DAYS = 45;
// Utility: Format date as relative time
function timeAgo(isoDateString) {
if (!isoDateString) return 'Never';
const date = new Date(isoDateString);
const now = new Date();
const diffMs = now - date;
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
if (diffDays === 0) return 'Today';
if (diffDays === 1) return '1 day ago';
if (diffDays < 30) return diffDays + ' days ago';
const diffMonths = Math.floor(diffDays / 30);
if (diffMonths === 1) return '1 month ago';
if (diffMonths < 12) return diffMonths + ' months ago';
const diffYears = Math.floor(diffDays / 365);
if (diffYears === 1) return '1 year ago';
return diffYears + ' years ago';
}
// Utility: Format date as human-readable
function formatDate(isoDateString) {
if (!isoDateString) return 'Never';
const date = new Date(isoDateString);
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric'
});
}
// Create HTML for a single ingest card
function createIngestCard(ingest) {
const card = document.createElement('div');
card.className = 'ingest-card ' + ingest.status;
// Status badge
const badge = document.createElement('div');
badge.className = 'status-badge ' + ingest.status;
badge.title = ingest.status.charAt(0).toUpperCase() + ingest.status.slice(1);
// Ingest name (linked to repo)
const name = document.createElement('div');
name.className = 'ingest-name';
const nameLink = document.createElement('a');
nameLink.href = ingest.repo_url;
nameLink.target = '_blank';
nameLink.textContent = ingest.name;
name.appendChild(nameLink);
// Add Koza 2 badge if applicable
if (ingest.koza_version === '2') {
const versionBadge = document.createElement('span');
versionBadge.className = 'version-badge';
versionBadge.textContent = 'koza 2';
name.appendChild(versionBadge);
}
// Details container
const details = document.createElement('div');
details.className = 'ingest-details';
// Release info
const releaseRow = document.createElement('div');
releaseRow.className = 'detail-row';
const releaseLabel = document.createElement('div');
releaseLabel.className = 'detail-label';
releaseLabel.textContent = 'Latest Release';
const releaseValue = document.createElement('div');
releaseValue.className = 'detail-value';
if (ingest.last_release) {
const releaseLink = document.createElement('a');
releaseLink.href = ingest.last_release.url;
releaseLink.target = '_blank';
releaseLink.textContent = ingest.last_release.tag;
releaseValue.appendChild(releaseLink);
const releaseTime = document.createElement('span');
releaseTime.className = 'time-ago';
releaseTime.textContent = timeAgo(ingest.last_release.date);
releaseValue.appendChild(releaseTime);
} else {
const noRelease = document.createElement('span');
noRelease.style.color = 'var(--text-secondary)';
noRelease.textContent = 'No releases';
releaseValue.appendChild(noRelease);
}
releaseRow.appendChild(releaseLabel);
releaseRow.appendChild(releaseValue);
// Workflow info
const workflowRow = document.createElement('div');
workflowRow.className = 'detail-row';
const workflowLabel = document.createElement('div');
workflowLabel.className = 'detail-label';
workflowLabel.textContent = 'Last Workflow Run';
const workflowValue = document.createElement('div');
workflowValue.className = 'detail-value';
if (ingest.last_workflow_run) {
const workflowLink = document.createElement('a');
workflowLink.href = ingest.last_workflow_run.url;
workflowLink.target = '_blank';
workflowLink.textContent = 'View run';
workflowValue.appendChild(workflowLink);
const conclusion = ingest.last_workflow_run.conclusion || 'unknown';
const conclusionBadge = document.createElement('span');
conclusionBadge.className = 'conclusion-badge ' + conclusion;
conclusionBadge.textContent = conclusion;
workflowValue.appendChild(conclusionBadge);
const workflowTime = document.createElement('span');
workflowTime.className = 'time-ago';
workflowTime.textContent = timeAgo(ingest.last_workflow_run.date);
workflowValue.appendChild(workflowTime);
} else {
const noWorkflow = document.createElement('span');
noWorkflow.style.color = 'var(--text-secondary)';
noWorkflow.textContent = 'No workflow runs';
workflowValue.appendChild(noWorkflow);
}
workflowRow.appendChild(workflowLabel);
workflowRow.appendChild(workflowValue);
// Template status row
var templateRow = null;
if (ingest.template_status) {
templateRow = document.createElement('div');
templateRow.className = 'detail-row';
var templateLabel = document.createElement('div');
templateLabel.className = 'detail-label';
templateLabel.textContent = 'Template';
var templateValue = document.createElement('div');
templateValue.className = 'detail-value';
var behind = ingest.template_status.commits_behind;
if (behind === null || behind === undefined) {
var unknownSpan = document.createElement('span');
unknownSpan.style.color = 'var(--text-secondary)';
unknownSpan.textContent = 'Unknown';
templateValue.appendChild(unknownSpan);
} else if (behind === 0) {
var upToDate = document.createElement('span');
upToDate.className = 'template-badge up-to-date';
upToDate.textContent = 'up to date';
templateValue.appendChild(upToDate);
} else {
var behindBadge = document.createElement('span');
behindBadge.className = 'template-badge behind';
if (behind >= 4) {
behindBadge.classList.add('behind-far');
}
behindBadge.textContent = behind + ' commit' + (behind === 1 ? '' : 's') + ' behind';
templateValue.appendChild(behindBadge);
}
templateRow.appendChild(templateLabel);
templateRow.appendChild(templateValue);
}
// Assemble card
details.appendChild(releaseRow);
details.appendChild(workflowRow);
if (templateRow) {
details.appendChild(templateRow);
}
card.appendChild(badge);
card.appendChild(name);
card.appendChild(details);
return card;
}
// Render the dashboard
function renderDashboard(data) {
// Update last updated timestamp
const lastUpdatedEl = document.getElementById('last-updated');
lastUpdatedEl.textContent = 'Last updated: ' + formatDate(data.last_updated) + ' (' + timeAgo(data.last_updated) + ')';
// Calculate summary stats
const healthy = data.ingests.filter(function(i) { return i.status === 'healthy'; }).length;
const stale = data.ingests.filter(function(i) { return i.status === 'stale'; }).length;
const failed = data.ingests.filter(function(i) { return i.status === 'failed'; }).length;
var templateBehind = data.ingests.filter(function(i) {
return i.template_status && i.template_status.commits_behind > 0;
}).length;
const summaryEl = document.getElementById('summary');
summaryEl.innerHTML = '<span class="healthy">' + healthy + ' healthy</span>' +
'<span class="stale">' + stale + ' stale</span>' +
'<span class="failed">' + failed + ' failed</span>' +
'<span class="template-behind">' + templateBehind + ' template behind</span>';
// Render ingest cards
const dashboardEl = document.getElementById('dashboard');
dashboardEl.innerHTML = ''; // Clear loading message
// Sort: failed first, then stale, then healthy, then alphabetically within each group
const statusOrder = { 'failed': 0, 'stale': 1, 'healthy': 2 };
const sortedIngests = data.ingests.sort(function(a, b) {
if (statusOrder[a.status] !== statusOrder[b.status]) {
return statusOrder[a.status] - statusOrder[b.status];
}
return a.name.localeCompare(b.name);
});
sortedIngests.forEach(function(ingest) {
const card = createIngestCard(ingest);
dashboardEl.appendChild(card);
});
}
// Load and render dashboard data
function loadDashboard() {
fetch(DATA_URL)
.then(function(response) {
if (!response.ok) {
throw new Error('HTTP error! status: ' + response.status);
}
return response.json();
})
.then(function(data) {
renderDashboard(data);
})
.catch(function(error) {
console.error('Error loading dashboard data:', error);
const dashboardEl = document.getElementById('dashboard');
dashboardEl.innerHTML = '<div class="loading">Error loading dashboard data. Please try refreshing the page.</div>';
});
}
// Initialize dashboard when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', loadDashboard);
} else {
loadDashboard();
}