hale-commenting-system 2.1.1 → 2.2.1

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.
Files changed (99) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/.editorconfig +17 -0
  3. package/.eslintrc.js +75 -0
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +23 -0
  5. package/.github/workflows/ci.yaml +51 -0
  6. package/.prettierignore +1 -0
  7. package/.prettierrc +4 -0
  8. package/GITHUB_OAUTH_ENV_TEMPLATE.md +53 -0
  9. package/LICENSE +21 -0
  10. package/README.md +92 -21
  11. package/package.json +74 -50
  12. package/scripts/README.md +42 -0
  13. package/scripts/integrate.js +440 -0
  14. package/src/app/AppLayout/AppLayout.tsx +248 -0
  15. package/src/app/Comments/Comments.tsx +273 -0
  16. package/src/app/Dashboard/Dashboard.tsx +10 -0
  17. package/src/app/NotFound/NotFound.tsx +35 -0
  18. package/src/app/Settings/General/GeneralSettings.tsx +16 -0
  19. package/src/app/Settings/Profile/ProfileSettings.tsx +18 -0
  20. package/src/app/Support/Support.tsx +50 -0
  21. package/src/app/__snapshots__/app.test.tsx.snap +524 -0
  22. package/src/app/app.css +11 -0
  23. package/src/app/app.test.tsx +55 -0
  24. package/src/app/bgimages/Patternfly-Logo.svg +28 -0
  25. package/src/app/commenting-system/components/CommentOverlay.tsx +93 -0
  26. package/src/app/commenting-system/components/CommentPanel.tsx +534 -0
  27. package/src/app/commenting-system/components/CommentPin.tsx +60 -0
  28. package/src/app/commenting-system/components/DetailsTab.tsx +516 -0
  29. package/src/app/commenting-system/components/FloatingWidget.tsx +130 -0
  30. package/src/app/commenting-system/components/JiraTab.tsx +696 -0
  31. package/src/app/commenting-system/contexts/CommentContext.tsx +1033 -0
  32. package/src/app/commenting-system/contexts/GitHubAuthContext.tsx +84 -0
  33. package/{dist/index.d.ts → src/app/commenting-system/index.ts} +5 -4
  34. package/src/app/commenting-system/services/githubAdapter.ts +359 -0
  35. package/src/app/commenting-system/types/index.ts +27 -0
  36. package/src/app/commenting-system/utils/version.ts +19 -0
  37. package/src/app/index.tsx +22 -0
  38. package/src/app/routes.tsx +81 -0
  39. package/src/app/utils/useDocumentTitle.ts +13 -0
  40. package/src/favicon.png +0 -0
  41. package/src/index.html +18 -0
  42. package/src/index.tsx +25 -0
  43. package/src/test/setup.ts +33 -0
  44. package/src/typings.d.ts +12 -0
  45. package/stylePaths.js +14 -0
  46. package/tsconfig.json +34 -0
  47. package/vitest.config.ts +19 -0
  48. package/webpack.common.js +139 -0
  49. package/webpack.dev.js +318 -0
  50. package/webpack.prod.js +38 -0
  51. package/bin/detect.d.ts +0 -10
  52. package/bin/detect.js +0 -134
  53. package/bin/generators.d.ts +0 -18
  54. package/bin/generators.js +0 -193
  55. package/bin/hale-commenting.js +0 -4
  56. package/bin/index.d.ts +0 -2
  57. package/bin/index.js +0 -61
  58. package/bin/onboarding.d.ts +0 -1
  59. package/bin/onboarding.js +0 -349
  60. package/bin/postinstall.d.ts +0 -2
  61. package/bin/postinstall.js +0 -65
  62. package/bin/validators.d.ts +0 -2
  63. package/bin/validators.js +0 -66
  64. package/dist/cli/detect.d.ts +0 -10
  65. package/dist/cli/detect.js +0 -134
  66. package/dist/cli/generators.d.ts +0 -18
  67. package/dist/cli/generators.js +0 -193
  68. package/dist/cli/index.d.ts +0 -2
  69. package/dist/cli/index.js +0 -61
  70. package/dist/cli/onboarding.d.ts +0 -1
  71. package/dist/cli/onboarding.js +0 -349
  72. package/dist/cli/postinstall.d.ts +0 -2
  73. package/dist/cli/postinstall.js +0 -65
  74. package/dist/cli/validators.d.ts +0 -2
  75. package/dist/cli/validators.js +0 -66
  76. package/dist/components/CommentOverlay.d.ts +0 -2
  77. package/dist/components/CommentOverlay.js +0 -101
  78. package/dist/components/CommentPanel.d.ts +0 -6
  79. package/dist/components/CommentPanel.js +0 -334
  80. package/dist/components/CommentPin.d.ts +0 -11
  81. package/dist/components/CommentPin.js +0 -64
  82. package/dist/components/DetailsTab.d.ts +0 -2
  83. package/dist/components/DetailsTab.js +0 -380
  84. package/dist/components/FloatingWidget.d.ts +0 -8
  85. package/dist/components/FloatingWidget.js +0 -128
  86. package/dist/components/JiraTab.d.ts +0 -2
  87. package/dist/components/JiraTab.js +0 -507
  88. package/dist/contexts/CommentContext.d.ts +0 -30
  89. package/dist/contexts/CommentContext.js +0 -891
  90. package/dist/contexts/GitHubAuthContext.d.ts +0 -13
  91. package/dist/contexts/GitHubAuthContext.js +0 -96
  92. package/dist/index.js +0 -27
  93. package/dist/services/githubAdapter.d.ts +0 -56
  94. package/dist/services/githubAdapter.js +0 -321
  95. package/dist/types/index.d.ts +0 -25
  96. package/dist/types/index.js +0 -2
  97. package/dist/utils/version.d.ts +0 -1
  98. package/dist/utils/version.js +0 -23
  99. package/templates/webpack-middleware.js +0 -226
