hale-commenting-system 2.2.97 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GITHUB_OAUTH_ENV_TEMPLATE.md +2 -2
- package/README.md +10 -1
- package/package.json +16 -9
- package/scripts/integrate.js +64 -430
- package/src/app/commenting-system/components/CommentOverlay.tsx +4 -3
- package/src/app/commenting-system/components/CommentPanel.tsx +11 -64
- package/src/app/commenting-system/components/FloatingWidget.tsx +105 -39
- package/src/app/commenting-system/contexts/CommentContext.tsx +11 -4
- package/src/app/commenting-system/types/index.ts +1 -0
- package/.claude/settings.local.json +0 -7
- package/.editorconfig +0 -17
- package/.eslintrc.js +0 -75
- package/.prettierignore +0 -1
- package/.prettierrc +0 -4
- package/src/app/AppLayout/AppLayout.tsx +0 -248
- package/src/app/Comments/Comments.tsx +0 -273
- package/src/app/Dashboard/Dashboard.tsx +0 -10
- package/src/app/NotFound/NotFound.tsx +0 -35
- package/src/app/Settings/General/GeneralSettings.tsx +0 -16
- package/src/app/Settings/Profile/ProfileSettings.tsx +0 -18
- package/src/app/Support/Support.tsx +0 -50
- package/src/app/app.css +0 -11
- package/src/app/bgimages/Patternfly-Logo.svg +0 -28
- package/src/app/index.tsx +0 -22
- package/src/app/routes.tsx +0 -81
- package/src/app/utils/useDocumentTitle.ts +0 -13
- package/src/favicon.png +0 -0
- package/src/index.html +0 -18
- package/src/index.tsx +0 -25
- package/src/test/setup.ts +0 -33
- package/src/typings.d.ts +0 -12
- package/stylePaths.js +0 -14
- package/tsconfig.json +0 -34
- package/vitest.config.ts +0 -19
- package/webpack.common.js +0 -139
- package/webpack.dev.js +0 -318
- package/webpack.prod.js +0 -38
package/webpack.dev.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { merge } = require('webpack-merge');
|
|
5
|
-
const common = require('./webpack.common.js');
|
|
6
|
-
const { stylePaths } = require('./stylePaths');
|
|
7
|
-
const HOST = process.env.HOST || 'localhost';
|
|
8
|
-
const PORT = process.env.PORT || '9000';
|
|
9
|
-
|
|
10
|
-
module.exports = merge(common('development'), {
|
|
11
|
-
mode: 'development',
|
|
12
|
-
devtool: 'eval-source-map',
|
|
13
|
-
devServer: {
|
|
14
|
-
host: HOST,
|
|
15
|
-
port: PORT,
|
|
16
|
-
historyApiFallback: true,
|
|
17
|
-
open: true,
|
|
18
|
-
static: {
|
|
19
|
-
directory: path.resolve(__dirname, 'dist'),
|
|
20
|
-
},
|
|
21
|
-
client: {
|
|
22
|
-
overlay: true,
|
|
23
|
-
},
|
|
24
|
-
setupMiddlewares: (middlewares, devServer) => {
|
|
25
|
-
if (!devServer || !devServer.app) {
|
|
26
|
-
return middlewares;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Load env vars for local OAuth/token exchange without bundling secrets into the client.
|
|
30
|
-
// `.env` is for client-safe values (e.g. VITE_GITHUB_CLIENT_ID, owner/repo).
|
|
31
|
-
// `.env.server` is for server-only secrets (e.g. GITHUB_CLIENT_SECRET).
|
|
32
|
-
try {
|
|
33
|
-
// eslint-disable-next-line global-require
|
|
34
|
-
const dotenv = require('dotenv');
|
|
35
|
-
dotenv.config({ path: path.resolve(__dirname, '.env') });
|
|
36
|
-
// IMPORTANT: allow server-only secrets to override anything accidentally present in `.env` or the shell env.
|
|
37
|
-
dotenv.config({ path: path.resolve(__dirname, '.env.server'), override: true });
|
|
38
|
-
} catch (e) {
|
|
39
|
-
// no-op
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// eslint-disable-next-line global-require
|
|
43
|
-
const express = require('express');
|
|
44
|
-
devServer.app.use(express.json());
|
|
45
|
-
|
|
46
|
-
devServer.app.get('/api/github-oauth-callback', async (req, res) => {
|
|
47
|
-
try {
|
|
48
|
-
const code = req.query.code;
|
|
49
|
-
if (!code) {
|
|
50
|
-
return res.status(400).send('Missing ?code from GitHub OAuth callback.');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const clientId = process.env.VITE_GITHUB_CLIENT_ID;
|
|
54
|
-
const clientSecret = process.env.GITHUB_CLIENT_SECRET;
|
|
55
|
-
|
|
56
|
-
if (!clientId) {
|
|
57
|
-
return res.status(500).send('Missing VITE_GITHUB_CLIENT_ID (client id).');
|
|
58
|
-
}
|
|
59
|
-
if (!clientSecret) {
|
|
60
|
-
return res.status(500).send(
|
|
61
|
-
'Missing GITHUB_CLIENT_SECRET. For local dev, put it in .env.server (gitignored).'
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Exchange code -> access token
|
|
66
|
-
const tokenResp = await fetch('https://github.com/login/oauth/access_token', {
|
|
67
|
-
method: 'POST',
|
|
68
|
-
headers: {
|
|
69
|
-
'Accept': 'application/json',
|
|
70
|
-
'Content-Type': 'application/json',
|
|
71
|
-
},
|
|
72
|
-
body: JSON.stringify({
|
|
73
|
-
client_id: clientId,
|
|
74
|
-
client_secret: clientSecret,
|
|
75
|
-
code,
|
|
76
|
-
}),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const tokenData = await tokenResp.json();
|
|
80
|
-
if (!tokenResp.ok || tokenData.error) {
|
|
81
|
-
return res
|
|
82
|
-
.status(500)
|
|
83
|
-
.send(`OAuth token exchange failed: ${tokenData.error || tokenResp.statusText}`);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const accessToken = tokenData.access_token;
|
|
87
|
-
if (!accessToken) {
|
|
88
|
-
return res.status(500).send('OAuth token exchange did not return an access_token.');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Fetch user
|
|
92
|
-
const userResp = await fetch('https://api.github.com/user', {
|
|
93
|
-
headers: {
|
|
94
|
-
'Accept': 'application/vnd.github+json',
|
|
95
|
-
'Authorization': `token ${accessToken}`,
|
|
96
|
-
'User-Agent': 'pfseed-commenting-system',
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
const user = await userResp.json();
|
|
100
|
-
if (!userResp.ok) {
|
|
101
|
-
return res.status(500).send(`Failed to fetch GitHub user: ${user.message || userResp.statusText}`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const login = encodeURIComponent(user.login || '');
|
|
105
|
-
const avatar = encodeURIComponent(user.avatar_url || '');
|
|
106
|
-
const token = encodeURIComponent(accessToken);
|
|
107
|
-
|
|
108
|
-
// Redirect back into the SPA; GitHubAuthContext will read these and store them.
|
|
109
|
-
return res.redirect(`/#/auth-callback?token=${token}&login=${login}&avatar=${avatar}`);
|
|
110
|
-
} catch (err) {
|
|
111
|
-
// eslint-disable-next-line no-console
|
|
112
|
-
console.error(err);
|
|
113
|
-
return res.status(500).send('Unhandled OAuth callback error. See dev server logs.');
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
devServer.app.post('/api/github-api', async (req, res) => {
|
|
118
|
-
try {
|
|
119
|
-
const { token, method, endpoint, data } = req.body || {};
|
|
120
|
-
if (!token) return res.status(401).json({ message: 'Missing token' });
|
|
121
|
-
if (!method || !endpoint) return res.status(400).json({ message: 'Missing method or endpoint' });
|
|
122
|
-
|
|
123
|
-
const url = `https://api.github.com${endpoint}`;
|
|
124
|
-
const resp = await fetch(url, {
|
|
125
|
-
method,
|
|
126
|
-
headers: {
|
|
127
|
-
'Accept': 'application/vnd.github+json',
|
|
128
|
-
'Authorization': `token ${token}`,
|
|
129
|
-
'User-Agent': 'pfseed-commenting-system',
|
|
130
|
-
...(data ? { 'Content-Type': 'application/json' } : {}),
|
|
131
|
-
},
|
|
132
|
-
body: data ? JSON.stringify(data) : undefined,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
const text = await resp.text();
|
|
136
|
-
const maybeJson = (() => {
|
|
137
|
-
try {
|
|
138
|
-
return JSON.parse(text);
|
|
139
|
-
} catch {
|
|
140
|
-
return text;
|
|
141
|
-
}
|
|
142
|
-
})();
|
|
143
|
-
|
|
144
|
-
return res.status(resp.status).json(maybeJson);
|
|
145
|
-
} catch (err) {
|
|
146
|
-
// eslint-disable-next-line no-console
|
|
147
|
-
console.error(err);
|
|
148
|
-
return res.status(500).json({ message: 'Unhandled github-api proxy error. See dev server logs.' });
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
devServer.app.get('/api/jira-issue', async (req, res) => {
|
|
153
|
-
try {
|
|
154
|
-
const key = String(req.query.key || '').trim();
|
|
155
|
-
if (!key) return res.status(400).json({ message: 'Missing ?key (e.g. ABC-123)' });
|
|
156
|
-
|
|
157
|
-
const baseUrl = (process.env.VITE_JIRA_BASE_URL || 'https://issues.redhat.com').replace(/\/+$/, '');
|
|
158
|
-
const email = process.env.JIRA_EMAIL;
|
|
159
|
-
const token = process.env.JIRA_API_TOKEN;
|
|
160
|
-
|
|
161
|
-
if (!token) {
|
|
162
|
-
return res.status(500).json({
|
|
163
|
-
message:
|
|
164
|
-
'Missing JIRA_API_TOKEN. For local dev, put it in .env.server (gitignored).',
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const authHeader = email
|
|
169
|
-
? `Basic ${Buffer.from(`${email}:${token}`).toString('base64')}` // Jira Cloud API token style
|
|
170
|
-
: `Bearer ${token}`; // Jira Server/DC PAT style
|
|
171
|
-
|
|
172
|
-
const adfToText = (node) => {
|
|
173
|
-
if (!node) return '';
|
|
174
|
-
if (typeof node === 'string') return node;
|
|
175
|
-
if (Array.isArray(node)) return node.map(adfToText).join('');
|
|
176
|
-
if (typeof node !== 'object') return '';
|
|
177
|
-
if (typeof node.text === 'string') return node.text;
|
|
178
|
-
const content = Array.isArray(node.content) ? node.content : [];
|
|
179
|
-
// Join blocks with newlines to preserve basic readability.
|
|
180
|
-
const joined = content.map(adfToText).join(node.type === 'paragraph' ? '' : '\n');
|
|
181
|
-
return joined;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
const stripHtmlTags = (input) => {
|
|
185
|
-
if (!input) return '';
|
|
186
|
-
return String(input)
|
|
187
|
-
.replace(/<[^>]*>/g, '')
|
|
188
|
-
.replace(/\r\n/g, '\n')
|
|
189
|
-
.trim();
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const buildUrl = (apiVersion) =>
|
|
193
|
-
`${baseUrl}/rest/api/${apiVersion}/issue/${encodeURIComponent(key)}?fields=summary,status,assignee,issuetype,priority,created,updated,description&expand=renderedFields`;
|
|
194
|
-
|
|
195
|
-
const commonHeaders = {
|
|
196
|
-
'Accept': 'application/json',
|
|
197
|
-
'Authorization': authHeader,
|
|
198
|
-
'User-Agent': 'pfseed-commenting-system',
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const fetchOnce = async (apiVersion) => {
|
|
202
|
-
const r = await fetch(buildUrl(apiVersion), { headers: commonHeaders, redirect: 'manual' });
|
|
203
|
-
const text = await r.text();
|
|
204
|
-
const contentType = String(r.headers.get('content-type') || '');
|
|
205
|
-
const looksLikeHtml =
|
|
206
|
-
contentType.includes('text/html') ||
|
|
207
|
-
String(text || '').trim().startsWith('<');
|
|
208
|
-
return { r, text, contentType, looksLikeHtml };
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// Red Hat Jira (issues.redhat.com) commonly works reliably on REST API v2.
|
|
212
|
-
// More generally: fall back across versions when we detect SSO redirects (302),
|
|
213
|
-
// HTML payloads, or auth failures that might be version-specific.
|
|
214
|
-
const preferV2 = baseUrl.includes('issues.redhat.com');
|
|
215
|
-
const firstVersion = preferV2 ? '2' : '3';
|
|
216
|
-
const secondVersion = preferV2 ? '3' : '2';
|
|
217
|
-
|
|
218
|
-
let attempt = await fetchOnce(firstVersion);
|
|
219
|
-
if (
|
|
220
|
-
attempt.r.status === 404 ||
|
|
221
|
-
attempt.r.status === 302 ||
|
|
222
|
-
attempt.looksLikeHtml ||
|
|
223
|
-
attempt.r.status === 401 ||
|
|
224
|
-
attempt.r.status === 403
|
|
225
|
-
) {
|
|
226
|
-
const fallback = await fetchOnce(secondVersion);
|
|
227
|
-
// Prefer the fallback if it succeeded, or if the first attempt clearly looked like SSO/HTML.
|
|
228
|
-
if (fallback.r.ok || attempt.looksLikeHtml || attempt.r.status === 302) {
|
|
229
|
-
attempt = fallback;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const resp = attempt.r;
|
|
234
|
-
const payloadText = attempt.text;
|
|
235
|
-
const contentType = attempt.contentType;
|
|
236
|
-
|
|
237
|
-
const payload = (() => {
|
|
238
|
-
try {
|
|
239
|
-
return JSON.parse(payloadText);
|
|
240
|
-
} catch {
|
|
241
|
-
return { message: payloadText };
|
|
242
|
-
}
|
|
243
|
-
})();
|
|
244
|
-
|
|
245
|
-
if (!resp.ok) {
|
|
246
|
-
// Many SSO flows return HTML (login page) instead of JSON; never dump that into the UI.
|
|
247
|
-
const looksLikeHtml =
|
|
248
|
-
contentType.includes('text/html') ||
|
|
249
|
-
String(payloadText || '').trim().startsWith('<');
|
|
250
|
-
|
|
251
|
-
if (looksLikeHtml) {
|
|
252
|
-
return res.status(resp.status).json({
|
|
253
|
-
message:
|
|
254
|
-
resp.status === 401 || resp.status === 403
|
|
255
|
-
? 'Unauthorized to Jira. Your token/auth scheme may be incorrect for this Jira instance.'
|
|
256
|
-
: `Jira request failed (${resp.status}).`,
|
|
257
|
-
hint: email
|
|
258
|
-
? 'You are using Basic auth (JIRA_EMAIL + JIRA_API_TOKEN). If this Jira uses PAT/Bearer tokens, remove JIRA_EMAIL and set only JIRA_API_TOKEN.'
|
|
259
|
-
: baseUrl.includes('issues.redhat.com')
|
|
260
|
-
? 'You are using Bearer auth (JIRA_API_TOKEN). For issues.redhat.com, ensure you are using a PAT that works with REST API v2 and that JIRA_EMAIL is NOT set.'
|
|
261
|
-
: 'You are using Bearer auth (JIRA_API_TOKEN). If this Jira uses Jira Cloud API tokens, set JIRA_EMAIL as well.',
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return res.status(resp.status).json({
|
|
266
|
-
message: payload?.message || `Jira request failed (${resp.status}).`,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const issue = payload;
|
|
271
|
-
const fields = issue.fields || {};
|
|
272
|
-
|
|
273
|
-
const descriptionRaw = fields.description;
|
|
274
|
-
const descriptionText =
|
|
275
|
-
typeof descriptionRaw === 'string'
|
|
276
|
-
? descriptionRaw
|
|
277
|
-
: typeof descriptionRaw === 'object'
|
|
278
|
-
? adfToText(descriptionRaw)
|
|
279
|
-
: '';
|
|
280
|
-
|
|
281
|
-
const renderedDescription = issue?.renderedFields?.description;
|
|
282
|
-
const renderedDescriptionText = stripHtmlTags(renderedDescription || '');
|
|
283
|
-
|
|
284
|
-
const finalDescription =
|
|
285
|
-
(stripHtmlTags(descriptionText) || renderedDescriptionText || '').trim();
|
|
286
|
-
|
|
287
|
-
return res.json({
|
|
288
|
-
key: issue.key,
|
|
289
|
-
url: `${baseUrl}/browse/${issue.key}`,
|
|
290
|
-
summary: fields.summary || '',
|
|
291
|
-
status: fields.status?.name || '',
|
|
292
|
-
assignee: fields.assignee?.displayName || '',
|
|
293
|
-
issueType: fields.issuetype?.name || '',
|
|
294
|
-
priority: fields.priority?.name || '',
|
|
295
|
-
created: fields.created || '',
|
|
296
|
-
updated: fields.updated || '',
|
|
297
|
-
description: finalDescription || '',
|
|
298
|
-
});
|
|
299
|
-
} catch (err) {
|
|
300
|
-
// eslint-disable-next-line no-console
|
|
301
|
-
console.error(err);
|
|
302
|
-
return res.status(500).json({ message: 'Unhandled jira-issue proxy error. See dev server logs.' });
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
return middlewares;
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
|
-
module: {
|
|
310
|
-
rules: [
|
|
311
|
-
{
|
|
312
|
-
test: /\.css$/,
|
|
313
|
-
include: [...stylePaths],
|
|
314
|
-
use: ['style-loader', 'css-loader'],
|
|
315
|
-
},
|
|
316
|
-
],
|
|
317
|
-
},
|
|
318
|
-
});
|
package/webpack.prod.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
|
|
3
|
-
const { merge } = require('webpack-merge');
|
|
4
|
-
const common = require('./webpack.common.js');
|
|
5
|
-
const { stylePaths } = require('./stylePaths');
|
|
6
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
7
|
-
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
8
|
-
const TerserJSPlugin = require('terser-webpack-plugin');
|
|
9
|
-
|
|
10
|
-
module.exports = merge(common('production'), {
|
|
11
|
-
mode: 'production',
|
|
12
|
-
devtool: 'source-map',
|
|
13
|
-
optimization: {
|
|
14
|
-
minimizer: [
|
|
15
|
-
new TerserJSPlugin({}),
|
|
16
|
-
new CssMinimizerPlugin({
|
|
17
|
-
minimizerOptions: {
|
|
18
|
-
preset: ['default', { mergeLonghand: false }],
|
|
19
|
-
},
|
|
20
|
-
}),
|
|
21
|
-
],
|
|
22
|
-
},
|
|
23
|
-
plugins: [
|
|
24
|
-
new MiniCssExtractPlugin({
|
|
25
|
-
filename: '[name].css',
|
|
26
|
-
chunkFilename: '[name].bundle.css',
|
|
27
|
-
}),
|
|
28
|
-
],
|
|
29
|
-
module: {
|
|
30
|
-
rules: [
|
|
31
|
-
{
|
|
32
|
-
test: /\.css$/,
|
|
33
|
-
include: [...stylePaths],
|
|
34
|
-
use: [MiniCssExtractPlugin.loader, 'css-loader'],
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
});
|