Repository navigation
Expand file tree
/
Copy pathgithub_action_execution.ts
More file actions
189 lines (182 loc) · 9.62 KB
/
Copy pathgithub_action_execution.ts
File metadata and controls
189 lines (182 loc) · 9.62 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
import * as core from '@actions/core';
import { ACTIONS } from '../data/model/action_types';
import { ApplicationError } from '../application/errors/application_error';
import { Ai } from '../data/model/ai';
import { Hotfix } from '../data/model/hotfix';
import { Release } from '../data/model/release';
import { SingleAction } from '../data/model/single_action';
import type { Execution } from '../data/model/execution';
import type { ProjectDetailQueryPort } from '../application/ports/project_detail_ports';
import { INPUT_KEYS } from '../application/contracts/input_keys';
import { isEnabledInput, parseIssueWorkflowBoolean } from './input_boolean_policy';
import { getGithubActionInput } from './github_action_input';
import { parseBoundedPositiveIntegerInput, parseIntegerInput } from './input_number_policy';
import { parseDelimitedValues } from './input_values_policy';
import { readGithubActionAiInputs } from './github_action_ai_inputs';
import { readGithubActionLocaleInputs } from './github_action_locale_inputs';
import { buildSizeThresholds } from './size_threshold_builder';
import { readGithubActionThresholdInputs } from './github_action_threshold_inputs';
import { buildBranches } from './branches_builder';
import { readGithubActionBranchInputs } from './github_action_branch_inputs';
import { readGithubActionLabelInputs } from './github_action_label_inputs';
import { readGithubActionWorkflowInputs } from './github_action_workflow_inputs';
import { readGithubActionIssueTypeInputs } from './github_action_issue_type_inputs';
import { readGithubActionProjectInputs } from './github_action_project_inputs';
import { buildExecution } from './execution_builder';
import { buildEmoji, buildIssue, buildIssueTypes, buildLabels, buildLocale, buildProjects, buildPullRequest, buildTokens, buildWorkflows } from './configuration_builders';
import { loadProjectDetails } from './project_details_loader';
import type { buildGithubActionEventInputs } from './github_event_inputs';
import { DEFAULT_INACTIVITY_THRESHOLD_HOURS, MAX_INACTIVITY_THRESHOLD_HOURS } from '../domain/issue_inactivity';
import { activeAgentTasks } from '../application/policies/agent_task_activation_policy';
import type { AgentTaskConfiguration } from '../domain/agent';
import { readDeploymentConfiguration } from './deployment_configuration_builder';
import { parseIssueWorkflowProfile } from '../domain/issue_workflow_profile';
import { issueWorkflowProfileDigest } from '../utils/issue_workflow_profile_digest';
export interface GithubActionExecutionInput {
readonly getInput: typeof getGithubActionInput;
readonly eventInputs: ReturnType<typeof buildGithubActionEventInputs>;
readonly projectQuery: ProjectDetailQueryPort;
readonly debug: boolean;
readonly token: string;
readonly tokenUser: string;
readonly singleAction: SingleAction;
readonly aiInputs?: ReturnType<typeof readGithubActionAiInputs>;
readonly activeAgentTasks?: ReturnType<typeof activeAgentTasks>;
readonly agentRuntimeAuthorized?: boolean;
readonly localeInputs?: ReturnType<typeof readGithubActionLocaleInputs>;
}
export async function buildGithubActionExecution(
input: GithubActionExecutionInput,
): Promise<Execution> {
const { getInput, eventInputs, debug, singleAction, token } = input;
const parsedIssueWorkflowProfile = parseIssueWorkflowProfile(getInput(INPUT_KEYS.ISSUE_WORKFLOW_PROFILE));
if ('error' in parsedIssueWorkflowProfile) throw new Error(parsedIssueWorkflowProfile.error);
// Locale is trusted configuration. Validate it before agent provisioning or
// any provider/domain mutation can begin.
const localeInputs = input.localeInputs ?? readGithubActionLocaleInputs(getInput);
const aiInputs = input.aiInputs ?? readGithubActionAiInputs(getInput);
const agentTasks = input.agentRuntimeAuthorized === false
? disableAgentTasks(aiInputs.requestedAgentTasks)
: aiInputs.requestedAgentTasks;
const projectInputs = readGithubActionProjectInputs(getInput, []);
const workflowInputs = readGithubActionWorkflowInputs(getInput);
const labelInputs = readGithubActionLabelInputs(getInput);
const issueTypeInputs = readGithubActionIssueTypeInputs(getInput);
const sizeThresholdInputs = readGithubActionThresholdInputs(getInput);
const branchInputs = readGithubActionBranchInputs(getInput);
const deployment = readDeploymentConfiguration(getInput, {
productionBranch: branchInputs.defaultBranch,
developmentBranch: branchInputs.development,
releaseTree: branchInputs.releaseTree,
hotfixTree: branchInputs.hotfixTree,
});
return buildExecution({
debug,
inactivityThresholdHours: parseBoundedPositiveIntegerInput(
getInput(INPUT_KEYS.INACTIVITY_THRESHOLD_HOURS),
DEFAULT_INACTIVITY_THRESHOLD_HOURS,
MAX_INACTIVITY_THRESHOLD_HOURS,
),
singleAction,
commitPrefixBuilder: getCommitPrefixBuilder(getInput),
issue: buildIssue(
parseIssueWorkflowBoolean(getInput(INPUT_KEYS.ISSUE_MANAGED_BRANCHES), INPUT_KEYS.ISSUE_MANAGED_BRANCHES, true),
isEnabledInput(getInput(INPUT_KEYS.REOPEN_ISSUE_ON_PUSH)),
parseIntegerInput(getInput(INPUT_KEYS.DESIRED_ASSIGNEES_COUNT), 0),
eventInputs,
),
preBranchSdd: parseIssueWorkflowBoolean(getInput(INPUT_KEYS.PRE_BRANCH_SDD), INPUT_KEYS.PRE_BRANCH_SDD, false),
verificationSetup: parseIssueWorkflowBoolean(getInput(INPUT_KEYS.VERIFICATION_SETUP), INPUT_KEYS.VERIFICATION_SETUP, false),
pullRequest: buildPullRequest(
parseIntegerInput(getInput(INPUT_KEYS.PULL_REQUEST_DESIRED_ASSIGNEES_COUNT), 0),
parseIntegerInput(getInput(INPUT_KEYS.PULL_REQUEST_DESIRED_REVIEWERS_COUNT), 0),
eventInputs,
),
emoji: buildEmoji(
getInput(INPUT_KEYS.EMOJI_LABELED_TITLE) === 'true',
getInput(INPUT_KEYS.BRANCH_MANAGEMENT_EMOJI),
),
tokens: buildTokens(token),
ai: new Ai(
'',
aiInputs.requestedAgentTasks.findings.model,
aiInputs.membersOnly,
aiInputs.ignoreFiles,
aiInputs.includeReasoning,
aiInputs.bugbotSeverity,
aiInputs.bugbotCommentLimit,
aiInputs.bugbotFixVerifyCommands,
agentTasks,
aiInputs.pullRequestDescriptionMode,
aiInputs.bugbotReviewConfiguration,
),
labels: buildLabels(labelInputs),
issueTypes: buildIssueTypes(issueTypeInputs),
locale: buildLocale(
localeInputs.repository,
localeInputs.issueOverride,
localeInputs.pullRequestOverride,
),
sizeThresholds: buildSizeThresholds(sizeThresholdInputs),
branches: buildBranches(branchInputs),
release: new Release(),
hotfix: new Hotfix(),
workflows: buildWorkflows(workflowInputs.release, workflowInputs.hotfix),
deployment,
projects: buildProjects(projectInputs),
tokenUser: input.tokenUser,
inputs: eventInputs,
issueWorkflowProfile: parsedIssueWorkflowProfile.profile,
issueWorkflowProfileDigest: issueWorkflowProfileDigest(parsedIssueWorkflowProfile.profile),
});
}
/** Loads provider-backed project facts only after live issue admission succeeds. */
export async function hydrateGithubActionExecutionProjects(
execution: Execution,
input: Pick<GithubActionExecutionInput, 'getInput' | 'projectQuery' | 'token'>,
): Promise<void> {
const projects = await loadProjectDetails(
input.projectQuery,
parseDelimitedValues(input.getInput(INPUT_KEYS.PROJECT_IDS)),
execution.owner,
input.token,
);
execution.project = buildProjects(readGithubActionProjectInputs(input.getInput, projects));
}
function disableAgentTasks(tasks: AgentTaskConfiguration): AgentTaskConfiguration {
return Object.fromEntries(
Object.entries(tasks).map(([task, configuration]) => [task, {
...configuration,
model: '',
}]),
) as unknown as AgentTaskConfiguration;
}
export function readGithubActionSingleAction(getInput: typeof getGithubActionInput): SingleAction {
const declared = core.getInput(INPUT_KEYS.SINGLE_ACTION, { trimWhitespace: false });
const configured = getInput(INPUT_KEYS.SINGLE_ACTION);
if (configured === ACTIONS.REPLACE_DEPLOYMENT && declared !== ACTIONS.REPLACE_DEPLOYMENT) {
throw new ApplicationError('workflow.invalid-event', 'Candidate replacement requires explicit declared workflow inputs.');
}
// Generic JSON configuration cannot synthesize, redirect or rewrite a replacement proof.
const read = declared === ACTIONS.REPLACE_DEPLOYMENT
? (key: string) => core.getInput(key, { trimWhitespace: false }) : getInput;
return new SingleAction(
read(INPUT_KEYS.SINGLE_ACTION),
read(INPUT_KEYS.SINGLE_ACTION_ISSUE),
read(INPUT_KEYS.SINGLE_ACTION_VERSION),
read(INPUT_KEYS.SINGLE_ACTION_TITLE),
read(INPUT_KEYS.SINGLE_ACTION_CHANGELOG),
read(INPUT_KEYS.SINGLE_ACTION_MESSAGE),
read(INPUT_KEYS.SINGLE_ACTION_COMMENT_ID),
read(INPUT_KEYS.SINGLE_ACTION_COMMENT_MODE),
read(INPUT_KEYS.SINGLE_ACTION_OPERATION_ID),
read(INPUT_KEYS.SINGLE_ACTION_EXPECTED_REVISION),
read(INPUT_KEYS.SINGLE_ACTION_CANDIDATE_SHA),
read(INPUT_KEYS.SINGLE_ACTION_PRODUCTION_BASE_SHA),
read(INPUT_KEYS.SINGLE_ACTION_CONFIRM_UNPUBLISHED),
read(INPUT_KEYS.SINGLE_ACTION_REVIEWED_SOURCE_SHA),
);
}
function getCommitPrefixBuilder(getInput: typeof getGithubActionInput): string {
return getInput(INPUT_KEYS.COMMIT_PREFIX_TRANSFORMS) || 'replace-slash';
}