@@ -0,0 +1,33 @@
1
+ import '@testing-library/jest-dom';
2
+ import { vi } from 'vitest';
3
+
4
+ // Mock CSS imports
5
+ Object.defineProperty(window, 'matchMedia', {
6
+ writable: true,
7
+ value: vi.fn().mockImplementation((query) => ({
8
+ matches: false,
9
+ media: query,
10
+ onchange: null,
11
+ addListener: vi.fn(), // deprecated
12
+ removeListener: vi.fn(), // deprecated
13
+ addEventListener: vi.fn(),
14
+ removeEventListener: vi.fn(),
15
+ dispatchEvent: vi.fn(),
16
+ })),
17
+ });
18
+
19
+ // Mock ResizeObserver
20
+ global.ResizeObserver = class ResizeObserver {
21
+ observe = vi.fn();
22
+ unobserve = vi.fn();
23
+ disconnect = vi.fn();
24
+ constructor(callback: ResizeObserverCallback) {}
25
+ };
26
+
27
+ // Mock IntersectionObserver
28
+ global.IntersectionObserver = class IntersectionObserver {
29
+ observe = vi.fn();
30
+ unobserve = vi.fn();
31
+ disconnect = vi.fn();
32
+ constructor(callback: IntersectionObserverCallback, options?: IntersectionObserverInit) {}
33
+ } as any;
@@ -0,0 +1,12 @@
1
+ declare module '*.png';
2
+ declare module '*.jpg';
3
+ declare module '*.jpeg';
4
+ declare module '*.gif';
5
+ declare module '*.svg';
6
+ declare module '*.css';
7
+ declare module '*.wav';
8
+ declare module '*.mp3';
9
+ declare module '*.m4a';
10
+ declare module '*.rdf';
11
+ declare module '*.ttl';
12
+ declare module '*.pdf';
package/stylePaths.js ADDED
@@ -0,0 +1,14 @@
1
+ const path = require('path');
2
+ module.exports = {
3
+ stylePaths: [
4
+ path.resolve(__dirname, 'src'),
5
+ path.resolve(__dirname, 'node_modules/patternfly'),
6
+ path.resolve(__dirname, 'node_modules/@patternfly/patternfly'),
7
+ path.resolve(__dirname, 'node_modules/@patternfly/react-styles/css'),
8
+ path.resolve(__dirname, 'node_modules/@patternfly/react-core/dist/styles/base.css'),
9
+ path.resolve(__dirname, 'node_modules/@patternfly/react-core/dist/esm/@patternfly/patternfly'),
10
+ path.resolve(__dirname, 'node_modules/@patternfly/react-core/node_modules/@patternfly/react-styles/css'),
11
+ path.resolve(__dirname, 'node_modules/@patternfly/react-table/node_modules/@patternfly/react-styles/css'),
12
+ path.resolve(__dirname, 'node_modules/@patternfly/react-inline-edit-extension/node_modules/@patternfly/react-styles/css')
13
+ ]
14
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "rootDir": ".",
5
+ "outDir": "dist",
6
+ "module": "esnext",
7
+ "target": "es5",
8
+ "lib": ["es6", "dom"],
9
+ "sourceMap": true,
10
+ "jsx": "react",
11
+ "moduleResolution": "node",
12
+ "forceConsistentCasingInFileNames": true,
13
+ "noImplicitReturns": true,
14
+ "noImplicitThis": true,
15
+ "noImplicitAny": false,
16
+ "allowJs": true,
17
+ "esModuleInterop": true,
18
+ "allowSyntheticDefaultImports": true,
19
+ "strict": true,
20
+ "paths": {
21
+ "@app/*": ["src/app/*"],
22
+ "@assets/*": ["node_modules/@patternfly/react-core/dist/styles/assets/*"]
23
+ },
24
+ "importHelpers": true,
25
+ "skipLibCheck": true
26
+ },
27
+ "include": [
28
+ "**/*.ts",
29
+ "**/*.tsx",
30
+ "**/*.jsx",
31
+ "**/*.js"
32
+ ],
33
+ "exclude": ["node_modules"]
34
+ }
@@ -0,0 +1,19 @@
1
+ /// <reference types="vitest" />
2
+ import { defineConfig } from 'vitest/config';
3
+ import react from '@vitejs/plugin-react';
4
+ import path from 'path';
5
+
6
+ export default defineConfig({
7
+ plugins: [react()],
8
+ test: {
9
+ environment: 'jsdom',
10
+ setupFiles: ['./src/test/setup.ts'],
11
+ globals: true,
12
+ css: true,
13
+ },
14
+ resolve: {
15
+ alias: {
16
+ '@app': path.resolve(__dirname, './src/app'),
17
+ },
18
+ },
19
+ });
@@ -0,0 +1,139 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+
3
+ const path = require('path');
4
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
5
+ const CopyPlugin = require('copy-webpack-plugin');
6
+ const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
7
+ const Dotenv = require('dotenv-webpack');
8
+ const BG_IMAGES_DIRNAME = 'bgimages';
9
+ const ASSET_PATH = process.env.ASSET_PATH || '/';
10
+ module.exports = (env) => {
11
+ return {
12
+ module: {
13
+ rules: [
14
+ {
15
+ test: /\.(tsx|ts|jsx)?$/,
16
+ use: [
17
+ {
18
+ loader: 'ts-loader',
19
+ options: {
20
+ transpileOnly: true,
21
+ experimentalWatchApi: true,
22
+ },
23
+ },
24
+ ],
25
+ },
26
+ {
27
+ test: /\.(svg|ttf|eot|woff|woff2)$/,
28
+ type: 'asset/resource',
29
+ // only process modules with this loader
30
+ // if they live under a 'fonts' or 'pficon' directory
31
+ include: [
32
+ path.resolve(__dirname, 'node_modules/patternfly/dist/fonts'),
33
+ path.resolve(__dirname, 'node_modules/@patternfly/react-core/dist/styles/assets/fonts'),
34
+ path.resolve(__dirname, 'node_modules/@patternfly/react-core/dist/styles/assets/pficon'),
35
+ path.resolve(__dirname, 'node_modules/@patternfly/patternfly/assets/fonts'),
36
+ path.resolve(__dirname, 'node_modules/@patternfly/patternfly/assets/pficon'),
37
+ ],
38
+ },
39
+ {
40
+ test: /\.svg$/,
41
+ type: 'asset/inline',
42
+ include: (input) => input.indexOf('background-filter.svg') > 1,
43
+ use: [
44
+ {
45
+ options: {
46
+ limit: 5000,
47
+ outputPath: 'svgs',
48
+ name: '[name].[ext]',
49
+ },
50
+ },
51
+ ],
52
+ },
53
+ {
54
+ test: /\.svg$/,
55
+ // only process SVG modules with this loader if they live under a 'bgimages' directory
56
+ // this is primarily useful when applying a CSS background using an SVG
57
+ include: (input) => input.indexOf(BG_IMAGES_DIRNAME) > -1,
58
+ type: 'asset/inline',
59
+ },
60
+ {
61
+ test: /\.svg$/,
62
+ // only process SVG modules with this loader when they don't live under a 'bgimages',
63
+ // 'fonts', or 'pficon' directory, those are handled with other loaders
64
+ include: (input) =>
65
+ input.indexOf(BG_IMAGES_DIRNAME) === -1 &&
66
+ input.indexOf('fonts') === -1 &&
67
+ input.indexOf('background-filter') === -1 &&
68
+ input.indexOf('pficon') === -1,
69
+ use: {
70
+ loader: 'raw-loader',
71
+ options: {},
72
+ },
73
+ },
74
+ {
75
+ test: /\.(jpg|jpeg|png|gif)$/i,
76
+ include: [
77
+ path.resolve(__dirname, 'src'),
78
+ path.resolve(__dirname, 'node_modules/patternfly'),
79
+ path.resolve(__dirname, 'node_modules/@patternfly/patternfly/assets/images'),
80
+ path.resolve(__dirname, 'node_modules/@patternfly/react-styles/css/assets/images'),
81
+ path.resolve(__dirname, 'node_modules/@patternfly/react-core/dist/styles/assets/images'),
82
+ path.resolve(
83
+ __dirname,
84
+ 'node_modules/@patternfly/react-core/node_modules/@patternfly/react-styles/css/assets/images'
85
+ ),
86
+ path.resolve(
87
+ __dirname,
88
+ 'node_modules/@patternfly/react-table/node_modules/@patternfly/react-styles/css/assets/images'
89
+ ),
90
+ path.resolve(
91
+ __dirname,
92
+ 'node_modules/@patternfly/react-inline-edit-extension/node_modules/@patternfly/react-styles/css/assets/images'
93
+ ),
94
+ ],
95
+ type: 'asset/inline',
96
+ use: [
97
+ {
98
+ options: {
99
+ limit: 5000,
100
+ outputPath: 'images',
101
+ name: '[name].[ext]',
102
+ },
103
+ },
104
+ ],
105
+ },
106
+ ],
107
+ },
108
+ output: {
109
+ filename: '[name].bundle.js',
110
+ path: path.resolve(__dirname, 'dist'),
111
+ publicPath: ASSET_PATH,
112
+ },
113
+ plugins: [
114
+ new HtmlWebpackPlugin({
115
+ template: path.resolve(__dirname, 'src', 'index.html'),
116
+ }),
117
+ new Dotenv({
118
+ // IMPORTANT: do not inline system env vars into the browser bundle.
119
+ // Keep `.env` for public/client-side config only (e.g. VITE_GITHUB_CLIENT_ID).
120
+ // Server-side secrets should be provided via server runtime env (functions) instead.
121
+ systemvars: false,
122
+ silent: true,
123
+ }),
124
+ new CopyPlugin({
125
+ patterns: [{ from: './src/favicon.png', to: 'images' }],
126
+ }),
127
+ ],
128
+ resolve: {
129
+ extensions: ['.js', '.ts', '.tsx', '.jsx'],
130
+ plugins: [
131
+ new TsconfigPathsPlugin({
132
+ configFile: path.resolve(__dirname, './tsconfig.json'),
133
+ }),
134
+ ],
135
+ symlinks: false,
136
+ cacheWithContext: false,
137
+ },
138
+ };
139
+ };
package/webpack.dev.js ADDED
@@ -0,0 +1,318 @@
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
+ });
@@ -0,0 +1,38 @@
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
+ });
package/bin/detect.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export declare function detectPatternFlySeed(): boolean;
2
- export interface GitRemoteInfo {
3
- owner?: string;
4
- repo?: string;
5
- url?: string;
6
- isFork?: boolean;
7
- }
8
- export declare function detectGitRemote(): GitRemoteInfo | null;
9
- export type ProjectSetupType = 'forked' | 'cloned' | 'unknown' | 'none';
10
- export declare function detectProjectSetup(): ProjectSetupType;