-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.mjs
More file actions
257 lines (225 loc) · 9.81 KB
/
main.mjs
File metadata and controls
257 lines (225 loc) · 9.81 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
import {
getRepositoriesFromQueryString,
setGitHubToken,
getGitHubToken,
fetchGitHub,
classifyItem,
fetchRepositoryData,
getContrastColor,
getRepoColor,
showError,
escapeHtml,
formatReactions,
getTotalReactions,
setupCommonUI,
setupAdBanner,
setupLoadButton,
setupAutoLoad,
setupHelpPanel,
setupAnalyticsConsent,
formatMarkdown,
formatDate,
renderIssueDetails
} from './shared.mjs';
// Initialize the application
document.addEventListener('DOMContentLoaded', () => {
setupCommonUI();
setupAdBanner();
setupHelpPanel();
setupAnalyticsConsent();
setupLoadButton((repos) => loadAllRepositories(repos, true));
// Auto-load on page load with initial repos
setupAutoLoad((repos) => loadAllRepositories(repos, true));
// Setup issue detail panel handlers
const iframePanel = document.getElementById('iframePanel');
const detailsContent = document.getElementById('detailsContent');
const detailsLoading = document.getElementById('detailsLoading');
const iframeTitle = document.getElementById('iframeTitle');
const closeIframe = document.getElementById('closeIframe');
closeIframe.addEventListener('click', () => {
iframePanel.classList.remove('open');
detailsContent.innerHTML = '';
});
// Event delegation for issue clicks
document.addEventListener('click', async (e) => {
// Check if clicked on item card or its children
const item = e.target.closest('.item');
if (item) {
e.preventDefault();
const isPR = item.dataset.isPr === 'true';
const issueData = JSON.parse(item.dataset.issue);
// Check if it's a PR - if so, open directly on GitHub
if (isPR) {
window.open(issueData.html_url, '_blank', 'noopener,noreferrer');
return;
}
// For issues, show in detail panel
iframeTitle.textContent = 'Loading...';
iframePanel.classList.add('open');
detailsContent.innerHTML = '';
detailsLoading.style.display = 'block';
try {
await loadIssueDetails(issueData);
} catch (error) {
detailsContent.innerHTML = `<div class="error">Failed to load issue details: ${error.message}</div>`;
} finally {
detailsLoading.style.display = 'none';
}
}
});
});
/**
* Load and display issue details
*/
async function loadIssueDetails(issue) {
const detailsContent = document.getElementById('detailsContent');
const iframeTitle = document.getElementById('iframeTitle');
// No need to fetch comments - we already have the count in issue.comments
renderIssueDetails(issue, issue.html_url, iframeTitle, detailsContent);
}
/**
* Load all repositories and display them
*/
async function loadAllRepositories(repos, openOnly = false) {
const loadingEl = document.getElementById('loading');
const swimlanesEl = document.getElementById('swimlanes');
const errorContainer = document.getElementById('error-container');
// Clear previous data
swimlanesEl.innerHTML = '';
errorContainer.innerHTML = '';
loadingEl.style.display = 'block';
try {
// Fetch all repositories
const results = await Promise.all(
repos.map(repo => fetchRepositoryData(repo, openOnly))
);
loadingEl.style.display = 'none';
// Show errors for failed repositories
const failed = results.filter(r => !r.success);
if (failed.length > 0) {
const errorMessages = failed.map(r => `${r.repo}: ${r.error}`).join('<br>');
showError(`Failed to load some repositories:<br>${errorMessages}`);
}
// Display successful repositories
const successful = results.filter(r => r.success);
if (successful.length === 0) {
swimlanesEl.innerHTML = '<div class="empty-state">No repositories loaded successfully</div>';
return;
}
successful.forEach(repoData => {
renderSwimlane(repoData);
});
} catch (error) {
loadingEl.style.display = 'none';
showError(`Error loading repositories: ${error.message}`);
}
}
/**
* Render a swimlane for a repository
*/
function renderSwimlane(repoData) {
const swimlanesEl = document.getElementById('swimlanes');
const { repo, issues, pullRequests } = repoData;
const swimlane = document.createElement('div');
swimlane.className = 'swimlane collapsed';
// Sort issues by type: bugs, features, tasks, other
// Then by reactions count (descending)
const typeOrder = { bug: 1, feature: 2, task: 3, other: 4 };
const sortedIssues = [...issues].sort((a, b) => {
const typeComparison = (typeOrder[a.type] || 4) - (typeOrder[b.type] || 4);
if (typeComparison !== 0) return typeComparison;
// If same type, sort by reactions count (descending)
return getTotalReactions(b.reactions) - getTotalReactions(a.reactions);
});
const totalIssues = issues.length;
const totalPRs = pullRequests.length;
const bugCount = [...issues, ...pullRequests].filter(item => item.type === 'bug').length;
const featureCount = [...issues, ...pullRequests].filter(item => item.type === 'feature').length;
const taskCount = [...issues, ...pullRequests].filter(item => item.type === 'task').length;
const otherCount = issues.filter(item => item.type === 'other').length;
const prSection = `
<div class="section prs-section">
<div class="section-title">Pull Requests (${totalPRs})</div>
${totalPRs > 0 ? renderItems(pullRequests, true) : '<div class="empty-state">No pull requests found</div>'}
</div>
`;
const [owner, repoName] = repo.split('/');
swimlane.innerHTML = `
<div class="swimlane-header" style="--repo-bg: ${getRepoColor(repo)}; background: var(--repo-bg, transparent); border-radius: 6px; padding: 15px;">
<div class="swimlane-title">
<div class="swimlane-title-main">
<span class="collapse-icon">▼</span>
<span>${repoName}</span>
</div>
<a href="https://github.com/${repo}" target="_blank" rel="noopener noreferrer" class="repo-link">${repo} ↗️</a>
</div>
<div class="swimlane-stats">
<div>
<span>📝 Issues: ${totalIssues}</span>
<span class="${totalPRs > 0 ? 'stat-prs' : ''}">🔀 PRs: ${totalPRs}</span>
</div>
<div>
<span class="${bugCount > 0 ? 'stat-bugs-present' : bugCount === 0 ? 'stat-bugs-none' : ''}">🐛 Bugs: ${bugCount}</span>
<span>✨ Features: ${featureCount}</span>
<span>📋 Tasks: ${taskCount}</span>
<span>❓ Other: ${otherCount}</span>
</div>
</div>
</div>
<div class="swimlane-content">
<div class="section issues-section">
<div class="section-title">Issues (${totalIssues})</div>
${renderItems(sortedIssues, false)}
</div>
${prSection}
</div>
`;
// Add click handler for collapsing
const header = swimlane.querySelector('.swimlane-header');
header.addEventListener('click', () => {
swimlane.classList.toggle('collapsed');
});
swimlanesEl.appendChild(swimlane);
}
/**
* Render a list of items (issues or PRs)
*/
function renderItems(items, isPR = false) {
if (items.length === 0) {
return '<div class="empty-state">No items found</div>';
}
return items.map(item => {
const typeLabel = item.type === 'bug' ? 'bug' :
item.type === 'feature' ? 'feature' :
item.type === 'task' ? 'task' : 'other';
const stateIcon = item.state === 'open' ? '🟢' : '🔴';
const milestone = item.milestone ? `<span class="milestone">🎯 ${escapeHtml(item.milestone.title)}</span>` : '';
const createdDate = formatDate(item.created_at);
const updatedDate = formatDate(item.updated_at);
return `
<div class="item" data-issue='${JSON.stringify(item).replace(/'/g, "'")}' data-is-pr="${isPR}">
<div class="item-header">
<span class="item-number">#${item.number}</span>
<a href="${item.html_url}" class="item-title" target="_blank" rel="noopener noreferrer">
${escapeHtml(item.title)} ↗️
</a>
</div>
<div class="item-meta">
<span class="label label-${typeLabel}">${typeLabel}</span>
<span class="item-state">${stateIcon} ${item.state}</span>
<span class="item-dates">📅 ${createdDate} • 🔄 ${updatedDate}</span>
${milestone}
${item.comments > 0 ? `<span class="interaction-metric" title="comments">💬 ${item.comments}</span>` : ''}
${formatReactions(item.reactions)}
${item.labels.slice(0, 3).map(label => {
const labelName = typeof label === 'string' ? label : label.name;
const labelColor = typeof label === 'object' && label.color ?
`#${label.color}` : '#6e7681';
const textColor = getContrastColor(labelColor);
return `<span class="label" style="--label-bg: ${labelColor}; --label-color: ${textColor}">${escapeHtml(labelName)}</span>`;
}).join('')}
</div>
</div>
`;
}).join('');
}