Repository navigation
Expand file tree
/
Copy pathissue_workflow_context.ts
More file actions
392 lines (369 loc) · 14.2 KB
/
Copy pathissue_workflow_context.ts
File metadata and controls
392 lines (369 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import type { AgentConfiguration } from '../../domain/agent';
import type { ProjectReference } from '../ports/project_board_link_ports';
import type { SelectedIssueType } from '../ports/issue_management_ports';
import type { Result } from '../../data/model/result';
import type { IssueWorkflowKind } from '../../domain/issue_workflow_profile';
import type { IssueCompletionLabelConfiguration } from '../../domain/issue_completion';
import { ISSUE_START_LABEL } from '../../domain/issue_start_policy';
export interface AssignmentContext {
readonly target: 'issue' | 'pull request';
readonly number: number;
readonly desiredAssigneesCount: number;
readonly creator: string;
}
export interface IssueNumberContext {
readonly issueNumber: number;
}
export interface CloseIssueAfterMergeContext extends IssueNumberContext {
readonly pullRequestNumber: number;
readonly completionLabels: IssueCompletionLabelConfiguration;
}
export interface UpdateIssueTypeContext extends IssueNumberContext {
readonly issueType: SelectedIssueType;
}
export interface MoveIssueToInProgressContext extends IssueNumberContext {
readonly columnName: string;
readonly projects: readonly ProjectReference[];
}
export interface PrioritySizeContext {
readonly contentNumber: number;
readonly priority: {
readonly currentLabel?: string;
readonly processable: boolean;
readonly high: string;
readonly medium: string;
readonly low: string;
};
readonly projects: readonly ProjectReference[];
}
export interface RemoveIssueBranchesContext extends IssueNumberContext {
readonly managedBranchTypes: readonly string[];
readonly previousBranchType?: string;
readonly hotfixBranchType: string;
}
export interface RemoveObsoleteIssueBranchesContext extends IssueNumberContext {
readonly issueTitle: string;
readonly managementBranch: string;
readonly managedBranchTypes: readonly string[];
}
export interface BranchConfigurationPatch {
readonly parentBranch?: string;
readonly workingBranch?: string;
readonly releaseBranch?: string;
readonly releaseOriginBranch?: string;
readonly releaseOriginSha?: string;
readonly hotfixBranch?: string;
readonly hotfixOriginSha?: string;
}
export interface BranchPreparationOutcome {
readonly results: readonly Result[];
readonly configurationPatch: BranchConfigurationPatch;
}
export function branchPreparationOutcome(
results: readonly Result[],
configurationPatch: BranchConfigurationPatch = {},
): BranchPreparationOutcome {
return Object.freeze({
results: Object.freeze([...results]),
configurationPatch: Object.freeze({ ...configurationPatch }),
});
}
export interface BranchPreparationContext extends IssueNumberContext {
readonly issueTitle: string;
readonly mandatoryBranchRequired: boolean;
readonly managementBranch: string;
readonly repositoryWebUrl: string;
readonly branches: {
readonly main: string;
readonly defaultBranch: string;
readonly development: string;
readonly managedTypes: readonly string[];
};
readonly currentConfiguration: {
readonly parentBranch?: string;
};
readonly release: {
readonly active: boolean;
readonly version?: string;
readonly branch?: string;
};
readonly hotfix: {
readonly active: boolean;
readonly baseVersion?: string;
readonly version?: string;
readonly baseBranch?: string;
readonly branch?: string;
};
readonly commitPrefixBuilder: string;
readonly deployLabel: string;
readonly releaseWorkflow: string;
readonly moveToInProgress: MoveIssueToInProgressContext;
}
export interface DeployAddedContext {
readonly issueWorkflowProfile?: import('../../domain/issue_workflow_profile').IssueWorkflowProfile;
readonly issue: {
readonly labeled: boolean;
readonly labelAdded: string;
readonly number: number;
readonly title: string;
readonly body: string;
};
readonly deployLabel: string;
readonly release: { readonly active: boolean; readonly branch?: string; readonly version?: string };
readonly hotfix: { readonly active: boolean; readonly branch?: string; readonly version?: string };
readonly workflows: { readonly release: string; readonly hotfix: string };
readonly repositoryWebUrl: string;
readonly moveToInProgress: MoveIssueToInProgressContext;
}
export interface AnswerIssueHelpContext extends IssueNumberContext {
readonly opened: boolean;
readonly questionOrHelp: boolean;
readonly description: string;
readonly agentConfiguration: Readonly<AgentConfiguration>;
readonly locale: string;
}
export interface IssueWorkflowStepContexts {
readonly closeNotAllowed: IssueNumberContext;
readonly assignment: AssignmentContext;
readonly issueType: UpdateIssueTypeContext;
readonly priority: PrioritySizeContext;
readonly removeIssueBranches: RemoveIssueBranchesContext;
readonly prepareBranches: BranchPreparationContext;
readonly removeObsoleteBranches: RemoveObsoleteIssueBranchesContext;
readonly deployAdded: DeployAddedContext;
readonly answerHelp: AnswerIssueHelpContext;
}
interface ProjectSource extends ProjectReference {
readonly publicUrl?: string;
}
export interface IssueWorkflowContextSource {
readonly issueWorkflowProfile?: import('../../domain/issue_workflow_profile').IssueWorkflowProfile;
readonly owner: string;
readonly repo: string;
readonly issueNumber: number;
readonly isIssue: boolean;
readonly isPullRequest: boolean;
readonly eventName: string;
readonly tokenUser?: string;
readonly managementBranch: string;
readonly issueWorkflowKind?: IssueWorkflowKind;
readonly issue: {
readonly number: number;
readonly title: string;
readonly body: string;
readonly liveBody?: string;
readonly creator: string;
readonly opened: boolean;
readonly labeled: boolean;
readonly labelAdded: string;
readonly desiredAssigneesCount: number;
};
readonly pullRequest: {
readonly number: number;
readonly creator: string;
readonly desiredAssigneesCount: number;
};
readonly labels: {
readonly isMandatoryBranchedLabel: boolean;
readonly isQuestion: boolean;
readonly isHelp: boolean;
readonly isHotfix: boolean;
readonly isRelease: boolean;
readonly isDocs: boolean;
readonly isDocumentation: boolean;
readonly isChore: boolean;
readonly isMaintenance: boolean;
readonly isBugfix: boolean;
readonly isBug: boolean;
readonly isFeature: boolean;
readonly isEnhancement: boolean;
readonly priorityLabelOnIssue?: string;
readonly priorityLabelOnIssueProcessable: boolean;
readonly priorityHigh: string;
readonly priorityMedium: string;
readonly priorityLow: string;
readonly feature: string;
readonly bugfix: string;
readonly deploy: string;
};
readonly issueTypes: Readonly<Record<IssueTypeKey, string>>;
readonly branches: {
readonly main: string;
readonly defaultBranch: string;
readonly development: string;
readonly featureTree: string;
readonly bugfixTree: string;
readonly docsTree: string;
readonly choreTree: string;
readonly hotfixTree: string;
};
readonly previousConfiguration?: { readonly branchType?: string };
readonly currentConfiguration: { readonly parentBranch?: string };
readonly release: { readonly active: boolean; readonly version?: string; readonly branch?: string };
readonly hotfix: {
readonly active: boolean;
readonly baseVersion?: string;
readonly version?: string;
readonly baseBranch?: string;
readonly branch?: string;
};
readonly commitPrefixBuilder: string;
readonly workflows: { readonly release: string; readonly hotfix: string };
readonly project: {
getProjects(): readonly ProjectSource[];
getProjectColumnIssueInProgress(): string;
};
readonly ai: { getAgentConfiguration(task: 'planner'): AgentConfiguration };
readonly locale: { readonly issue: string };
readonly inputs?: { readonly action?: string };
}
type IssueTypeName = 'task' | 'bug' | 'feature' | 'documentation' | 'maintenance' | 'hotfix' | 'release' | 'question' | 'help';
type IssueTypeKey = IssueTypeName | `${IssueTypeName}Description` | `${IssueTypeName}Color`;
export function projectIssueWorkflowStepContexts(source: IssueWorkflowContextSource): IssueWorkflowStepContexts {
const projects = copyProjects(source.project.getProjects());
const moveToInProgress = Object.freeze({
issueNumber: source.issueNumber,
columnName: source.project.getProjectColumnIssueInProgress(),
projects,
});
const managedBranchTypes = Object.freeze([
source.branches.featureTree,
source.branches.bugfixTree,
source.branches.docsTree,
source.branches.choreTree,
].filter(value => value.length > 0));
const branchPreparationTypes = Object.freeze([
source.branches.featureTree,
source.branches.bugfixTree,
source.branches.docsTree,
source.branches.choreTree,
].filter((value) => value.length > 0));
const repositoryWebUrl = `https://github.com/${encodeURIComponent(source.owner)}/${encodeURIComponent(source.repo)}`;
return Object.freeze({
closeNotAllowed: Object.freeze({ issueNumber: source.issueNumber }),
assignment: projectAssignmentContext(source),
issueType: Object.freeze({
issueNumber: source.issueNumber,
issueType: Object.freeze(selectIssueType(source)),
}),
priority: Object.freeze({
contentNumber: source.issueNumber,
priority: Object.freeze({
...(source.labels.priorityLabelOnIssue ? { currentLabel: source.labels.priorityLabelOnIssue } : {}),
processable: source.labels.priorityLabelOnIssueProcessable,
high: source.labels.priorityHigh,
medium: source.labels.priorityMedium,
low: source.labels.priorityLow,
}),
projects,
}),
removeIssueBranches: Object.freeze({
issueNumber: source.issueNumber,
managedBranchTypes,
...(source.previousConfiguration?.branchType
? { previousBranchType: source.previousConfiguration.branchType }
: {}),
hotfixBranchType: source.branches.hotfixTree,
}),
prepareBranches: Object.freeze({
issueNumber: source.issueNumber,
issueTitle: source.issue.title ?? '',
mandatoryBranchRequired: source.labels.isMandatoryBranchedLabel,
managementBranch: source.managementBranch,
repositoryWebUrl,
branches: Object.freeze({
main: source.branches.main,
defaultBranch: source.branches.defaultBranch,
development: source.branches.development,
managedTypes: branchPreparationTypes,
}),
currentConfiguration: Object.freeze({
...(source.currentConfiguration.parentBranch
? { parentBranch: source.currentConfiguration.parentBranch }
: {}),
}),
release: Object.freeze({ ...source.release }),
hotfix: Object.freeze({ ...source.hotfix }),
commitPrefixBuilder: source.commitPrefixBuilder,
deployLabel: source.labels.deploy,
releaseWorkflow: source.workflows.release,
moveToInProgress,
}),
removeObsoleteBranches: Object.freeze({
issueNumber: source.issueNumber,
issueTitle: source.issue.title ?? '',
managementBranch: source.managementBranch,
managedBranchTypes,
}),
deployAdded: Object.freeze({
issueWorkflowProfile: source.issueWorkflowProfile,
issue: Object.freeze({
labeled: source.issue.labeled,
labelAdded: source.issue.labelAdded,
number: source.issue.number,
title: source.issue.title,
body: source.issue.liveBody ?? source.issue.body,
}),
deployLabel: source.labels.deploy,
release: Object.freeze({ ...source.release }),
hotfix: Object.freeze({ ...source.hotfix }),
workflows: Object.freeze({ ...source.workflows }),
repositoryWebUrl,
moveToInProgress,
}),
answerHelp: Object.freeze({
issueNumber: source.issue.number,
opened: source.issue.opened || (source.issue.labeled && source.issue.labelAdded === ISSUE_START_LABEL),
questionOrHelp: source.labels.isQuestion || source.labels.isHelp,
description: (source.issue.body ?? '').trim(),
agentConfiguration: Object.freeze({ ...source.ai.getAgentConfiguration('planner') }),
locale: source.locale.issue,
}),
});
}
export function projectAssignmentContext(source: {
readonly isIssue: boolean;
readonly issue: { readonly number: number; readonly desiredAssigneesCount: number; readonly creator: string };
readonly pullRequest: { readonly number: number; readonly desiredAssigneesCount: number; readonly creator: string };
}): AssignmentContext {
const target = source.isIssue ? source.issue : source.pullRequest;
return Object.freeze({
target: source.isIssue ? 'issue' : 'pull request',
number: target.number,
desiredAssigneesCount: target.desiredAssigneesCount,
creator: target.creator,
});
}
export function copyProjects(projects: readonly ProjectSource[]): readonly ProjectReference[] {
return Object.freeze(projects.map((project) => Object.freeze({
id: project.id,
title: project.title,
type: project.type,
owner: project.owner,
url: project.publicUrl || project.url,
number: project.number,
})));
}
function selectIssueType(source: IssueWorkflowContextSource): SelectedIssueType {
const name: IssueTypeName = source.issueWorkflowKind === 'bugfix' ? 'bug'
: source.issueWorkflowKind === 'documentation' ? 'documentation'
: source.issueWorkflowKind === 'chore' ? 'maintenance'
: source.issueWorkflowKind === 'help' ? 'help'
: source.issueWorkflowKind === 'hotfix' ? 'hotfix'
: source.issueWorkflowKind === 'release' ? 'release'
: source.issueWorkflowKind === 'feature' ? 'feature'
: source.labels.isHotfix ? 'hotfix'
: source.labels.isRelease ? 'release'
: source.labels.isDocs || source.labels.isDocumentation ? 'documentation'
: source.labels.isChore || source.labels.isMaintenance ? 'maintenance'
: source.labels.isBugfix || source.labels.isBug ? 'bug'
: source.labels.isFeature || source.labels.isEnhancement ? 'feature'
: source.labels.isHelp ? 'help'
: source.labels.isQuestion ? 'question'
: 'task';
return {
name: source.issueTypes[name],
description: source.issueTypes[`${name}Description`],
color: source.issueTypes[`${name}Color`],
};
}