-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
github-issue.html
268 lines (252 loc) · 9.08 KB
/
github-issue.html
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
<!DOCTYPE html>
<html>
<head>
<title>GitHub Issue Viewer</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 0 20px;
}
.container {
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
}
.input-group {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.token-group {
margin-bottom: 20px;
}
input {
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
.url-input {
flex: 1;
}
.token-input {
width: 100%;
max-width: 360px;
}
button {
padding: 8px 16px;
background: #0366d6;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
.error {
background: #ffebe9;
border: 1px solid #ff8182;
color: #cf222e;
padding: 10px;
border-radius: 4px;
margin-bottom: 20px;
display: none;
}
pre {
background: #f6f8fa;
padding: 16px;
border-radius: 4px;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
margin-bottom: 16px;
}
.loading {
display: none;
margin: 20px 0;
color: #666;
}
.copy-button {
display: none;
margin-top: 10px;
}
label {
display: block;
margin-bottom: 8px;
color: #444;
}
.token-help {
font-size: 14px;
color: #666;
margin-top: 4px;
}
</style>
</head>
<body>
<div class="container">
<div class="token-group">
<label for="tokenInput">GitHub Personal Access Token (optional)</label>
<input
type="password"
id="tokenInput"
placeholder="ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
class="token-input">
<div class="token-help">Token will be saved in your browser for future use</div>
</div>
<div class="input-group">
<input type="text" id="urlInput" placeholder="Enter GitHub issue URL" class="url-input">
<button id="fetchButton">Fetch Issue</button>
</div>
<div id="error" class="error"></div>
<div id="loading" class="loading">Loading...</div>
<pre id="output"></pre>
<button id="copyButton" class="copy-button">Copy to clipboard</button>
</div>
<script>
const urlInput = document.getElementById('urlInput');
const tokenInput = document.getElementById('tokenInput');
const fetchButton = document.getElementById('fetchButton');
const errorDiv = document.getElementById('error');
const loadingDiv = document.getElementById('loading');
const output = document.getElementById('output');
const copyButton = document.getElementById('copyButton');
// Load token from localStorage on page load
document.addEventListener('DOMContentLoaded', () => {
const savedToken = localStorage.getItem('githubToken');
if (savedToken) {
tokenInput.value = savedToken;
}
});
// Save token to localStorage when it changes
tokenInput.addEventListener('input', () => {
const token = tokenInput.value.trim();
if (token) {
localStorage.setItem('githubToken', token);
} else {
localStorage.removeItem('githubToken');
}
});
function convertUrlToApi(githubUrl) {
const match = githubUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\/issues\/(\d+)/);
if (!match) throw new Error('Invalid GitHub issue URL');
const [_, owner, repo, issue] = match;
return {
issueUrl: `https://api.github.com/repos/${owner}/${repo}/issues/${issue}`,
commentsUrl: `https://api.github.com/repos/${owner}/${repo}/issues/${issue}/comments`
};
}
function formatDate(dateString) {
return new Date(dateString)
.toISOString()
.replace('T', ' ')
.replace('Z', ' UTC');
}
function getRequestHeaders() {
const headers = {
'Accept': 'application/vnd.github.v3+json'
};
const token = tokenInput.value.trim();
if (token) {
headers['Authorization'] = `token ${token}`;
}
return headers;
}
function copyToClipboard() {
const text = output.textContent;
navigator.clipboard.writeText(text).then(() => {
const originalText = copyButton.textContent;
copyButton.textContent = 'Copied!';
copyButton.disabled = true;
setTimeout(() => {
copyButton.textContent = originalText;
copyButton.disabled = false;
}, 1500);
});
}
function fetchIssueData(inputUrl) {
errorDiv.style.display = 'none';
loadingDiv.style.display = 'block';
output.textContent = '';
copyButton.style.display = 'none';
fetchButton.disabled = true;
let apiUrls;
try {
apiUrls = convertUrlToApi(inputUrl);
} catch (err) {
errorDiv.textContent = err.message;
errorDiv.style.display = 'block';
loadingDiv.style.display = 'none';
fetchButton.disabled = false;
return;
}
const headers = getRequestHeaders();
// Fetch issue data
fetch(apiUrls.issueUrl, { headers })
.then(response => {
if (!response.ok) {
if (response.status === 401) {
throw new Error('Invalid GitHub token');
} else if (response.status === 403) {
throw new Error('Rate limit exceeded. Try adding a GitHub token');
} else if (response.status === 404) {
throw new Error('Issue not found or private repository');
}
throw new Error('Failed to fetch issue');
}
return response.json();
})
.then(issue => {
// Build markdown
let md = `# ${issue.title}\n\n`;
md += `**State:** ${issue.state}\n`;
md += `**Created by:** ${issue.user.login}\n`;
md += `**Created at:** ${formatDate(issue.created_at)}\n\n`;
md += `${issue.body}\n\n`;
// Fetch comments
return fetch(apiUrls.commentsUrl, { headers })
.then(response => {
if (!response.ok) throw new Error('Failed to fetch comments');
return response.json();
})
.then(comments => {
// Add comments to markdown
if (comments.length > 0) {
md += `## Comments\n\n`;
comments.forEach(comment => {
md += `### Comment by ${comment.user.login} at ${formatDate(comment.created_at)}\n\n`;
md += `${comment.body}\n\n`;
});
}
return md;
});
})
.then(markdown => {
output.textContent = markdown;
copyButton.style.display = 'block';
})
.catch(err => {
errorDiv.textContent = err.message;
errorDiv.style.display = 'block';
})
.finally(() => {
loadingDiv.style.display = 'none';
fetchButton.disabled = false;
});
}
fetchButton.addEventListener('click', () => {
fetchIssueData(urlInput.value);
});
urlInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
fetchIssueData(urlInput.value);
}
});
copyButton.addEventListener('click', copyToClipboard);
</script>
</body>
</html>