github-issue-tower-defence-management 1.89.0 → 1.91.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/CODEOWNERS +1 -2
- package/CHANGELOG.md +14 -0
- package/README.md +15 -2
- package/bin/adapter/entry-points/cli/index.js +16 -12
- package/bin/adapter/entry-points/cli/index.js.map +1 -1
- package/bin/adapter/entry-points/cli/projectConfig.js +2 -0
- package/bin/adapter/entry-points/cli/projectConfig.js.map +1 -1
- package/bin/adapter/entry-points/console/consoleOperationApi.js +54 -27
- package/bin/adapter/entry-points/console/consoleOperationApi.js.map +1 -1
- package/bin/adapter/entry-points/console/consoleProjectResolver.js +38 -0
- package/bin/adapter/entry-points/console/consoleProjectResolver.js.map +1 -0
- package/bin/adapter/entry-points/console/consoleServer.js +43 -17
- package/bin/adapter/entry-points/console/consoleServer.js.map +1 -1
- package/bin/adapter/entry-points/console/ui-dist/assets/index-BU6p3cGU.css +1 -0
- package/bin/adapter/entry-points/console/ui-dist/assets/index-BvuSQN9s.js +100 -0
- package/bin/adapter/entry-points/console/ui-dist/index.html +2 -2
- package/bin/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.js +16 -0
- package/bin/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.js.map +1 -1
- package/jest.config.js +57 -9
- package/package.json +17 -13
- package/src/adapter/entry-points/cli/index.test.ts +12 -2
- package/src/adapter/entry-points/cli/index.ts +30 -12
- package/src/adapter/entry-points/cli/projectConfig.ts +3 -0
- package/src/adapter/entry-points/console/consoleOperationApi.test.ts +129 -15
- package/src/adapter/entry-points/console/consoleOperationApi.ts +83 -28
- package/src/adapter/entry-points/console/consoleProjectResolver.test.ts +96 -0
- package/src/adapter/entry-points/console/consoleProjectResolver.ts +50 -0
- package/src/adapter/entry-points/console/consoleServer.test.ts +86 -4
- package/src/adapter/entry-points/console/consoleServer.ts +53 -23
- package/src/adapter/entry-points/console/ui/jest.setup.ts +1 -0
- package/src/adapter/entry-points/console/ui/jest.styleMock.js +1 -0
- package/src/adapter/entry-points/console/ui/src/features/console/colors.test.ts +34 -0
- package/src/adapter/entry-points/console/ui/src/features/console/colors.ts +73 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleChangedFileList.stories.tsx +28 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleChangedFileList.test.tsx +42 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleChangedFileList.tsx +55 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCloseButtonGroup.stories.tsx +14 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCloseButtonGroup.test.tsx +23 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCloseButtonGroup.tsx +26 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCommentList.stories.tsx +29 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCommentList.test.tsx +55 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCommentList.tsx +66 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCommitList.stories.tsx +25 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCommitList.test.tsx +53 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleCommitList.tsx +53 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleItemDetail.stories.tsx +79 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleItemDetail.test.tsx +81 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleItemDetail.tsx +226 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleItemIcon.stories.tsx +82 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleItemIcon.test.tsx +52 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleItemIcon.tsx +32 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleListItemRow.stories.tsx +25 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleListItemRow.test.tsx +43 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleListItemRow.tsx +34 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleListView.stories.tsx +22 -6
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleListView.test.tsx +87 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleListView.tsx +36 -32
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleMarkdownView.stories.tsx +27 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleMarkdownView.test.tsx +36 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleMarkdownView.tsx +50 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleMermaidDiagram.stories.tsx +22 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleMermaidDiagram.test.tsx +38 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleMermaidDiagram.tsx +65 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleNextActionDateGroup.stories.tsx +20 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleNextActionDateGroup.test.tsx +42 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleNextActionDateGroup.tsx +28 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleOperationBar.stories.tsx +55 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleOperationBar.test.tsx +85 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleOperationBar.tsx +55 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePanel.stories.tsx +26 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePanel.test.tsx +32 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePanel.tsx +36 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleProjectHeader.stories.tsx +29 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleProjectHeader.test.tsx +14 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleProjectHeader.tsx +14 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePullRequestReviewGroup.stories.tsx +14 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePullRequestReviewGroup.test.tsx +33 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePullRequestReviewGroup.tsx +34 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePullRequestSection.stories.tsx +31 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePullRequestSection.test.tsx +40 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsolePullRequestSection.tsx +88 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStatusButtonGroup.stories.tsx +17 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStatusButtonGroup.test.tsx +49 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStatusButtonGroup.tsx +63 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStoryButtonGroup.stories.tsx +17 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStoryButtonGroup.test.tsx +45 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStoryButtonGroup.tsx +42 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStoryGroupHeader.stories.tsx +27 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStoryGroupHeader.test.tsx +24 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleStoryGroupHeader.tsx +28 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleTabBar.stories.tsx +41 -5
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleTabBar.test.tsx +59 -0
- package/src/adapter/entry-points/console/ui/src/features/console/components/ConsoleTabBar.tsx +28 -19
- package/src/adapter/entry-points/console/ui/src/features/console/fileStatus.test.ts +35 -0
- package/src/adapter/entry-points/console/ui/src/features/console/fileStatus.ts +21 -0
- package/src/adapter/entry-points/console/ui/src/features/console/fixtures.ts +206 -9
- package/src/adapter/entry-points/console/ui/src/features/console/grouping.test.ts +91 -0
- package/src/adapter/entry-points/console/ui/src/features/console/grouping.ts +79 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleCaches.test.ts +22 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleCaches.ts +42 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleItemDetailData.test.ts +126 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleItemDetailData.ts +167 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleOperations.test.ts +198 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleOperations.ts +243 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleOverlay.test.ts +40 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleOverlay.ts +71 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsolePjcode.test.ts +24 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsolePjcode.ts +17 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleResource.test.ts +41 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleResource.ts +57 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleTabData.test.ts +63 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleTabData.ts +129 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleToken.test.ts +41 -0
- package/src/adapter/entry-points/console/ui/src/features/console/itemIcons.test.ts +97 -0
- package/src/adapter/entry-points/console/ui/src/features/console/itemIcons.ts +95 -0
- package/src/adapter/entry-points/console/ui/src/features/console/lib/consoleApi.test.ts +155 -0
- package/src/adapter/entry-points/console/ui/src/features/console/lib/consoleApi.ts +187 -0
- package/src/adapter/entry-points/console/ui/src/features/console/lib/markdown.test.ts +76 -0
- package/src/adapter/entry-points/console/ui/src/features/console/lib/markdown.ts +73 -0
- package/src/adapter/entry-points/console/ui/src/features/console/lib/mermaidLoader.test.ts +27 -0
- package/src/adapter/entry-points/console/ui/src/features/console/lib/mermaidLoader.ts +71 -0
- package/src/adapter/entry-points/console/ui/src/features/console/lib/resourceCache.test.ts +56 -0
- package/src/adapter/entry-points/console/ui/src/features/console/lib/resourceCache.ts +51 -0
- package/src/adapter/entry-points/console/ui/src/features/console/operations.test.ts +37 -0
- package/src/adapter/entry-points/console/ui/src/features/console/operations.ts +35 -0
- package/src/adapter/entry-points/console/ui/src/features/console/overlay.test.ts +124 -0
- package/src/adapter/entry-points/console/ui/src/features/console/overlay.ts +101 -0
- package/src/adapter/entry-points/console/ui/src/features/console/pages/ConsoleItemDetailContainer.test.tsx +79 -0
- package/src/adapter/entry-points/console/ui/src/features/console/pages/ConsoleItemDetailContainer.tsx +109 -0
- package/src/adapter/entry-points/console/ui/src/features/console/pages/ConsolePage.test.tsx +74 -0
- package/src/adapter/entry-points/console/ui/src/features/console/pages/ConsolePage.tsx +137 -7
- package/src/adapter/entry-points/console/ui/src/features/console/relativeTime.test.ts +52 -0
- package/src/adapter/entry-points/console/ui/src/features/console/relativeTime.ts +51 -0
- package/src/adapter/entry-points/console/ui/src/features/console/types.ts +73 -1
- package/src/adapter/entry-points/console/ui/src/index.css +352 -2
- package/src/adapter/entry-points/console/ui/tsconfig.json +3 -1
- package/src/adapter/entry-points/console/ui/vite.config.ts +6 -1
- package/src/adapter/entry-points/console/ui-dist/assets/index-BU6p3cGU.css +1 -0
- package/src/adapter/entry-points/console/ui-dist/assets/index-BvuSQN9s.js +100 -0
- package/src/adapter/entry-points/console/ui-dist/index.html +2 -2
- package/src/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.ts +25 -0
- package/src/domain/usecases/adapter-interfaces/IssueRepository.ts +4 -0
- package/types/adapter/entry-points/cli/index.d.ts.map +1 -1
- package/types/adapter/entry-points/cli/projectConfig.d.ts +1 -0
- package/types/adapter/entry-points/cli/projectConfig.d.ts.map +1 -1
- package/types/adapter/entry-points/console/consoleOperationApi.d.ts +6 -2
- package/types/adapter/entry-points/console/consoleOperationApi.d.ts.map +1 -1
- package/types/adapter/entry-points/console/consoleProjectResolver.d.ts +6 -0
- package/types/adapter/entry-points/console/consoleProjectResolver.d.ts.map +1 -0
- package/types/adapter/entry-points/console/consoleServer.d.ts +3 -3
- package/types/adapter/entry-points/console/consoleServer.d.ts.map +1 -1
- package/types/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.d.ts +1 -0
- package/types/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.d.ts.map +1 -1
- package/types/domain/usecases/adapter-interfaces/IssueRepository.d.ts +1 -0
- package/types/domain/usecases/adapter-interfaces/IssueRepository.d.ts.map +1 -1
- package/bin/adapter/entry-points/console/ui-dist/assets/index-DFxrSRH4.css +0 -1
- package/bin/adapter/entry-points/console/ui-dist/assets/index-DcOZ02ON.js +0 -49
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleList.ts +0 -65
- package/src/adapter/entry-points/console/ui-dist/assets/index-DFxrSRH4.css +0 -1
- package/src/adapter/entry-points/console/ui-dist/assets/index-DcOZ02ON.js +0 -49
package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleCaches.test.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react';
|
|
2
|
+
import { useConsoleCaches } from './useConsoleCaches';
|
|
3
|
+
|
|
4
|
+
describe('useConsoleCaches', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
localStorage.clear();
|
|
7
|
+
window.history.replaceState({}, '', '/?k=token');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('exposes one cache per resource and a stable identity across renders', () => {
|
|
11
|
+
const { result, rerender } = renderHook(() => useConsoleCaches());
|
|
12
|
+
const first = result.current;
|
|
13
|
+
expect(first.body).toBeDefined();
|
|
14
|
+
expect(first.comments).toBeDefined();
|
|
15
|
+
expect(first.files).toBeDefined();
|
|
16
|
+
expect(first.commits).toBeDefined();
|
|
17
|
+
expect(first.relatedPrs).toBeDefined();
|
|
18
|
+
expect(first.state).toBeDefined();
|
|
19
|
+
rerender();
|
|
20
|
+
expect(result.current).toBe(first);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
type ConsoleApiClient,
|
|
4
|
+
createConsoleApiClient,
|
|
5
|
+
} from '../lib/consoleApi';
|
|
6
|
+
import { ResourceCache } from '../lib/resourceCache';
|
|
7
|
+
import type {
|
|
8
|
+
ConsoleChangedFile,
|
|
9
|
+
ConsoleComment,
|
|
10
|
+
ConsoleCommit,
|
|
11
|
+
ConsoleIssueState,
|
|
12
|
+
ConsoleRelatedPullRequest,
|
|
13
|
+
} from '../types';
|
|
14
|
+
import { useConsoleToken } from './useConsoleToken';
|
|
15
|
+
|
|
16
|
+
export type ConsoleCaches = {
|
|
17
|
+
body: ResourceCache<string>;
|
|
18
|
+
comments: ResourceCache<ConsoleComment[]>;
|
|
19
|
+
files: ResourceCache<ConsoleChangedFile[]>;
|
|
20
|
+
commits: ResourceCache<ConsoleCommit[]>;
|
|
21
|
+
relatedPrs: ResourceCache<ConsoleRelatedPullRequest[]>;
|
|
22
|
+
state: ResourceCache<ConsoleIssueState>;
|
|
23
|
+
client: ConsoleApiClient;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const useConsoleCaches = (): ConsoleCaches => {
|
|
27
|
+
const { appendToken } = useConsoleToken();
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
const client = createConsoleApiClient(appendToken);
|
|
30
|
+
return {
|
|
31
|
+
client,
|
|
32
|
+
body: new ResourceCache<string>(client.fetchItemBody),
|
|
33
|
+
comments: new ResourceCache<ConsoleComment[]>(client.fetchComments),
|
|
34
|
+
files: new ResourceCache<ConsoleChangedFile[]>(client.fetchPrFiles),
|
|
35
|
+
commits: new ResourceCache<ConsoleCommit[]>(client.fetchPrCommits),
|
|
36
|
+
relatedPrs: new ResourceCache<ConsoleRelatedPullRequest[]>(
|
|
37
|
+
client.fetchRelatedPrs,
|
|
38
|
+
),
|
|
39
|
+
state: new ResourceCache<ConsoleIssueState>(client.fetchIssueState),
|
|
40
|
+
};
|
|
41
|
+
}, [appendToken]);
|
|
42
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { renderHook, waitFor } from '@testing-library/react';
|
|
2
|
+
import { ResourceCache } from '../lib/resourceCache';
|
|
3
|
+
import type {
|
|
4
|
+
ConsoleChangedFile,
|
|
5
|
+
ConsoleComment,
|
|
6
|
+
ConsoleCommit,
|
|
7
|
+
ConsoleIssueState,
|
|
8
|
+
ConsoleListItem,
|
|
9
|
+
ConsoleRelatedPullRequest,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import type { ConsoleCaches } from './useConsoleCaches';
|
|
12
|
+
import { useConsoleItemDetailData } from './useConsoleItemDetailData';
|
|
13
|
+
|
|
14
|
+
const prItem: ConsoleListItem = {
|
|
15
|
+
number: 1,
|
|
16
|
+
title: 'PR',
|
|
17
|
+
url: 'https://github.com/o/r/pull/1',
|
|
18
|
+
repo: 'o/r',
|
|
19
|
+
nameWithOwner: 'o/r',
|
|
20
|
+
projectItemId: 'PVTI_1',
|
|
21
|
+
itemId: 'PVTI_1',
|
|
22
|
+
isPr: true,
|
|
23
|
+
story: 'Story',
|
|
24
|
+
labels: [],
|
|
25
|
+
createdAt: '2026-06-10T00:00:00.000Z',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const issueItem: ConsoleListItem = {
|
|
29
|
+
...prItem,
|
|
30
|
+
isPr: false,
|
|
31
|
+
url: 'https://github.com/o/r/issues/2',
|
|
32
|
+
number: 2,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const buildCaches = (related: ConsoleRelatedPullRequest[]): ConsoleCaches => {
|
|
36
|
+
const client = {
|
|
37
|
+
fetchItemBody: async () => 'body',
|
|
38
|
+
fetchComments: async (): Promise<ConsoleComment[]> => [],
|
|
39
|
+
fetchPrFiles: async (): Promise<ConsoleChangedFile[]> => [
|
|
40
|
+
{
|
|
41
|
+
path: 'a.ts',
|
|
42
|
+
additions: 1,
|
|
43
|
+
deletions: 0,
|
|
44
|
+
status: 'added',
|
|
45
|
+
patch: null,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
fetchPrCommits: async (): Promise<ConsoleCommit[]> => [
|
|
49
|
+
{
|
|
50
|
+
sha: 'abc',
|
|
51
|
+
message: 'm',
|
|
52
|
+
author: 'a',
|
|
53
|
+
authoredAt: '2026-06-10T00:00:00.000Z',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
fetchRelatedPrs: async (): Promise<ConsoleRelatedPullRequest[]> => related,
|
|
57
|
+
fetchIssueState: async (): Promise<ConsoleIssueState> => ({
|
|
58
|
+
state: 'open',
|
|
59
|
+
merged: false,
|
|
60
|
+
isPullRequest: true,
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
client,
|
|
65
|
+
body: new ResourceCache(client.fetchItemBody),
|
|
66
|
+
comments: new ResourceCache(client.fetchComments),
|
|
67
|
+
files: new ResourceCache(client.fetchPrFiles),
|
|
68
|
+
commits: new ResourceCache(client.fetchPrCommits),
|
|
69
|
+
relatedPrs: new ResourceCache(client.fetchRelatedPrs),
|
|
70
|
+
state: new ResourceCache(client.fetchIssueState),
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
describe('useConsoleItemDetailData', () => {
|
|
75
|
+
it('loads body, files and commits for a PR item', async () => {
|
|
76
|
+
const caches = buildCaches([]);
|
|
77
|
+
const { result } = renderHook(() =>
|
|
78
|
+
useConsoleItemDetailData(caches, prItem),
|
|
79
|
+
);
|
|
80
|
+
await waitFor(() => {
|
|
81
|
+
expect(result.current.body).toBe('body');
|
|
82
|
+
expect(result.current.files.length).toBe(1);
|
|
83
|
+
expect(result.current.commits.length).toBe(1);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('loads related pull request views for an issue item', async () => {
|
|
88
|
+
const related: ConsoleRelatedPullRequest[] = [
|
|
89
|
+
{
|
|
90
|
+
url: 'https://github.com/o/r/pull/9',
|
|
91
|
+
branchName: 'feat',
|
|
92
|
+
createdAt: '2026-06-10T00:00:00.000Z',
|
|
93
|
+
isDraft: false,
|
|
94
|
+
isConflicted: false,
|
|
95
|
+
isPassedAllCiJob: true,
|
|
96
|
+
isCiStateSuccess: true,
|
|
97
|
+
isResolvedAllReviewComments: true,
|
|
98
|
+
isBranchOutOfDate: false,
|
|
99
|
+
missingRequiredCheckNames: [],
|
|
100
|
+
summary: {
|
|
101
|
+
title: 'Linked PR',
|
|
102
|
+
body: 'body',
|
|
103
|
+
additions: 5,
|
|
104
|
+
deletions: 1,
|
|
105
|
+
changedFiles: 2,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
const caches = buildCaches(related);
|
|
110
|
+
const { result } = renderHook(() =>
|
|
111
|
+
useConsoleItemDetailData(caches, issueItem),
|
|
112
|
+
);
|
|
113
|
+
await waitFor(() => {
|
|
114
|
+
expect(result.current.relatedPullRequests.length).toBe(1);
|
|
115
|
+
expect(result.current.relatedPullRequests[0].filesAreLoading).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
expect(result.current.relatedPullRequests[0].files.length).toBe(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('returns defaults when no item is selected', () => {
|
|
121
|
+
const caches = buildCaches([]);
|
|
122
|
+
const { result } = renderHook(() => useConsoleItemDetailData(caches, null));
|
|
123
|
+
expect(result.current.body).toBe('');
|
|
124
|
+
expect(result.current.relatedPullRequests).toEqual([]);
|
|
125
|
+
});
|
|
126
|
+
});
|
package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleItemDetailData.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import type { ConsoleRelatedPullRequestView } from '../components/ConsoleItemDetail';
|
|
3
|
+
import type {
|
|
4
|
+
ConsoleChangedFile,
|
|
5
|
+
ConsoleComment,
|
|
6
|
+
ConsoleCommit,
|
|
7
|
+
ConsoleIssueState,
|
|
8
|
+
ConsoleListItem,
|
|
9
|
+
ConsoleRelatedPullRequest,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import type { ConsoleCaches } from './useConsoleCaches';
|
|
12
|
+
import { useConsoleResource } from './useConsoleResource';
|
|
13
|
+
|
|
14
|
+
const EMPTY_COMMENTS: ConsoleComment[] = [];
|
|
15
|
+
const EMPTY_FILES: ConsoleChangedFile[] = [];
|
|
16
|
+
const EMPTY_COMMITS: ConsoleCommit[] = [];
|
|
17
|
+
const EMPTY_RELATED: ConsoleRelatedPullRequest[] = [];
|
|
18
|
+
const DEFAULT_STATE: ConsoleIssueState = {
|
|
19
|
+
state: 'open',
|
|
20
|
+
merged: false,
|
|
21
|
+
isPullRequest: false,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type ConsoleItemDetailData = {
|
|
25
|
+
state: ConsoleIssueState | null;
|
|
26
|
+
body: string;
|
|
27
|
+
bodyIsLoading: boolean;
|
|
28
|
+
bodyError: string | null;
|
|
29
|
+
comments: ConsoleComment[];
|
|
30
|
+
commentsAreLoading: boolean;
|
|
31
|
+
commentsError: string | null;
|
|
32
|
+
files: ConsoleChangedFile[];
|
|
33
|
+
filesAreLoading: boolean;
|
|
34
|
+
filesError: string | null;
|
|
35
|
+
commits: ConsoleCommit[];
|
|
36
|
+
commitsAreLoading: boolean;
|
|
37
|
+
commitsError: string | null;
|
|
38
|
+
relatedPullRequests: ConsoleRelatedPullRequestView[];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const useConsoleItemDetailData = (
|
|
42
|
+
caches: ConsoleCaches,
|
|
43
|
+
item: ConsoleListItem | null,
|
|
44
|
+
): ConsoleItemDetailData => {
|
|
45
|
+
const key = item !== null ? `${item.repo}#${item.number}` : null;
|
|
46
|
+
const url = item !== null ? item.url : null;
|
|
47
|
+
const isPr = item?.isPr ?? false;
|
|
48
|
+
|
|
49
|
+
const body = useConsoleResource(caches.body, key, url, '');
|
|
50
|
+
const state = useConsoleResource(caches.state, key, url, DEFAULT_STATE);
|
|
51
|
+
const comments = useConsoleResource(
|
|
52
|
+
caches.comments,
|
|
53
|
+
key,
|
|
54
|
+
url,
|
|
55
|
+
EMPTY_COMMENTS,
|
|
56
|
+
);
|
|
57
|
+
const files = useConsoleResource(
|
|
58
|
+
caches.files,
|
|
59
|
+
isPr ? key : null,
|
|
60
|
+
isPr ? url : null,
|
|
61
|
+
EMPTY_FILES,
|
|
62
|
+
);
|
|
63
|
+
const commits = useConsoleResource(
|
|
64
|
+
caches.commits,
|
|
65
|
+
isPr ? key : null,
|
|
66
|
+
isPr ? url : null,
|
|
67
|
+
EMPTY_COMMITS,
|
|
68
|
+
);
|
|
69
|
+
const relatedPrs = useConsoleResource(
|
|
70
|
+
caches.relatedPrs,
|
|
71
|
+
!isPr ? key : null,
|
|
72
|
+
!isPr ? url : null,
|
|
73
|
+
EMPTY_RELATED,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const [relatedViews, setRelatedViews] = useState<
|
|
77
|
+
ConsoleRelatedPullRequestView[]
|
|
78
|
+
>([]);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (isPr || relatedPrs.data.length === 0) {
|
|
82
|
+
setRelatedViews([]);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
let cancelled = false;
|
|
86
|
+
const initial: ConsoleRelatedPullRequestView[] = relatedPrs.data.map(
|
|
87
|
+
(pullRequest) => ({
|
|
88
|
+
pullRequest,
|
|
89
|
+
files: EMPTY_FILES,
|
|
90
|
+
filesAreLoading: true,
|
|
91
|
+
filesError: null,
|
|
92
|
+
commits: EMPTY_COMMITS,
|
|
93
|
+
commitsAreLoading: true,
|
|
94
|
+
commitsError: null,
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
setRelatedViews(initial);
|
|
98
|
+
|
|
99
|
+
const updateView = (
|
|
100
|
+
prUrl: string,
|
|
101
|
+
patch: Partial<ConsoleRelatedPullRequestView>,
|
|
102
|
+
): void => {
|
|
103
|
+
if (cancelled) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
setRelatedViews((current) =>
|
|
107
|
+
current.map((view) =>
|
|
108
|
+
view.pullRequest.url === prUrl ? { ...view, ...patch } : view,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
for (const pullRequest of relatedPrs.data) {
|
|
114
|
+
const relatedKey = pullRequest.url;
|
|
115
|
+
caches.files
|
|
116
|
+
.load(relatedKey, pullRequest.url)
|
|
117
|
+
.then((value) =>
|
|
118
|
+
updateView(pullRequest.url, {
|
|
119
|
+
files: value,
|
|
120
|
+
filesAreLoading: false,
|
|
121
|
+
}),
|
|
122
|
+
)
|
|
123
|
+
.catch((cause: unknown) =>
|
|
124
|
+
updateView(pullRequest.url, {
|
|
125
|
+
filesAreLoading: false,
|
|
126
|
+
filesError: cause instanceof Error ? cause.message : String(cause),
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
caches.commits
|
|
130
|
+
.load(relatedKey, pullRequest.url)
|
|
131
|
+
.then((value) =>
|
|
132
|
+
updateView(pullRequest.url, {
|
|
133
|
+
commits: value,
|
|
134
|
+
commitsAreLoading: false,
|
|
135
|
+
}),
|
|
136
|
+
)
|
|
137
|
+
.catch((cause: unknown) =>
|
|
138
|
+
updateView(pullRequest.url, {
|
|
139
|
+
commitsAreLoading: false,
|
|
140
|
+
commitsError:
|
|
141
|
+
cause instanceof Error ? cause.message : String(cause),
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return () => {
|
|
147
|
+
cancelled = true;
|
|
148
|
+
};
|
|
149
|
+
}, [caches, isPr, relatedPrs.data]);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
state: state.data,
|
|
153
|
+
body: body.data,
|
|
154
|
+
bodyIsLoading: body.isLoading,
|
|
155
|
+
bodyError: body.error,
|
|
156
|
+
comments: comments.data,
|
|
157
|
+
commentsAreLoading: comments.isLoading,
|
|
158
|
+
commentsError: comments.error,
|
|
159
|
+
files: files.data,
|
|
160
|
+
filesAreLoading: files.isLoading,
|
|
161
|
+
filesError: files.error,
|
|
162
|
+
commits: commits.data,
|
|
163
|
+
commitsAreLoading: commits.isLoading,
|
|
164
|
+
commitsError: commits.error,
|
|
165
|
+
relatedPullRequests: relatedViews,
|
|
166
|
+
};
|
|
167
|
+
};
|
package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleOperations.test.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react';
|
|
2
|
+
import {
|
|
3
|
+
consoleListItemsFixture,
|
|
4
|
+
consoleStatusOptionsFixture,
|
|
5
|
+
} from '../fixtures';
|
|
6
|
+
import { overlayStorageKey } from '../overlay';
|
|
7
|
+
import { useConsoleOperations } from './useConsoleOperations';
|
|
8
|
+
import { useConsoleOverlay } from './useConsoleOverlay';
|
|
9
|
+
|
|
10
|
+
const prItem = consoleListItemsFixture[0];
|
|
11
|
+
const issueItem = consoleListItemsFixture[2];
|
|
12
|
+
|
|
13
|
+
const captureFetch = (): jest.Mock => {
|
|
14
|
+
const fetchMock = jest.fn(async () => ({
|
|
15
|
+
ok: true,
|
|
16
|
+
status: 200,
|
|
17
|
+
json: async () => ({ ok: true }),
|
|
18
|
+
}));
|
|
19
|
+
global.fetch = fetchMock as unknown as typeof fetch;
|
|
20
|
+
return fetchMock;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const lastBody = (fetchMock: jest.Mock): Record<string, unknown> =>
|
|
24
|
+
JSON.parse((fetchMock.mock.calls.at(-1)?.[1] as { body: string }).body);
|
|
25
|
+
|
|
26
|
+
const setup = () => {
|
|
27
|
+
localStorage.clear();
|
|
28
|
+
window.history.replaceState({}, '', '/projects/umino/prs?k=token');
|
|
29
|
+
return renderHook(() => {
|
|
30
|
+
const overlay = useConsoleOverlay('umino');
|
|
31
|
+
const operations = useConsoleOperations('umino', 'prs', overlay);
|
|
32
|
+
return { overlay, operations };
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe('useConsoleOperations', () => {
|
|
37
|
+
it('posts a totally wrong review as a close with the totally wrong comment body', async () => {
|
|
38
|
+
const fetchMock = captureFetch();
|
|
39
|
+
const { result } = setup();
|
|
40
|
+
await act(async () => {
|
|
41
|
+
await result.current.operations.reviewPullRequest(
|
|
42
|
+
prItem,
|
|
43
|
+
prItem.url,
|
|
44
|
+
'totally_wrong',
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
expect(fetchMock.mock.calls[0][0]).toBe('/api/review?k=token');
|
|
48
|
+
expect(lastBody(fetchMock)).toMatchObject({
|
|
49
|
+
pjcode: 'umino',
|
|
50
|
+
action: 'close',
|
|
51
|
+
prUrl: prItem.url,
|
|
52
|
+
commentBody: 'totally wrong',
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('posts an unnecessary review as a close with the unnecessary comment body', async () => {
|
|
57
|
+
const fetchMock = captureFetch();
|
|
58
|
+
const { result } = setup();
|
|
59
|
+
await act(async () => {
|
|
60
|
+
await result.current.operations.reviewPullRequest(
|
|
61
|
+
prItem,
|
|
62
|
+
prItem.url,
|
|
63
|
+
'unnecessary',
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
expect(lastBody(fetchMock)).toMatchObject({
|
|
67
|
+
action: 'close',
|
|
68
|
+
commentBody: 'This pull request is unnecessary.',
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('posts an approve review and marks the item done in the overlay', async () => {
|
|
73
|
+
captureFetch();
|
|
74
|
+
const { result } = setup();
|
|
75
|
+
await act(async () => {
|
|
76
|
+
await result.current.operations.reviewPullRequest(
|
|
77
|
+
prItem,
|
|
78
|
+
prItem.url,
|
|
79
|
+
'approve',
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
const stored = JSON.parse(
|
|
83
|
+
localStorage.getItem(overlayStorageKey('umino')) ?? '{}',
|
|
84
|
+
);
|
|
85
|
+
expect(stored[prItem.projectItemId].done).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('posts a not-planned close through the triage endpoint', async () => {
|
|
89
|
+
const fetchMock = captureFetch();
|
|
90
|
+
const { result } = setup();
|
|
91
|
+
await act(async () => {
|
|
92
|
+
await result.current.operations.closeIssue(
|
|
93
|
+
issueItem,
|
|
94
|
+
'close_not_planned',
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
expect(fetchMock.mock.calls[0][0]).toBe('/api/triage?k=token');
|
|
98
|
+
expect(lastBody(fetchMock)).toMatchObject({
|
|
99
|
+
pjcode: 'umino',
|
|
100
|
+
action: 'close_not_planned',
|
|
101
|
+
issueUrl: issueItem.url,
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('posts set_status and records the overlay status', async () => {
|
|
106
|
+
const fetchMock = captureFetch();
|
|
107
|
+
const { result } = setup();
|
|
108
|
+
const option = consoleStatusOptionsFixture[1];
|
|
109
|
+
await act(async () => {
|
|
110
|
+
await result.current.operations.setStatus(issueItem, option);
|
|
111
|
+
});
|
|
112
|
+
expect(lastBody(fetchMock)).toMatchObject({
|
|
113
|
+
action: 'set_status',
|
|
114
|
+
statusName: option.name,
|
|
115
|
+
});
|
|
116
|
+
const stored = JSON.parse(
|
|
117
|
+
localStorage.getItem(overlayStorageKey('umino')) ?? '{}',
|
|
118
|
+
);
|
|
119
|
+
expect(stored[issueItem.projectItemId].status.name).toBe(option.name);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('posts set_intmux through the intmux endpoint', async () => {
|
|
123
|
+
const fetchMock = captureFetch();
|
|
124
|
+
const { result } = setup();
|
|
125
|
+
const option = consoleStatusOptionsFixture[5];
|
|
126
|
+
await act(async () => {
|
|
127
|
+
await result.current.operations.setInTmuxByHuman(issueItem, option);
|
|
128
|
+
});
|
|
129
|
+
expect(fetchMock.mock.calls[0][0]).toBe('/api/intmux?k=token');
|
|
130
|
+
expect(lastBody(fetchMock)).toMatchObject({
|
|
131
|
+
pjcode: 'umino',
|
|
132
|
+
action: 'set_intmux',
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('does not mark done on snooze outside the todo-by-human tab', async () => {
|
|
137
|
+
captureFetch();
|
|
138
|
+
const { result } = setup();
|
|
139
|
+
await act(async () => {
|
|
140
|
+
await result.current.operations.setNextActionDate(
|
|
141
|
+
issueItem,
|
|
142
|
+
'snooze_1day',
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
const stored = JSON.parse(
|
|
146
|
+
localStorage.getItem(overlayStorageKey('umino')) ?? '{}',
|
|
147
|
+
);
|
|
148
|
+
expect(stored[issueItem.projectItemId]?.done).toBeUndefined();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('marks done on snooze in the todo-by-human tab so the item is skipped', async () => {
|
|
152
|
+
captureFetch();
|
|
153
|
+
localStorage.clear();
|
|
154
|
+
window.history.replaceState(
|
|
155
|
+
{},
|
|
156
|
+
'',
|
|
157
|
+
'/projects/umino/todo-by-human?k=token',
|
|
158
|
+
);
|
|
159
|
+
const { result } = renderHook(() => {
|
|
160
|
+
const overlay = useConsoleOverlay('umino');
|
|
161
|
+
const operations = useConsoleOperations(
|
|
162
|
+
'umino',
|
|
163
|
+
'todo-by-human',
|
|
164
|
+
overlay,
|
|
165
|
+
);
|
|
166
|
+
return { overlay, operations };
|
|
167
|
+
});
|
|
168
|
+
await act(async () => {
|
|
169
|
+
await result.current.operations.setNextActionDate(
|
|
170
|
+
issueItem,
|
|
171
|
+
'snooze_1week',
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
const stored = JSON.parse(
|
|
175
|
+
localStorage.getItem(overlayStorageKey('umino')) ?? '{}',
|
|
176
|
+
);
|
|
177
|
+
expect(stored[issueItem.projectItemId].done).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('rejects an operation and posts nothing when no pjcode is available', async () => {
|
|
181
|
+
const fetchMock = captureFetch();
|
|
182
|
+
localStorage.clear();
|
|
183
|
+
window.history.replaceState({}, '', '/?k=token');
|
|
184
|
+
const { result } = renderHook(() => {
|
|
185
|
+
const overlay = useConsoleOverlay('console');
|
|
186
|
+
const operations = useConsoleOperations(null, 'prs', overlay);
|
|
187
|
+
return { overlay, operations };
|
|
188
|
+
});
|
|
189
|
+
await expect(
|
|
190
|
+
result.current.operations.reviewPullRequest(
|
|
191
|
+
prItem,
|
|
192
|
+
prItem.url,
|
|
193
|
+
'approve',
|
|
194
|
+
),
|
|
195
|
+
).rejects.toThrow('No project specified in the URL path.');
|
|
196
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
197
|
+
});
|
|
198
|
+
});
|