github-issue-tower-defence-management 2.4.0 → 2.5.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.
- package/CHANGELOG.md +20 -0
- package/bin/adapter/entry-points/console/ui-dist/assets/{index-C5cOzhyn.js → index-CaxYBHiT.js} +1 -1
- package/bin/adapter/entry-points/console/ui-dist/index.html +1 -1
- package/bin/adapter/entry-points/handlers/HandleScheduledEventUseCaseHandler.js +13 -3
- package/bin/adapter/entry-points/handlers/HandleScheduledEventUseCaseHandler.js.map +1 -1
- package/bin/adapter/entry-points/handlers/subscriptionDisabledTokenHandler.js +27 -0
- package/bin/adapter/entry-points/handlers/subscriptionDisabledTokenHandler.js.map +1 -0
- package/bin/domain/usecases/HandleScheduledEventUseCase.js +1 -11
- package/bin/domain/usecases/HandleScheduledEventUseCase.js.map +1 -1
- package/bin/domain/usecases/SubscriptionDisabledIssueUseCase.js +42 -0
- package/bin/domain/usecases/SubscriptionDisabledIssueUseCase.js.map +1 -0
- package/bin/domain/usecases/TriagerApprovalDispatchUseCase.js +9 -4
- package/bin/domain/usecases/TriagerApprovalDispatchUseCase.js.map +1 -1
- package/package.json +1 -1
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleOperations.test.ts +140 -0
- package/src/adapter/entry-points/console/ui/src/features/console/hooks/useConsoleOperations.ts +21 -19
- package/src/adapter/entry-points/console/ui-dist/assets/{index-C5cOzhyn.js → index-CaxYBHiT.js} +1 -1
- package/src/adapter/entry-points/console/ui-dist/index.html +1 -1
- package/src/adapter/entry-points/handlers/HandleScheduledEventUseCaseHandler.test.ts +0 -8
- package/src/adapter/entry-points/handlers/HandleScheduledEventUseCaseHandler.ts +17 -4
- package/src/adapter/entry-points/handlers/subscriptionDisabledTokenHandler.ts +41 -0
- package/src/adapter/repositories/githubGraphqlClient.test.ts +2 -2
- package/src/domain/usecases/HandleScheduledEventUseCase.test.ts +0 -56
- package/src/domain/usecases/HandleScheduledEventUseCase.ts +0 -13
- package/src/domain/usecases/SubscriptionDisabledIssueUseCase.test.ts +197 -0
- package/src/domain/usecases/SubscriptionDisabledIssueUseCase.ts +74 -0
- package/src/domain/usecases/TriagerApprovalDispatchUseCase.test.ts +83 -0
- package/src/domain/usecases/TriagerApprovalDispatchUseCase.ts +12 -4
- package/types/adapter/entry-points/handlers/HandleScheduledEventUseCaseHandler.d.ts.map +1 -1
- package/types/adapter/entry-points/handlers/subscriptionDisabledTokenHandler.d.ts +9 -0
- package/types/adapter/entry-points/handlers/subscriptionDisabledTokenHandler.d.ts.map +1 -0
- package/types/domain/usecases/HandleScheduledEventUseCase.d.ts +1 -4
- package/types/domain/usecases/HandleScheduledEventUseCase.d.ts.map +1 -1
- package/types/domain/usecases/SubscriptionDisabledIssueUseCase.d.ts +16 -0
- package/types/domain/usecases/SubscriptionDisabledIssueUseCase.d.ts.map +1 -0
- package/types/domain/usecases/TriagerApprovalDispatchUseCase.d.ts.map +1 -1
- package/src/domain/usecases/ConvertCheckboxToIssueInStoryIssueUseCase.test.ts +0 -1638
- package/src/domain/usecases/ConvertCheckboxToIssueInStoryIssueUseCase.ts +0 -192
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>TDPM Console</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-CaxYBHiT.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-CLHvrafO.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
@@ -83,14 +83,6 @@ jest.mock(
|
|
|
83
83
|
jest.mock('../../../domain/usecases/CreateEstimationIssueUseCase', () => ({
|
|
84
84
|
CreateEstimationIssueUseCase: jest.fn().mockImplementation(() => ({})),
|
|
85
85
|
}));
|
|
86
|
-
jest.mock(
|
|
87
|
-
'../../../domain/usecases/ConvertCheckboxToIssueInStoryIssueUseCase',
|
|
88
|
-
() => ({
|
|
89
|
-
ConvertCheckboxToIssueInStoryIssueUseCase: jest
|
|
90
|
-
.fn()
|
|
91
|
-
.mockImplementation(() => ({})),
|
|
92
|
-
}),
|
|
93
|
-
);
|
|
94
86
|
jest.mock('../../../domain/usecases/ChangeStatusByStoryColorUseCase', () => ({
|
|
95
87
|
ChangeStatusByStoryColorUseCase: jest.fn().mockImplementation(() => ({})),
|
|
96
88
|
}));
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { writeDashboardRow } from './dashboardRowWriter';
|
|
11
11
|
import { writeMachineStatus } from './machineStatusWriter';
|
|
12
12
|
import { writeTokenStatus } from './tokenStatusWriter';
|
|
13
|
+
import { handleSubscriptionDisabledTokens } from './subscriptionDisabledTokenHandler';
|
|
13
14
|
import { writeInTmuxByHumanData } from './inTmuxByHumanDataWriter';
|
|
14
15
|
import { cleanClosedIssueOwnerCallFiles } from './ownerCallFileCleaner';
|
|
15
16
|
import { reconcileInTmuxByHumanSessions } from './inTmuxByHumanSessionReconciler';
|
|
@@ -59,7 +60,6 @@ import { ClearDependedIssueURLUseCase } from '../../../domain/usecases/ClearDepe
|
|
|
59
60
|
import { SetDependedIssueUrlForOpenTaskPRsUseCase } from '../../../domain/usecases/SetDependedIssueUrlForOpenTaskPRsUseCase';
|
|
60
61
|
import { StaleTaskPullRequestCloseUseCase } from '../../../domain/usecases/StaleTaskPullRequestCloseUseCase';
|
|
61
62
|
import { CreateEstimationIssueUseCase } from '../../../domain/usecases/CreateEstimationIssueUseCase';
|
|
62
|
-
import { ConvertCheckboxToIssueInStoryIssueUseCase } from '../../../domain/usecases/ConvertCheckboxToIssueInStoryIssueUseCase';
|
|
63
63
|
import { ChangeStatusByStoryColorUseCase } from '../../../domain/usecases/ChangeStatusByStoryColorUseCase';
|
|
64
64
|
import { SetNoStoryIssueToStoryUseCase } from '../../../domain/usecases/SetNoStoryIssueToStoryUseCase';
|
|
65
65
|
import { CreateNewStoryByLabelUseCase } from '../../../domain/usecases/CreateNewStoryByLabelUseCase';
|
|
@@ -463,8 +463,6 @@ export class HandleScheduledEventUseCaseHandler {
|
|
|
463
463
|
issueRepository,
|
|
464
464
|
systemDateRepository,
|
|
465
465
|
);
|
|
466
|
-
const convertCheckboxToIssueInStoryIssueUseCase =
|
|
467
|
-
new ConvertCheckboxToIssueInStoryIssueUseCase(issueRepository);
|
|
468
466
|
const changeStatusByStoryColorUseCase = new ChangeStatusByStoryColorUseCase(
|
|
469
467
|
systemDateRepository,
|
|
470
468
|
issueRepository,
|
|
@@ -560,7 +558,6 @@ export class HandleScheduledEventUseCaseHandler {
|
|
|
560
558
|
setDependedIssueUrlForOpenTaskPRsUseCase,
|
|
561
559
|
staleTaskPullRequestCloseUseCase,
|
|
562
560
|
createEstimationIssueUseCase,
|
|
563
|
-
convertCheckboxToIssueInStoryIssueUseCase,
|
|
564
561
|
changeStatusByStoryColorUseCase,
|
|
565
562
|
setNoStoryIssueToStoryUseCase,
|
|
566
563
|
createNewStoryByLabel,
|
|
@@ -694,6 +691,22 @@ export class HandleScheduledEventUseCaseHandler {
|
|
|
694
691
|
);
|
|
695
692
|
}
|
|
696
693
|
|
|
694
|
+
try {
|
|
695
|
+
await handleSubscriptionDisabledTokens({
|
|
696
|
+
tokenListJsonPath:
|
|
697
|
+
mergedInput.claudeCodeOauthTokenListJsonPath ?? null,
|
|
698
|
+
org: input.org,
|
|
699
|
+
repo: input.workingReport.repo,
|
|
700
|
+
issueRepository,
|
|
701
|
+
});
|
|
702
|
+
} catch (error) {
|
|
703
|
+
console.error(
|
|
704
|
+
`Failed to handle subscription disabled tokens: ${
|
|
705
|
+
error instanceof Error ? error.message : String(error)
|
|
706
|
+
}`,
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
|
|
697
710
|
const inTmuxNow = new Date();
|
|
698
711
|
|
|
699
712
|
const inTmuxGetuid = process.getuid?.bind(process);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IssueRepository } from '../../../domain/usecases/adapter-interfaces/IssueRepository';
|
|
2
|
+
import { SubscriptionDisabledIssueUseCase } from '../../../domain/usecases/SubscriptionDisabledIssueUseCase';
|
|
3
|
+
import { loadTokenEntries } from '../../proxy/TokenListLoader';
|
|
4
|
+
import { readRateLimit } from '../../proxy/RateLimitCache';
|
|
5
|
+
|
|
6
|
+
export type SubscriptionDisabledTokenHandlerParams = {
|
|
7
|
+
tokenListJsonPath: string | null;
|
|
8
|
+
org: string;
|
|
9
|
+
repo: string;
|
|
10
|
+
issueRepository: Pick<
|
|
11
|
+
IssueRepository,
|
|
12
|
+
'searchIssue' | 'createNewIssue' | 'createCommentByUrl'
|
|
13
|
+
>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const handleSubscriptionDisabledTokens = async (
|
|
17
|
+
params: SubscriptionDisabledTokenHandlerParams,
|
|
18
|
+
): Promise<void> => {
|
|
19
|
+
const { tokenListJsonPath, org, repo, issueRepository } = params;
|
|
20
|
+
|
|
21
|
+
if (tokenListJsonPath === null) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const entries = loadTokenEntries(tokenListJsonPath);
|
|
26
|
+
if (entries === null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const tokenEntries = entries.map((entry) => ({
|
|
31
|
+
name: entry.name,
|
|
32
|
+
subscriptionDisabled:
|
|
33
|
+
readRateLimit(entry.token)?.subscriptionDisabled ?? false,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
await new SubscriptionDisabledIssueUseCase(issueRepository).run({
|
|
37
|
+
tokenEntries,
|
|
38
|
+
org,
|
|
39
|
+
repo,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -126,12 +126,12 @@ describe('githubGraphqlClient', () => {
|
|
|
126
126
|
' at postGithubGraphqlJson (/app/bin/adapter/repositories/githubGraphqlClient.js:120:22)',
|
|
127
127
|
' at GraphqlProjectItemRepository.fetchProjectItemByUrl (/app/bin/adapter/repositories/issue/GraphqlProjectItemRepository.js:1042:11)',
|
|
128
128
|
' at ApiV3CheerioRestIssueRepository.getIssueByUrl (/app/bin/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.js:813:11)',
|
|
129
|
-
' at async
|
|
129
|
+
' at async ChangeStatusByStoryColorUseCase.run (/app/bin/domain/usecases/ChangeStatusByStoryColorUseCase.js:63:31)',
|
|
130
130
|
' at async HandleScheduledEventUseCase.runSlowSweepUseCases (/app/bin/domain/usecases/HandleScheduledEventUseCase.js:552:5)',
|
|
131
131
|
].join('\n');
|
|
132
132
|
|
|
133
133
|
expect(extractGraphqlCallSite(stack)).toBe(
|
|
134
|
-
'GraphqlProjectItemRepository<-ApiV3CheerioRestIssueRepository<-
|
|
134
|
+
'GraphqlProjectItemRepository<-ApiV3CheerioRestIssueRepository<-ChangeStatusByStoryColorUseCase',
|
|
135
135
|
);
|
|
136
136
|
});
|
|
137
137
|
|
|
@@ -9,7 +9,6 @@ import { ClearDependedIssueURLUseCase } from './ClearDependedIssueURLUseCase';
|
|
|
9
9
|
import { SetDependedIssueUrlForOpenTaskPRsUseCase } from './SetDependedIssueUrlForOpenTaskPRsUseCase';
|
|
10
10
|
import { StaleTaskPullRequestCloseUseCase } from './StaleTaskPullRequestCloseUseCase';
|
|
11
11
|
import { CreateEstimationIssueUseCase } from './CreateEstimationIssueUseCase';
|
|
12
|
-
import { ConvertCheckboxToIssueInStoryIssueUseCase } from './ConvertCheckboxToIssueInStoryIssueUseCase';
|
|
13
12
|
import { DateRepository } from './adapter-interfaces/DateRepository';
|
|
14
13
|
import { SpreadsheetRepository } from './adapter-interfaces/SpreadsheetRepository';
|
|
15
14
|
import { ProjectRepository } from './adapter-interfaces/ProjectRepository';
|
|
@@ -112,8 +111,6 @@ describe('HandleScheduledEventUseCase', () => {
|
|
|
112
111
|
mock<StaleTaskPullRequestCloseUseCase>();
|
|
113
112
|
const mockCreateEstimationIssueUseCase =
|
|
114
113
|
mock<CreateEstimationIssueUseCase>();
|
|
115
|
-
const mockConvertCheckboxToIssueInStoryIssueUseCase =
|
|
116
|
-
mock<ConvertCheckboxToIssueInStoryIssueUseCase>();
|
|
117
114
|
const mockChangeStatusByStoryColorUseCase =
|
|
118
115
|
mock<ChangeStatusByStoryColorUseCase>();
|
|
119
116
|
const mockSetNoStoryIssueToStoryUseCase =
|
|
@@ -158,7 +155,6 @@ describe('HandleScheduledEventUseCase', () => {
|
|
|
158
155
|
mockSetDependedIssueUrlForOpenTaskPRsUseCase,
|
|
159
156
|
mockStaleTaskPullRequestCloseUseCase,
|
|
160
157
|
mockCreateEstimationIssueUseCase,
|
|
161
|
-
mockConvertCheckboxToIssueInStoryIssueUseCase,
|
|
162
158
|
mockChangeStatusByStoryColorUseCase,
|
|
163
159
|
mockSetNoStoryIssueToStoryUseCase,
|
|
164
160
|
mockCreateNewStoryByLabelUseCase,
|
|
@@ -353,57 +349,6 @@ describe('HandleScheduledEventUseCase', () => {
|
|
|
353
349
|
expect(mockProjectRepository.findProjectIdByUrl).toHaveBeenCalled();
|
|
354
350
|
});
|
|
355
351
|
|
|
356
|
-
it('should pass createTaskFromStoryBodyCheckboxEnabled false to ConvertCheckboxToIssueInStoryIssueUseCase when the field is absent', async () => {
|
|
357
|
-
const input = {
|
|
358
|
-
projectName: 'test-project',
|
|
359
|
-
org: 'test-org',
|
|
360
|
-
projectUrl: 'https://github.com/test-org/test-project',
|
|
361
|
-
manager: 'test-manager',
|
|
362
|
-
workingReport: {
|
|
363
|
-
repo: 'test-repo',
|
|
364
|
-
members: ['member1'],
|
|
365
|
-
spreadsheetUrl: 'https://docs.google.com/spreadsheets/test',
|
|
366
|
-
},
|
|
367
|
-
urlOfStoryView: 'https://github.com/test-org/test-project/issues',
|
|
368
|
-
disabled: false,
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
await useCase.run(input);
|
|
372
|
-
expect(
|
|
373
|
-
mockConvertCheckboxToIssueInStoryIssueUseCase.run,
|
|
374
|
-
).toHaveBeenCalledWith(
|
|
375
|
-
expect.objectContaining({
|
|
376
|
-
createTaskFromStoryBodyCheckboxEnabled: false,
|
|
377
|
-
}),
|
|
378
|
-
);
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it('should pass createTaskFromStoryBodyCheckboxEnabled true to ConvertCheckboxToIssueInStoryIssueUseCase when the field is true', async () => {
|
|
382
|
-
const input = {
|
|
383
|
-
projectName: 'test-project',
|
|
384
|
-
org: 'test-org',
|
|
385
|
-
projectUrl: 'https://github.com/test-org/test-project',
|
|
386
|
-
manager: 'test-manager',
|
|
387
|
-
workingReport: {
|
|
388
|
-
repo: 'test-repo',
|
|
389
|
-
members: ['member1'],
|
|
390
|
-
spreadsheetUrl: 'https://docs.google.com/spreadsheets/test',
|
|
391
|
-
},
|
|
392
|
-
urlOfStoryView: 'https://github.com/test-org/test-project/issues',
|
|
393
|
-
disabled: false,
|
|
394
|
-
createTaskFromStoryBodyCheckboxEnabled: true,
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
await useCase.run(input);
|
|
398
|
-
expect(
|
|
399
|
-
mockConvertCheckboxToIssueInStoryIssueUseCase.run,
|
|
400
|
-
).toHaveBeenCalledWith(
|
|
401
|
-
expect.objectContaining({
|
|
402
|
-
createTaskFromStoryBodyCheckboxEnabled: true,
|
|
403
|
-
}),
|
|
404
|
-
);
|
|
405
|
-
});
|
|
406
|
-
|
|
407
352
|
it('should pass storyProgressCommentEnabled true to AnalyzeProblemByIssueUseCase when the field is absent', async () => {
|
|
408
353
|
const input = {
|
|
409
354
|
projectName: 'test-project',
|
|
@@ -1872,7 +1817,6 @@ describe('HandleScheduledEventUseCase', () => {
|
|
|
1872
1817
|
mock<SetDependedIssueUrlForOpenTaskPRsUseCase>(),
|
|
1873
1818
|
mock<StaleTaskPullRequestCloseUseCase>(),
|
|
1874
1819
|
mock<CreateEstimationIssueUseCase>(),
|
|
1875
|
-
mock<ConvertCheckboxToIssueInStoryIssueUseCase>(),
|
|
1876
1820
|
mock<ChangeStatusByStoryColorUseCase>(),
|
|
1877
1821
|
mock<SetNoStoryIssueToStoryUseCase>(),
|
|
1878
1822
|
mock<CreateNewStoryByLabelUseCase>(),
|
|
@@ -15,7 +15,6 @@ import { ClearDependedIssueURLUseCase } from './ClearDependedIssueURLUseCase';
|
|
|
15
15
|
import { SetDependedIssueUrlForOpenTaskPRsUseCase } from './SetDependedIssueUrlForOpenTaskPRsUseCase';
|
|
16
16
|
import { StaleTaskPullRequestCloseUseCase } from './StaleTaskPullRequestCloseUseCase';
|
|
17
17
|
import { CreateEstimationIssueUseCase } from './CreateEstimationIssueUseCase';
|
|
18
|
-
import { ConvertCheckboxToIssueInStoryIssueUseCase } from './ConvertCheckboxToIssueInStoryIssueUseCase';
|
|
19
18
|
import { ChangeStatusByStoryColorUseCase } from './ChangeStatusByStoryColorUseCase';
|
|
20
19
|
import { SetNoStoryIssueToStoryUseCase } from './SetNoStoryIssueToStoryUseCase';
|
|
21
20
|
import { CreateNewStoryByLabelUseCase } from './CreateNewStoryByLabelUseCase';
|
|
@@ -130,7 +129,6 @@ export class HandleScheduledEventUseCase {
|
|
|
130
129
|
readonly setDependedIssueUrlForOpenTaskPRsUseCase: SetDependedIssueUrlForOpenTaskPRsUseCase,
|
|
131
130
|
readonly staleTaskPullRequestCloseUseCase: StaleTaskPullRequestCloseUseCase,
|
|
132
131
|
readonly createEstimationIssueUseCase: CreateEstimationIssueUseCase,
|
|
133
|
-
readonly convertCheckboxToIssueInStoryIssueUseCase: ConvertCheckboxToIssueInStoryIssueUseCase,
|
|
134
132
|
readonly changeStatusByStoryColorUseCase: ChangeStatusByStoryColorUseCase,
|
|
135
133
|
readonly setNoStoryIssueToStoryUseCase: SetNoStoryIssueToStoryUseCase,
|
|
136
134
|
readonly createNewStoryByLabelUseCase: CreateNewStoryByLabelUseCase,
|
|
@@ -191,7 +189,6 @@ export class HandleScheduledEventUseCase {
|
|
|
191
189
|
} | null;
|
|
192
190
|
thresholdForAutoReject?: number;
|
|
193
191
|
thresholdForDispatchLoop?: number;
|
|
194
|
-
createTaskFromStoryBodyCheckboxEnabled?: boolean;
|
|
195
192
|
queryToAddProjectEnabled?: boolean;
|
|
196
193
|
queryToAddProject?: string | null;
|
|
197
194
|
storyProgressCommentEnabled?: boolean;
|
|
@@ -615,16 +612,6 @@ ${JSON.stringify(e)}
|
|
|
615
612
|
urlOfStoryView: input.urlOfStoryView,
|
|
616
613
|
storyObjectMap: storyObjectMap,
|
|
617
614
|
});
|
|
618
|
-
await this.convertCheckboxToIssueInStoryIssueUseCase.run({
|
|
619
|
-
project,
|
|
620
|
-
issues,
|
|
621
|
-
cacheUsed,
|
|
622
|
-
urlOfStoryView: input.urlOfStoryView,
|
|
623
|
-
storyObjectMap: storyObjectMap,
|
|
624
|
-
manager: input.manager,
|
|
625
|
-
createTaskFromStoryBodyCheckboxEnabled:
|
|
626
|
-
input.createTaskFromStoryBodyCheckboxEnabled ?? false,
|
|
627
|
-
});
|
|
628
615
|
await this.changeStatusByStoryColorUseCase.run({
|
|
629
616
|
project,
|
|
630
617
|
cacheUsed,
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { mock } from 'jest-mock-extended';
|
|
2
|
+
import { IssueRepository } from './adapter-interfaces/IssueRepository';
|
|
3
|
+
import { SubscriptionDisabledIssueUseCase } from './SubscriptionDisabledIssueUseCase';
|
|
4
|
+
|
|
5
|
+
const ORG = 'test-org';
|
|
6
|
+
const REPO = 'test-repo';
|
|
7
|
+
|
|
8
|
+
const buildEntry = (name: string, subscriptionDisabled: boolean) => ({
|
|
9
|
+
name,
|
|
10
|
+
subscriptionDisabled,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('SubscriptionDisabledIssueUseCase', () => {
|
|
14
|
+
describe('when no tokens are disabled', () => {
|
|
15
|
+
it('does not create any issue or comment', async () => {
|
|
16
|
+
const mockIssueRepository = mock<IssueRepository>();
|
|
17
|
+
|
|
18
|
+
const useCase = new SubscriptionDisabledIssueUseCase(mockIssueRepository);
|
|
19
|
+
|
|
20
|
+
await useCase.run({
|
|
21
|
+
tokenEntries: [buildEntry('dev1', false), buildEntry('dev2', false)],
|
|
22
|
+
org: ORG,
|
|
23
|
+
repo: REPO,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(mockIssueRepository.searchIssue.mock.calls).toHaveLength(0);
|
|
27
|
+
expect(mockIssueRepository.createNewIssue.mock.calls).toHaveLength(0);
|
|
28
|
+
expect(mockIssueRepository.createCommentByUrl.mock.calls).toHaveLength(0);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('when a token is disabled and no open issue exists', () => {
|
|
33
|
+
it('creates a new issue naming the token by display name only', async () => {
|
|
34
|
+
const mockIssueRepository = mock<IssueRepository>();
|
|
35
|
+
mockIssueRepository.searchIssue.mockResolvedValue([]);
|
|
36
|
+
mockIssueRepository.createNewIssue.mockResolvedValue(42);
|
|
37
|
+
|
|
38
|
+
const useCase = new SubscriptionDisabledIssueUseCase(mockIssueRepository);
|
|
39
|
+
|
|
40
|
+
await useCase.run({
|
|
41
|
+
tokenEntries: [buildEntry('dev3', true)],
|
|
42
|
+
org: ORG,
|
|
43
|
+
repo: REPO,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(mockIssueRepository.searchIssue.mock.calls).toHaveLength(1);
|
|
47
|
+
expect(mockIssueRepository.searchIssue.mock.calls[0][0]).toEqual({
|
|
48
|
+
owner: ORG,
|
|
49
|
+
repositoryName: REPO,
|
|
50
|
+
type: 'issue',
|
|
51
|
+
state: 'open',
|
|
52
|
+
title: 'Restore Claude subscription access for dev3',
|
|
53
|
+
});
|
|
54
|
+
expect(mockIssueRepository.createNewIssue.mock.calls).toHaveLength(1);
|
|
55
|
+
expect(mockIssueRepository.createNewIssue.mock.calls[0][0]).toBe(ORG);
|
|
56
|
+
expect(mockIssueRepository.createNewIssue.mock.calls[0][1]).toBe(REPO);
|
|
57
|
+
expect(mockIssueRepository.createNewIssue.mock.calls[0][2]).toBe(
|
|
58
|
+
'Restore Claude subscription access for dev3',
|
|
59
|
+
);
|
|
60
|
+
expect(mockIssueRepository.createNewIssue.mock.calls[0][3]).toContain(
|
|
61
|
+
'dev3',
|
|
62
|
+
);
|
|
63
|
+
expect(mockIssueRepository.createCommentByUrl.mock.calls).toHaveLength(0);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('does not include the token value in the issue body', async () => {
|
|
67
|
+
const mockIssueRepository = mock<IssueRepository>();
|
|
68
|
+
mockIssueRepository.searchIssue.mockResolvedValue([]);
|
|
69
|
+
mockIssueRepository.createNewIssue.mockResolvedValue(1);
|
|
70
|
+
|
|
71
|
+
const useCase = new SubscriptionDisabledIssueUseCase(mockIssueRepository);
|
|
72
|
+
|
|
73
|
+
const SECRET_TOKEN = 'sk-ant-secret-abc123';
|
|
74
|
+
await useCase.run({
|
|
75
|
+
tokenEntries: [{ name: 'dev3', subscriptionDisabled: true }],
|
|
76
|
+
org: ORG,
|
|
77
|
+
repo: REPO,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(mockIssueRepository.createNewIssue.mock.calls[0][3]).not.toContain(
|
|
81
|
+
SECRET_TOKEN,
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('when a token is disabled and an open issue already exists', () => {
|
|
87
|
+
it('comments on the existing issue instead of creating a new one', async () => {
|
|
88
|
+
const mockIssueRepository = mock<IssueRepository>();
|
|
89
|
+
const existingIssueUrl =
|
|
90
|
+
'https://github.com/test-org/test-repo/issues/99';
|
|
91
|
+
mockIssueRepository.searchIssue.mockResolvedValue([
|
|
92
|
+
{
|
|
93
|
+
url: existingIssueUrl,
|
|
94
|
+
title: 'Restore Claude subscription access for dev3',
|
|
95
|
+
number: '99',
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
const useCase = new SubscriptionDisabledIssueUseCase(mockIssueRepository);
|
|
100
|
+
|
|
101
|
+
await useCase.run({
|
|
102
|
+
tokenEntries: [buildEntry('dev3', true)],
|
|
103
|
+
org: ORG,
|
|
104
|
+
repo: REPO,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(mockIssueRepository.createNewIssue.mock.calls).toHaveLength(0);
|
|
108
|
+
expect(mockIssueRepository.createCommentByUrl.mock.calls).toHaveLength(1);
|
|
109
|
+
expect(mockIssueRepository.createCommentByUrl.mock.calls[0][0]).toBe(
|
|
110
|
+
existingIssueUrl,
|
|
111
|
+
);
|
|
112
|
+
expect(mockIssueRepository.createCommentByUrl.mock.calls[0][1]).toContain(
|
|
113
|
+
'dev3',
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('when multiple tokens have different states', () => {
|
|
119
|
+
it('only handles disabled tokens', async () => {
|
|
120
|
+
const mockIssueRepository = mock<IssueRepository>();
|
|
121
|
+
mockIssueRepository.searchIssue.mockResolvedValue([]);
|
|
122
|
+
mockIssueRepository.createNewIssue.mockResolvedValue(1);
|
|
123
|
+
|
|
124
|
+
const useCase = new SubscriptionDisabledIssueUseCase(mockIssueRepository);
|
|
125
|
+
|
|
126
|
+
await useCase.run({
|
|
127
|
+
tokenEntries: [
|
|
128
|
+
buildEntry('dev1', false),
|
|
129
|
+
buildEntry('dev2', true),
|
|
130
|
+
buildEntry('dev3', false),
|
|
131
|
+
buildEntry('dev4', true),
|
|
132
|
+
],
|
|
133
|
+
org: ORG,
|
|
134
|
+
repo: REPO,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(mockIssueRepository.searchIssue.mock.calls).toHaveLength(2);
|
|
138
|
+
expect(mockIssueRepository.createNewIssue.mock.calls).toHaveLength(2);
|
|
139
|
+
expect(mockIssueRepository.searchIssue.mock.calls[0][0]).toEqual(
|
|
140
|
+
expect.objectContaining({
|
|
141
|
+
title: 'Restore Claude subscription access for dev2',
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
expect(mockIssueRepository.searchIssue.mock.calls[1][0]).toEqual(
|
|
145
|
+
expect.objectContaining({
|
|
146
|
+
title: 'Restore Claude subscription access for dev4',
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('when the token list is empty', () => {
|
|
153
|
+
it('does nothing', async () => {
|
|
154
|
+
const mockIssueRepository = mock<IssueRepository>();
|
|
155
|
+
|
|
156
|
+
const useCase = new SubscriptionDisabledIssueUseCase(mockIssueRepository);
|
|
157
|
+
|
|
158
|
+
await useCase.run({
|
|
159
|
+
tokenEntries: [],
|
|
160
|
+
org: ORG,
|
|
161
|
+
repo: REPO,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(mockIssueRepository.searchIssue.mock.calls).toHaveLength(0);
|
|
165
|
+
expect(mockIssueRepository.createNewIssue.mock.calls).toHaveLength(0);
|
|
166
|
+
expect(mockIssueRepository.createCommentByUrl.mock.calls).toHaveLength(0);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('when searchIssue returns issues but none with exact title match', () => {
|
|
171
|
+
it('creates a new issue when title does not exactly match', async () => {
|
|
172
|
+
const mockIssueRepository = mock<IssueRepository>();
|
|
173
|
+
mockIssueRepository.searchIssue.mockResolvedValue([
|
|
174
|
+
{
|
|
175
|
+
url: 'https://github.com/test-org/test-repo/issues/5',
|
|
176
|
+
title: 'Restore Claude subscription access for dev3-old',
|
|
177
|
+
number: '5',
|
|
178
|
+
},
|
|
179
|
+
]);
|
|
180
|
+
mockIssueRepository.createNewIssue.mockResolvedValue(6);
|
|
181
|
+
|
|
182
|
+
const useCase = new SubscriptionDisabledIssueUseCase(mockIssueRepository);
|
|
183
|
+
|
|
184
|
+
await useCase.run({
|
|
185
|
+
tokenEntries: [buildEntry('dev3', true)],
|
|
186
|
+
org: ORG,
|
|
187
|
+
repo: REPO,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
expect(mockIssueRepository.createNewIssue.mock.calls).toHaveLength(1);
|
|
191
|
+
expect(mockIssueRepository.createNewIssue.mock.calls[0][2]).toBe(
|
|
192
|
+
'Restore Claude subscription access for dev3',
|
|
193
|
+
);
|
|
194
|
+
expect(mockIssueRepository.createCommentByUrl.mock.calls).toHaveLength(0);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { IssueRepository } from './adapter-interfaces/IssueRepository';
|
|
2
|
+
|
|
3
|
+
export type SubscriptionDisabledTokenEntry = {
|
|
4
|
+
name: string;
|
|
5
|
+
subscriptionDisabled: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export class SubscriptionDisabledIssueUseCase {
|
|
9
|
+
constructor(
|
|
10
|
+
private readonly issueRepository: Pick<
|
|
11
|
+
IssueRepository,
|
|
12
|
+
'searchIssue' | 'createNewIssue' | 'createCommentByUrl'
|
|
13
|
+
>,
|
|
14
|
+
) {}
|
|
15
|
+
|
|
16
|
+
run = async (input: {
|
|
17
|
+
tokenEntries: SubscriptionDisabledTokenEntry[];
|
|
18
|
+
org: string;
|
|
19
|
+
repo: string;
|
|
20
|
+
}): Promise<void> => {
|
|
21
|
+
for (const entry of input.tokenEntries) {
|
|
22
|
+
if (!entry.subscriptionDisabled) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
await this.handleDisabledToken(entry.name, input.org, input.repo);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(
|
|
29
|
+
`SubscriptionDisabledIssue: error handling token ${entry.name}: ${error instanceof Error ? error.message : String(error)}`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
private handleDisabledToken = async (
|
|
36
|
+
tokenName: string,
|
|
37
|
+
org: string,
|
|
38
|
+
repo: string,
|
|
39
|
+
): Promise<void> => {
|
|
40
|
+
const issueTitle = `Restore Claude subscription access for ${tokenName}`;
|
|
41
|
+
const existingIssues = await this.issueRepository.searchIssue({
|
|
42
|
+
owner: org,
|
|
43
|
+
repositoryName: repo,
|
|
44
|
+
type: 'issue',
|
|
45
|
+
state: 'open',
|
|
46
|
+
title: issueTitle,
|
|
47
|
+
});
|
|
48
|
+
const existingIssue = existingIssues.find(
|
|
49
|
+
(issue) => issue.title === issueTitle,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (existingIssue) {
|
|
53
|
+
await this.issueRepository.createCommentByUrl(
|
|
54
|
+
existingIssue.url,
|
|
55
|
+
`The Claude subscription access for the token displayed as \`${tokenName}\` remains disabled. Please restore the account's Claude Code subscription access.`,
|
|
56
|
+
);
|
|
57
|
+
console.log(
|
|
58
|
+
`SubscriptionDisabledIssue: commented on existing issue for token ${tokenName}: ${existingIssue.url}`,
|
|
59
|
+
);
|
|
60
|
+
} else {
|
|
61
|
+
const issueNumber = await this.issueRepository.createNewIssue(
|
|
62
|
+
org,
|
|
63
|
+
repo,
|
|
64
|
+
issueTitle,
|
|
65
|
+
`The Claude subscription access for the token displayed as \`${tokenName}\` has been disabled.\n\nPlease restore the account's Claude Code subscription access to resume operations.`,
|
|
66
|
+
[],
|
|
67
|
+
[],
|
|
68
|
+
);
|
|
69
|
+
console.log(
|
|
70
|
+
`SubscriptionDisabledIssue: created issue #${issueNumber} for token ${tokenName}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -964,5 +964,88 @@ describe('TriagerApprovalDispatchUseCase', () => {
|
|
|
964
964
|
expect(mockIssueRepository.updateStory.mock.calls).toEqual([]);
|
|
965
965
|
expect(mockIssueRepository.setIssueAgentField.mock.calls).toHaveLength(1);
|
|
966
966
|
});
|
|
967
|
+
|
|
968
|
+
it('should not dispatch again when TRIAGER_PROPOSAL_APPROVED was already posted after the approval', async () => {
|
|
969
|
+
const issue = createMockIssue({
|
|
970
|
+
status: 'Awaiting Workspace',
|
|
971
|
+
author: 'owner-user',
|
|
972
|
+
agent: null,
|
|
973
|
+
});
|
|
974
|
+
mockIssueRepository.getAllIssues.mockResolvedValue({
|
|
975
|
+
project: mockProject,
|
|
976
|
+
issues: [issue],
|
|
977
|
+
cacheUsed: false,
|
|
978
|
+
});
|
|
979
|
+
mockIssueCommentRepository.getCommentsFromIssue.mockResolvedValue([
|
|
980
|
+
createComment(
|
|
981
|
+
'bot',
|
|
982
|
+
TRIAGER_PROPOSAL_COMMENT(
|
|
983
|
+
'developer',
|
|
984
|
+
'regular / workflow improvement',
|
|
985
|
+
false,
|
|
986
|
+
),
|
|
987
|
+
),
|
|
988
|
+
createComment('owner-user', 'ok'),
|
|
989
|
+
createComment(
|
|
990
|
+
'bot',
|
|
991
|
+
'Auto Status Check: TRIAGER_PROPOSAL_APPROVED\nAgent: developer\nStory: regular / workflow improvement',
|
|
992
|
+
),
|
|
993
|
+
]);
|
|
994
|
+
|
|
995
|
+
await useCase.run({
|
|
996
|
+
projectUrl: 'https://github.com/orgs/owner/projects/1',
|
|
997
|
+
allowedIssueAuthors: ['owner-user'],
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
expect(mockIssueRepository.updateStatus.mock.calls).toEqual([]);
|
|
1001
|
+
expect(mockIssueRepository.setIssueAgentField.mock.calls).toEqual([]);
|
|
1002
|
+
expect(mockIssueCommentRepository.createComment.mock.calls).toEqual([]);
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
it('should dispatch again when the issue returns to AW after the agent ran and TRIAGER_PROPOSAL_APPROVED was posted without a subsequent new proposal+approval', async () => {
|
|
1006
|
+
const issue = createMockIssue({
|
|
1007
|
+
status: 'Awaiting Workspace',
|
|
1008
|
+
author: 'owner-user',
|
|
1009
|
+
agent: null,
|
|
1010
|
+
});
|
|
1011
|
+
mockIssueRepository.getAllIssues.mockResolvedValue({
|
|
1012
|
+
project: mockProject,
|
|
1013
|
+
issues: [issue],
|
|
1014
|
+
cacheUsed: false,
|
|
1015
|
+
});
|
|
1016
|
+
// second proposal after TRIAGER_PROPOSAL_APPROVED, with a new owner approval
|
|
1017
|
+
mockIssueCommentRepository.getCommentsFromIssue.mockResolvedValue([
|
|
1018
|
+
createComment(
|
|
1019
|
+
'bot',
|
|
1020
|
+
TRIAGER_PROPOSAL_COMMENT(
|
|
1021
|
+
'developer',
|
|
1022
|
+
'regular / workflow improvement',
|
|
1023
|
+
false,
|
|
1024
|
+
),
|
|
1025
|
+
),
|
|
1026
|
+
createComment('owner-user', 'ok'),
|
|
1027
|
+
createComment(
|
|
1028
|
+
'bot',
|
|
1029
|
+
'Auto Status Check: TRIAGER_PROPOSAL_APPROVED\nAgent: developer\nStory: regular / workflow improvement',
|
|
1030
|
+
),
|
|
1031
|
+
createComment(
|
|
1032
|
+
'bot',
|
|
1033
|
+
TRIAGER_PROPOSAL_COMMENT(
|
|
1034
|
+
'developer',
|
|
1035
|
+
'regular / workflow improvement',
|
|
1036
|
+
true,
|
|
1037
|
+
),
|
|
1038
|
+
),
|
|
1039
|
+
createComment('owner-user', 'ok'),
|
|
1040
|
+
]);
|
|
1041
|
+
|
|
1042
|
+
await useCase.run({
|
|
1043
|
+
projectUrl: 'https://github.com/orgs/owner/projects/1',
|
|
1044
|
+
allowedIssueAuthors: ['owner-user'],
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
expect(mockIssueRepository.updateStatus.mock.calls).toHaveLength(1);
|
|
1048
|
+
expect(mockIssueRepository.setIssueAgentField.mock.calls).toHaveLength(1);
|
|
1049
|
+
});
|
|
967
1050
|
});
|
|
968
1051
|
});
|
|
@@ -197,7 +197,7 @@ export class TriagerApprovalDispatchUseCase {
|
|
|
197
197
|
continue;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
let
|
|
200
|
+
let approvalIndex = -1;
|
|
201
201
|
for (let i = firstProposalIndex + 1; i < comments.length; i++) {
|
|
202
202
|
const comment = comments[i];
|
|
203
203
|
if (
|
|
@@ -207,12 +207,20 @@ export class TriagerApprovalDispatchUseCase {
|
|
|
207
207
|
allowedIssueAuthors ?? [],
|
|
208
208
|
)
|
|
209
209
|
) {
|
|
210
|
-
|
|
211
|
-
break;
|
|
210
|
+
approvalIndex = i;
|
|
212
211
|
}
|
|
213
212
|
}
|
|
214
213
|
|
|
215
|
-
if (
|
|
214
|
+
if (approvalIndex === -1) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const alreadyDispatched = comments
|
|
219
|
+
.slice(approvalIndex + 1)
|
|
220
|
+
.some((c) =>
|
|
221
|
+
c.content.startsWith('Auto Status Check: TRIAGER_PROPOSAL_APPROVED'),
|
|
222
|
+
);
|
|
223
|
+
if (alreadyDispatched) {
|
|
216
224
|
continue;
|
|
217
225
|
}
|
|
218
226
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HandleScheduledEventUseCaseHandler.d.ts","sourceRoot":"","sources":["../../../../src/adapter/entry-points/handlers/HandleScheduledEventUseCaseHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HandleScheduledEventUseCaseHandler.d.ts","sourceRoot":"","sources":["../../../../src/adapter/entry-points/handlers/HandleScheduledEventUseCaseHandler.ts"],"names":[],"mappings":"AAsDA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AA0D3D,qBAAa,kCAAkC;IAC7C,MAAM,GACJ,gBAAgB,MAAM,EACtB,UAAU,OAAO,EACjB,6BAA4B,MAAM,EAAE,GAAG,IAAW,KACjD,OAAO,CAAC;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,KAAK,EAAE,CAAC;QAChB,SAAS,EAAE,OAAO,CAAC;QACnB,eAAe,EAAE,IAAI,EAAE,CAAC;KACzB,GAAG,IAAI,CAAC,CAy1BP;CACH"}
|