Repository navigation
Expand file tree
/
Copy pathpull_request_workflow_context.ts
More file actions
224 lines (213 loc) · 8.91 KB
/
Copy pathpull_request_workflow_context.ts
File metadata and controls
224 lines (213 loc) · 8.91 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
import { pendingPullRequestParent } from '../../domain/pull_request_issue_link_state';
import { DEFAULT_COPILOT_LIFECYCLE_LABELS, type CopilotLifecycleLabels } from '../../domain/copilot_lifecycle';
import type { AgentConfiguration } from '../../domain/agent';
import type { PullRequestDescriptionMode } from '../../domain/pull_request_description';
import type { AssignmentContext, CloseIssueAfterMergeContext, PrioritySizeContext } from './issue_workflow_context';
import { copyProjects, projectAssignmentContext } from './issue_workflow_context';
import type { ProjectReference } from '../ports/project_board_link_ports';
export interface AssignReviewersContext {
readonly pullRequestNumber: number;
readonly desiredReviewersCount: number;
readonly creator: string;
}
export interface LinkPullRequestIssueContext {
readonly pullRequestNumber: number;
readonly issueNumber: number;
readonly originalBaseBranch: string;
readonly defaultBranch: string;
readonly expectedHeadSha?: string;
readonly expectedHeadRepository?: string;
readonly expectedHeadRef?: string;
readonly recoveryOnly?: boolean;
}
export interface SyncPullRequestLabelsContext {
readonly issueNumber: number;
readonly pullRequestNumber: number;
readonly sizeLabels: readonly string[];
readonly projects: readonly ProjectReference[];
readonly projectSizeByLabel: Readonly<Record<string, string>>;
}
export interface PullRequestDescriptionContext {
readonly eventName: string;
readonly issueNumber: number;
readonly pullRequest: {
readonly number: number;
readonly body: string;
readonly headSha?: string;
readonly headRepository?: string;
readonly headBranch: string;
readonly baseBranch: string;
readonly creator: string;
};
readonly mode: PullRequestDescriptionMode;
readonly membersOnly: boolean;
readonly agentConfiguration: Readonly<AgentConfiguration>;
readonly targetLocale: string;
}
export interface PullRequestDescriptionRequest {
readonly context: PullRequestDescriptionContext;
readonly trigger: 'automatic' | 'authorized-command';
}
export interface PullRequestWorkflowStepContexts {
readonly assignment: AssignmentContext;
readonly reviewers: AssignReviewersContext;
readonly linkIssue: LinkPullRequestIssueContext;
readonly syncLabels: SyncPullRequestLabelsContext;
readonly priority: PrioritySizeContext;
readonly description: PullRequestDescriptionContext;
readonly closeIssue: CloseIssueAfterMergeContext;
readonly retireBranchSync: import('./actions/retire_branch_sync_use_case').RetireBranchSyncContext;
}
interface ProjectSource {
readonly id: string;
readonly title: string;
readonly type: string;
readonly owner: string;
readonly url: string;
readonly publicUrl?: string;
readonly number: number;
}
export interface PullRequestWorkflowContextSource {
readonly pullRequestParentBranch?: string;
readonly currentConfiguration?: { readonly parentBranch?: string; readonly workingBranch?: string };
readonly tokenUser?: string;
readonly isIssue: boolean;
readonly isPullRequest: boolean;
readonly eventName: string;
readonly issueNumber: number;
readonly issue: {
readonly number: number;
readonly creator: string;
readonly desiredAssigneesCount: number;
};
readonly pullRequest: {
readonly number: number;
readonly body: string;
readonly head: string;
readonly headSha?: string;
readonly headRepository?: string;
readonly base: string;
readonly creator: string;
readonly desiredAssigneesCount: number;
readonly desiredReviewersCount: number;
};
readonly branches: {
readonly defaultBranch: string;
readonly development?: string;
readonly featureTree?: string;
readonly bugfixTree?: string;
readonly docsTree?: string;
readonly choreTree?: string;
};
readonly labels: {
readonly sizeLabels: readonly string[];
readonly sizeXxl?: string;
readonly sizeXl?: string;
readonly sizeL?: string;
readonly sizeM?: string;
readonly sizeS?: string;
readonly sizeXs?: string;
readonly lifecycle?: CopilotLifecycleLabels;
readonly completionProtectedLabels?: readonly string[];
readonly priorityLabelOnIssue?: string;
readonly priorityLabelOnIssueProcessable: boolean;
readonly priorityHigh: string;
readonly priorityMedium: string;
readonly priorityLow: string;
};
readonly project: { getProjects(): readonly ProjectSource[] };
readonly ai: {
getPullRequestDescriptionMode(): PullRequestDescriptionMode;
getAiMembersOnly(): boolean;
getAgentConfiguration(task: 'planner'): AgentConfiguration;
};
readonly locale: { readonly pullRequest: string; readonly issue?: string };
}
export function projectLinkPullRequestIssueContext(source: PullRequestWorkflowContextSource): LinkPullRequestIssueContext {
return Object.freeze({
pullRequestNumber: source.pullRequest.number,
issueNumber: source.issueNumber,
originalBaseBranch: pendingPullRequestParent(source.pullRequest.body ?? '', source.pullRequest.number, source.issueNumber)
?? source.pullRequestParentBranch ?? source.pullRequest.base,
expectedHeadSha: source.pullRequest.headSha,
expectedHeadRepository: source.pullRequest.headRepository,
expectedHeadRef: source.pullRequest.head || source.currentConfiguration?.workingBranch,
defaultBranch: source.branches.defaultBranch,
});
}
export function projectPullRequestWorkflowStepContexts(
source: PullRequestWorkflowContextSource,
): PullRequestWorkflowStepContexts {
const projects = copyProjects(source.project.getProjects());
return Object.freeze({
assignment: projectAssignmentContext(source),
reviewers: Object.freeze({
pullRequestNumber: source.pullRequest.number,
desiredReviewersCount: source.pullRequest.desiredReviewersCount,
creator: source.pullRequest.creator,
}),
linkIssue: projectLinkPullRequestIssueContext(source),
syncLabels: Object.freeze({
issueNumber: source.issueNumber,
pullRequestNumber: source.pullRequest.number,
sizeLabels: Object.freeze([...source.labels.sizeLabels]),
projects,
projectSizeByLabel: Object.freeze(Object.fromEntries([
[source.labels.sizeXxl, 'XL'], [source.labels.sizeXl, 'XL'],
[source.labels.sizeL, 'L'], [source.labels.sizeM, 'M'],
[source.labels.sizeS, 'S'], [source.labels.sizeXs, 'XS'],
].filter(([label]) => typeof label === 'string' && label.length > 0))),
}),
priority: Object.freeze({
contentNumber: source.pullRequest.number,
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,
}),
description: projectPullRequestDescriptionContext(source),
retireBranchSync: Object.freeze({ issueNumber: source.issueNumber, locale: source.locale.issue ?? 'en-US', trustedBotLogin: source.tokenUser }),
closeIssue: Object.freeze({
completionLabels: Object.freeze({
lifecycle: Object.freeze({ ...(source.labels.lifecycle ?? DEFAULT_COPILOT_LIFECYCLE_LABELS) }),
protectedLabels: Object.freeze([...(source.labels.completionProtectedLabels ?? ['branched', 'SDD', 'contract-change'])]),
}),
issueNumber: source.issueNumber,
pullRequestNumber: source.pullRequest.number,
...(source.pullRequest.headSha ? { stagedRollout: Object.freeze({
headSha: source.pullRequest.headSha,
integrationBranch: source.branches.development,
branchTypes: Object.freeze([
source.branches.featureTree, source.branches.bugfixTree, source.branches.docsTree, source.branches.choreTree,
].filter((type): type is string => Boolean(type))),
botLogin: source.tokenUser,
locale: source.locale.issue ?? 'en-US',
}) } : {}),
}),
});
}
export function projectPullRequestDescriptionContext(
source: PullRequestWorkflowContextSource,
): PullRequestDescriptionContext {
return Object.freeze({
eventName: source.eventName,
issueNumber: source.issueNumber,
pullRequest: Object.freeze({
number: source.pullRequest.number > 0 ? source.pullRequest.number : source.issue.number,
body: source.pullRequest.body ?? '',
headBranch: source.pullRequest.head,
headSha: source.pullRequest.headSha,
headRepository: source.pullRequest.headRepository,
baseBranch: pendingPullRequestParent(source.pullRequest.body ?? '', source.pullRequest.number, source.issueNumber) ?? source.pullRequestParentBranch ?? source.pullRequest.base,
creator: source.pullRequest.creator,
}),
mode: source.ai.getPullRequestDescriptionMode(),
membersOnly: source.ai.getAiMembersOnly(),
agentConfiguration: Object.freeze({ ...source.ai.getAgentConfiguration('planner') }),
targetLocale: source.locale.pullRequest,
});
}