@vypdev/copilot 3.5.3 → 3.5.4
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/build/cli/index.js +186 -45
- package/build/github_action/index.js +186 -45
- package/package.json +1 -1
package/build/cli/index.js
CHANGED
|
@@ -38159,6 +38159,27 @@ function runAtApplicationErrorBoundary(operation) {
|
|
|
38159
38159
|
}
|
|
38160
38160
|
|
|
38161
38161
|
|
|
38162
|
+
/***/ }),
|
|
38163
|
+
|
|
38164
|
+
/***/ 72594:
|
|
38165
|
+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
38166
|
+
|
|
38167
|
+
"use strict";
|
|
38168
|
+
|
|
38169
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
38170
|
+
exports.DeploymentMergeEffectError = void 0;
|
|
38171
|
+
const application_error_1 = __nccwpck_require__(75999);
|
|
38172
|
+
/** Semantic effect failure. Only a confirmed readiness rejection permits one new inspection. */
|
|
38173
|
+
class DeploymentMergeEffectError extends application_error_1.ApplicationError {
|
|
38174
|
+
constructor(action, readinessChanged, code, message, cause) {
|
|
38175
|
+
super(code, message, { cause });
|
|
38176
|
+
this.action = action;
|
|
38177
|
+
this.readinessChanged = readinessChanged;
|
|
38178
|
+
}
|
|
38179
|
+
}
|
|
38180
|
+
exports.DeploymentMergeEffectError = DeploymentMergeEffectError;
|
|
38181
|
+
|
|
38182
|
+
|
|
38162
38183
|
/***/ }),
|
|
38163
38184
|
|
|
38164
38185
|
/***/ 38313:
|
|
@@ -51843,6 +51864,91 @@ function bindSddEvidenceReadPorts(ports) {
|
|
|
51843
51864
|
}
|
|
51844
51865
|
|
|
51845
51866
|
|
|
51867
|
+
/***/ }),
|
|
51868
|
+
|
|
51869
|
+
/***/ 84387:
|
|
51870
|
+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
51871
|
+
|
|
51872
|
+
"use strict";
|
|
51873
|
+
|
|
51874
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
51875
|
+
exports.DeploymentMergeEffects = void 0;
|
|
51876
|
+
const application_error_1 = __nccwpck_require__(75999);
|
|
51877
|
+
const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
|
|
51878
|
+
const managed_pull_request_1 = __nccwpck_require__(95914);
|
|
51879
|
+
/** Applies current policy, with one bounded re-observation after a typed readiness rejection. */
|
|
51880
|
+
class DeploymentMergeEffects {
|
|
51881
|
+
constructor(pullRequests) {
|
|
51882
|
+
this.pullRequests = pullRequests;
|
|
51883
|
+
}
|
|
51884
|
+
async configure(operation, pullRequest, inspection, inspect, beforeApply) {
|
|
51885
|
+
await beforeApply(inspection.decision.mode);
|
|
51886
|
+
const action = selectAction(operation, inspection);
|
|
51887
|
+
try {
|
|
51888
|
+
await this.apply(action, pullRequest);
|
|
51889
|
+
return inspection.decision.mode;
|
|
51890
|
+
}
|
|
51891
|
+
catch (error) {
|
|
51892
|
+
if (!(error instanceof deployment_merge_effect_error_1.DeploymentMergeEffectError) || !error.readinessChanged || operation.prMode !== "auto")
|
|
51893
|
+
throw error;
|
|
51894
|
+
const current = await this.pullRequests.getPullRequest(pullRequest.number);
|
|
51895
|
+
assertSamePullRequest(pullRequest, current);
|
|
51896
|
+
if (current.merged)
|
|
51897
|
+
return inspection.decision.mode;
|
|
51898
|
+
if (current.state !== "open")
|
|
51899
|
+
throw new application_error_1.ApplicationError("provider.conflict", "The managed PR was closed without merging.");
|
|
51900
|
+
const refreshed = await inspect(current);
|
|
51901
|
+
if (refreshed.kind === "blocked")
|
|
51902
|
+
throw new application_error_1.ApplicationError("provider.conflict", refreshed.reason);
|
|
51903
|
+
const nextAction = selectAction(operation, refreshed);
|
|
51904
|
+
if (nextAction === action) {
|
|
51905
|
+
if (action === "enable-auto-merge" && current.autoMergeEnabled)
|
|
51906
|
+
return refreshed.decision.mode;
|
|
51907
|
+
throw error;
|
|
51908
|
+
}
|
|
51909
|
+
await beforeApply(refreshed.decision.mode);
|
|
51910
|
+
await this.apply(nextAction, current);
|
|
51911
|
+
return refreshed.decision.mode;
|
|
51912
|
+
}
|
|
51913
|
+
}
|
|
51914
|
+
async apply(action, pullRequest) {
|
|
51915
|
+
try {
|
|
51916
|
+
if (action === "merge") {
|
|
51917
|
+
await this.pullRequests.mergePullRequest(pullRequest.number, pullRequest.headSha);
|
|
51918
|
+
}
|
|
51919
|
+
else if (action === "enable-auto-merge" && !pullRequest.autoMergeEnabled) {
|
|
51920
|
+
await this.pullRequests.enableAutoMerge(pullRequest.nodeId, pullRequest.headSha);
|
|
51921
|
+
}
|
|
51922
|
+
else if (action === "merge-queue" && !await this.pullRequests.isPullRequestQueued(pullRequest.nodeId)) {
|
|
51923
|
+
await this.pullRequests.enqueuePullRequest(pullRequest.nodeId, pullRequest.headSha);
|
|
51924
|
+
}
|
|
51925
|
+
}
|
|
51926
|
+
catch (cause) {
|
|
51927
|
+
if (cause instanceof application_error_1.ApplicationError)
|
|
51928
|
+
throw cause;
|
|
51929
|
+
throw new application_error_1.ApplicationError("workflow.failed", `Automatic merge action ${action} failed with an unclassified provider rejection.`, { cause, retryable: true });
|
|
51930
|
+
}
|
|
51931
|
+
}
|
|
51932
|
+
}
|
|
51933
|
+
exports.DeploymentMergeEffects = DeploymentMergeEffects;
|
|
51934
|
+
function selectAction(operation, inspection) {
|
|
51935
|
+
if (inspection.decision.mode !== "auto-merge")
|
|
51936
|
+
return inspection.decision.mode;
|
|
51937
|
+
return operation.prMode === "auto" && inspection.capabilities.immediatelyMergeable ? "merge" : "enable-auto-merge";
|
|
51938
|
+
}
|
|
51939
|
+
function assertSamePullRequest(expected, current) {
|
|
51940
|
+
const marker = (0, managed_pull_request_1.parseManagedPullRequestMarker)(expected.body);
|
|
51941
|
+
const currentMarker = (0, managed_pull_request_1.parseManagedPullRequestMarker)(current.body);
|
|
51942
|
+
if (expected.number !== current.number || expected.nodeId !== current.nodeId
|
|
51943
|
+
|| expected.repositoryFullName !== current.repositoryFullName || expected.baseBranch !== current.baseBranch
|
|
51944
|
+
|| expected.headBranch !== current.headBranch || expected.headSha !== current.headSha
|
|
51945
|
+
|| !marker || !currentMarker || marker.operationId !== currentMarker.operationId
|
|
51946
|
+
|| marker.phase !== currentMarker.phase || marker.issue !== currentMarker.issue) {
|
|
51947
|
+
throw new application_error_1.ApplicationError("provider.conflict", "The managed PR identity or frozen head changed during merge setup.", { retryable: false });
|
|
51948
|
+
}
|
|
51949
|
+
}
|
|
51950
|
+
|
|
51951
|
+
|
|
51846
51952
|
/***/ }),
|
|
51847
51953
|
|
|
51848
51954
|
/***/ 77658:
|
|
@@ -51867,6 +51973,7 @@ const deployment_message_catalog_1 = __nccwpck_require__(79364);
|
|
|
51867
51973
|
const deployment_operation_1 = __nccwpck_require__(92730);
|
|
51868
51974
|
const merge_queue_readiness_1 = __nccwpck_require__(12515);
|
|
51869
51975
|
const result_1 = __nccwpck_require__(73817);
|
|
51976
|
+
const deployment_merge_effects_1 = __nccwpck_require__(84387);
|
|
51870
51977
|
exports.DEPLOYMENT_ORCHESTRATION_TASK_ID = "DeploymentOrchestrationUseCase";
|
|
51871
51978
|
class DeploymentOrchestrationRuntime {
|
|
51872
51979
|
constructor(dependencies, stateBoundary) {
|
|
@@ -51941,18 +52048,18 @@ class DeploymentOrchestrationRuntime {
|
|
|
51941
52048
|
result: await this.block(context, operation, category, inspection.reason, true),
|
|
51942
52049
|
};
|
|
51943
52050
|
}
|
|
51944
|
-
|
|
51945
|
-
...operation,
|
|
51946
|
-
selectedPrMode: inspection.decision.mode,
|
|
51947
|
-
};
|
|
51948
|
-
await this.persist(context, managed);
|
|
52051
|
+
let managed = operation;
|
|
51949
52052
|
try {
|
|
51950
|
-
await this.
|
|
52053
|
+
await new deployment_merge_effects_1.DeploymentMergeEffects(this.dependencies.pullRequests).configure(operation, pullRequest, inspection, (current) => this.inspectMergeBehavior(context, operation, current.baseBranch, targetRole, current.headSha, current.number), async (mode) => {
|
|
52054
|
+
managed = { ...operation, selectedPrMode: mode };
|
|
52055
|
+
await this.persist(context, managed);
|
|
52056
|
+
});
|
|
51951
52057
|
}
|
|
51952
52058
|
catch (cause) {
|
|
51953
|
-
const
|
|
51954
|
-
const
|
|
51955
|
-
|
|
52059
|
+
const diagnostic = (0, application_error_1.toApplicationError)(cause, "workflow.failed", "Automatic merge setup failed with an unclassified provider rejection.", { retryable: true });
|
|
52060
|
+
const message = `GitHub could not configure automatic merge for PR #${pullRequest.number}. ${diagnostic.message} Check the PR and retry the stored ${category} phase.`;
|
|
52061
|
+
const error = new application_error_1.ApplicationError(diagnostic.code, message, { cause, retryable: diagnostic.retryable });
|
|
52062
|
+
return { kind: "blocked", result: await this.block(context, managed, category, message, error.retryable, error) };
|
|
51956
52063
|
}
|
|
51957
52064
|
await this.publishDashboard(context, managed);
|
|
51958
52065
|
return { kind: "configured", operation: managed };
|
|
@@ -52007,27 +52114,6 @@ class DeploymentOrchestrationRuntime {
|
|
|
52007
52114
|
// Preserve the original provider failure returned by the coordinator.
|
|
52008
52115
|
}
|
|
52009
52116
|
}
|
|
52010
|
-
async applyMergeBehavior(context, operation, pullRequest, inspection) {
|
|
52011
|
-
if (inspection.decision.mode === "auto-merge") {
|
|
52012
|
-
await this.applyAutoMerge(context, operation, pullRequest, inspection.capabilities);
|
|
52013
|
-
return;
|
|
52014
|
-
}
|
|
52015
|
-
if (inspection.decision.mode === "merge-queue") {
|
|
52016
|
-
const queued = await this.dependencies.pullRequests.isPullRequestQueued(pullRequest.nodeId);
|
|
52017
|
-
if (!queued) {
|
|
52018
|
-
await this.dependencies.pullRequests.enqueuePullRequest(pullRequest.nodeId, pullRequest.headSha);
|
|
52019
|
-
}
|
|
52020
|
-
}
|
|
52021
|
-
}
|
|
52022
|
-
async applyAutoMerge(context, operation, pullRequest, capabilities) {
|
|
52023
|
-
if (operation.prMode === "auto" && capabilities.immediatelyMergeable) {
|
|
52024
|
-
await this.dependencies.pullRequests.mergePullRequest(pullRequest.number, pullRequest.headSha);
|
|
52025
|
-
return;
|
|
52026
|
-
}
|
|
52027
|
-
if (!pullRequest.autoMergeEnabled) {
|
|
52028
|
-
await this.dependencies.pullRequests.enableAutoMerge(pullRequest.nodeId);
|
|
52029
|
-
}
|
|
52030
|
-
}
|
|
52031
52117
|
async unsupportedMergeBehavior(context, operation, targetRole, targetBranch, capabilities, decision) {
|
|
52032
52118
|
const catalog = await this.presentationCatalog('issue', context, operation);
|
|
52033
52119
|
if (capabilities.mergeQueueObservationProblems.length === 0) {
|
|
@@ -79339,6 +79425,47 @@ function isNotFound(error) {
|
|
|
79339
79425
|
}
|
|
79340
79426
|
|
|
79341
79427
|
|
|
79428
|
+
/***/ }),
|
|
79429
|
+
|
|
79430
|
+
/***/ 30873:
|
|
79431
|
+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
79432
|
+
|
|
79433
|
+
"use strict";
|
|
79434
|
+
|
|
79435
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
79436
|
+
exports.githubDeploymentMergeError = githubDeploymentMergeError;
|
|
79437
|
+
const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
|
|
79438
|
+
/** Never copy provider messages, request objects, headers, or arbitrary error types into public state. */
|
|
79439
|
+
function githubDeploymentMergeError(action, cause) {
|
|
79440
|
+
const value = isRecord(cause) ? cause : {};
|
|
79441
|
+
const status = typeof value.status === "number" && Number.isInteger(value.status)
|
|
79442
|
+
&& value.status >= 100 && value.status <= 599 ? value.status : undefined;
|
|
79443
|
+
const rawErrors = Array.isArray(value.errors) ? value.errors : [];
|
|
79444
|
+
const errors = rawErrors.filter(isRecord);
|
|
79445
|
+
const types = errors.map((error) => error.type);
|
|
79446
|
+
const denied = status === 401 || status === 403 || types.includes("FORBIDDEN") || types.includes("UNAUTHORIZED");
|
|
79447
|
+
const limited = status === 429 || types.includes("RATE_LIMITED");
|
|
79448
|
+
const unavailable = (status !== undefined && status >= 500) || types.includes("INTERNAL") || types.includes("SERVICE_UNAVAILABLE");
|
|
79449
|
+
const cleanRejection = rawErrors.length === 1 && errors.length === 1 && errors[0].type === "UNPROCESSABLE"
|
|
79450
|
+
&& typeof errors[0].message === "string"
|
|
79451
|
+
&& ["Pull request is in clean status", "Pull request Pull request is in clean status",
|
|
79452
|
+
"Pull request is in unstable status", "Pull request Pull request is in unstable status"].includes(errors[0].message);
|
|
79453
|
+
const readinessChanged = !denied && !limited && !unavailable
|
|
79454
|
+
&& ((action === "merge" && status === 405) || (action === "enable-auto-merge" && (status === undefined || status === 200) && cleanRejection));
|
|
79455
|
+
const code = denied ? "authorization.denied"
|
|
79456
|
+
: limited ? "provider.rate-limited"
|
|
79457
|
+
: unavailable ? "provider.unavailable"
|
|
79458
|
+
: status === 404 || types.includes("NOT_FOUND") ? "provider.not-found"
|
|
79459
|
+
: status !== undefined || types.length > 0 ? "provider.conflict" : "workflow.failed";
|
|
79460
|
+
const reason = readinessChanged ? "readiness-changed" : code;
|
|
79461
|
+
const http = status === undefined ? "" : `; HTTP ${status}`;
|
|
79462
|
+
return new deployment_merge_effect_error_1.DeploymentMergeEffectError(action, readinessChanged, code, `GitHub rejected ${action} (${reason}${http}).`, cause);
|
|
79463
|
+
}
|
|
79464
|
+
function isRecord(value) {
|
|
79465
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
79466
|
+
}
|
|
79467
|
+
|
|
79468
|
+
|
|
79342
79469
|
/***/ }),
|
|
79343
79470
|
|
|
79344
79471
|
/***/ 96483:
|
|
@@ -79349,6 +79476,8 @@ function isNotFound(error) {
|
|
|
79349
79476
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
79350
79477
|
exports.GithubManagedPullRequestRepository = void 0;
|
|
79351
79478
|
const managed_pull_request_1 = __nccwpck_require__(95914);
|
|
79479
|
+
const github_deployment_merge_error_1 = __nccwpck_require__(30873);
|
|
79480
|
+
const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
|
|
79352
79481
|
class GithubManagedPullRequestRepository {
|
|
79353
79482
|
constructor(clientProvider) {
|
|
79354
79483
|
this.clientProvider = clientProvider;
|
|
@@ -79392,12 +79521,21 @@ class GithubManagedPullRequestRepository {
|
|
|
79392
79521
|
});
|
|
79393
79522
|
return mapPullRequest(data, owner, repository);
|
|
79394
79523
|
}
|
|
79395
|
-
async enableAutoMerge(
|
|
79396
|
-
|
|
79397
|
-
|
|
79398
|
-
|
|
79524
|
+
async enableAutoMerge(_owner, _repository, pullRequestNodeId, expectedHeadSha, token) {
|
|
79525
|
+
let response;
|
|
79526
|
+
try {
|
|
79527
|
+
response = await this.clientProvider.getClient(token).graphql(`mutation EnableDeploymentAutoMerge($pullRequestId: ID!, $expectedHeadOid: GitObjectID!) {
|
|
79528
|
+
enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, expectedHeadOid: $expectedHeadOid, mergeMethod: MERGE}) {
|
|
79529
|
+
pullRequest { id }
|
|
79530
|
+
}
|
|
79531
|
+
}`, { pullRequestId: pullRequestNodeId, expectedHeadOid: expectedHeadSha });
|
|
79532
|
+
}
|
|
79533
|
+
catch (cause) {
|
|
79534
|
+
throw (0, github_deployment_merge_error_1.githubDeploymentMergeError)("enable-auto-merge", cause);
|
|
79535
|
+
}
|
|
79536
|
+
if (response?.enablePullRequestAutoMerge?.pullRequest?.id !== pullRequestNodeId) {
|
|
79537
|
+
throw new deployment_merge_effect_error_1.DeploymentMergeEffectError("enable-auto-merge", false, "provider.contract-invalid", "GitHub did not confirm native auto-merge for the expected PR.");
|
|
79399
79538
|
}
|
|
79400
|
-
}`, { pullRequestId: pullRequestNodeId, owner, repository });
|
|
79401
79539
|
}
|
|
79402
79540
|
async isPullRequestQueued(owner, repository, pullRequestNodeId, token) {
|
|
79403
79541
|
const response = await this.clientProvider.getClient(token).graphql(`query DeploymentPullRequestQueue($pullRequestId: ID!) {
|
|
@@ -79421,15 +79559,18 @@ class GithubManagedPullRequestRepository {
|
|
|
79421
79559
|
}
|
|
79422
79560
|
}
|
|
79423
79561
|
async mergePullRequest(owner, repository, pullRequest, expectedHeadSha, token) {
|
|
79424
|
-
|
|
79425
|
-
|
|
79426
|
-
|
|
79427
|
-
|
|
79428
|
-
|
|
79429
|
-
|
|
79430
|
-
|
|
79431
|
-
|
|
79432
|
-
|
|
79562
|
+
let data;
|
|
79563
|
+
try {
|
|
79564
|
+
({ data } = await this.clientProvider.getClient(token).rest.pulls.merge({
|
|
79565
|
+
owner, repo: repository, pull_number: pullRequest, merge_method: "merge", sha: expectedHeadSha,
|
|
79566
|
+
}));
|
|
79567
|
+
}
|
|
79568
|
+
catch (cause) {
|
|
79569
|
+
throw (0, github_deployment_merge_error_1.githubDeploymentMergeError)("merge", cause);
|
|
79570
|
+
}
|
|
79571
|
+
if (!data?.merged || typeof data.sha !== "string" || !/^[a-f0-9]{40}$/i.test(data.sha)) {
|
|
79572
|
+
throw new deployment_merge_effect_error_1.DeploymentMergeEffectError("merge", false, "provider.contract-invalid", "GitHub did not confirm a completed merge with a valid commit SHA.");
|
|
79573
|
+
}
|
|
79433
79574
|
return data.sha;
|
|
79434
79575
|
}
|
|
79435
79576
|
}
|
|
@@ -92473,7 +92614,7 @@ function bindManagedPullRequests(port, binding) {
|
|
|
92473
92614
|
findManagedPullRequests: (query) => port.findManagedPullRequests({ ...query, owner: binding.owner, repository: binding.repository, token: binding.token }),
|
|
92474
92615
|
createManagedPullRequest: (command) => port.createManagedPullRequest({ ...command, owner: binding.owner, repository: binding.repository, token: binding.token }),
|
|
92475
92616
|
getPullRequest: (pullRequest) => port.getPullRequest(binding.owner, binding.repository, pullRequest, binding.token),
|
|
92476
|
-
enableAutoMerge: (pullRequestNodeId) => port.enableAutoMerge(binding.owner, binding.repository, pullRequestNodeId, binding.token),
|
|
92617
|
+
enableAutoMerge: (pullRequestNodeId, expectedHeadSha) => port.enableAutoMerge(binding.owner, binding.repository, pullRequestNodeId, expectedHeadSha, binding.token),
|
|
92477
92618
|
isPullRequestQueued: (pullRequestNodeId) => port.isPullRequestQueued(binding.owner, binding.repository, pullRequestNodeId, binding.token),
|
|
92478
92619
|
enqueuePullRequest: (pullRequestNodeId, expectedHeadSha) => port.enqueuePullRequest(binding.owner, binding.repository, pullRequestNodeId, expectedHeadSha, binding.token),
|
|
92479
92620
|
mergePullRequest: (pullRequest, expectedHeadSha) => port.mergePullRequest(binding.owner, binding.repository, pullRequest, expectedHeadSha, binding.token),
|
|
@@ -38816,6 +38816,27 @@ function runAtApplicationErrorBoundary(operation) {
|
|
|
38816
38816
|
}
|
|
38817
38817
|
|
|
38818
38818
|
|
|
38819
|
+
/***/ }),
|
|
38820
|
+
|
|
38821
|
+
/***/ 72594:
|
|
38822
|
+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
38823
|
+
|
|
38824
|
+
"use strict";
|
|
38825
|
+
|
|
38826
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
38827
|
+
exports.DeploymentMergeEffectError = void 0;
|
|
38828
|
+
const application_error_1 = __nccwpck_require__(75999);
|
|
38829
|
+
/** Semantic effect failure. Only a confirmed readiness rejection permits one new inspection. */
|
|
38830
|
+
class DeploymentMergeEffectError extends application_error_1.ApplicationError {
|
|
38831
|
+
constructor(action, readinessChanged, code, message, cause) {
|
|
38832
|
+
super(code, message, { cause });
|
|
38833
|
+
this.action = action;
|
|
38834
|
+
this.readinessChanged = readinessChanged;
|
|
38835
|
+
}
|
|
38836
|
+
}
|
|
38837
|
+
exports.DeploymentMergeEffectError = DeploymentMergeEffectError;
|
|
38838
|
+
|
|
38839
|
+
|
|
38819
38840
|
/***/ }),
|
|
38820
38841
|
|
|
38821
38842
|
/***/ 61544:
|
|
@@ -50157,6 +50178,91 @@ function bindSddEvidenceReadPorts(ports) {
|
|
|
50157
50178
|
}
|
|
50158
50179
|
|
|
50159
50180
|
|
|
50181
|
+
/***/ }),
|
|
50182
|
+
|
|
50183
|
+
/***/ 84387:
|
|
50184
|
+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
50185
|
+
|
|
50186
|
+
"use strict";
|
|
50187
|
+
|
|
50188
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
50189
|
+
exports.DeploymentMergeEffects = void 0;
|
|
50190
|
+
const application_error_1 = __nccwpck_require__(75999);
|
|
50191
|
+
const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
|
|
50192
|
+
const managed_pull_request_1 = __nccwpck_require__(95914);
|
|
50193
|
+
/** Applies current policy, with one bounded re-observation after a typed readiness rejection. */
|
|
50194
|
+
class DeploymentMergeEffects {
|
|
50195
|
+
constructor(pullRequests) {
|
|
50196
|
+
this.pullRequests = pullRequests;
|
|
50197
|
+
}
|
|
50198
|
+
async configure(operation, pullRequest, inspection, inspect, beforeApply) {
|
|
50199
|
+
await beforeApply(inspection.decision.mode);
|
|
50200
|
+
const action = selectAction(operation, inspection);
|
|
50201
|
+
try {
|
|
50202
|
+
await this.apply(action, pullRequest);
|
|
50203
|
+
return inspection.decision.mode;
|
|
50204
|
+
}
|
|
50205
|
+
catch (error) {
|
|
50206
|
+
if (!(error instanceof deployment_merge_effect_error_1.DeploymentMergeEffectError) || !error.readinessChanged || operation.prMode !== "auto")
|
|
50207
|
+
throw error;
|
|
50208
|
+
const current = await this.pullRequests.getPullRequest(pullRequest.number);
|
|
50209
|
+
assertSamePullRequest(pullRequest, current);
|
|
50210
|
+
if (current.merged)
|
|
50211
|
+
return inspection.decision.mode;
|
|
50212
|
+
if (current.state !== "open")
|
|
50213
|
+
throw new application_error_1.ApplicationError("provider.conflict", "The managed PR was closed without merging.");
|
|
50214
|
+
const refreshed = await inspect(current);
|
|
50215
|
+
if (refreshed.kind === "blocked")
|
|
50216
|
+
throw new application_error_1.ApplicationError("provider.conflict", refreshed.reason);
|
|
50217
|
+
const nextAction = selectAction(operation, refreshed);
|
|
50218
|
+
if (nextAction === action) {
|
|
50219
|
+
if (action === "enable-auto-merge" && current.autoMergeEnabled)
|
|
50220
|
+
return refreshed.decision.mode;
|
|
50221
|
+
throw error;
|
|
50222
|
+
}
|
|
50223
|
+
await beforeApply(refreshed.decision.mode);
|
|
50224
|
+
await this.apply(nextAction, current);
|
|
50225
|
+
return refreshed.decision.mode;
|
|
50226
|
+
}
|
|
50227
|
+
}
|
|
50228
|
+
async apply(action, pullRequest) {
|
|
50229
|
+
try {
|
|
50230
|
+
if (action === "merge") {
|
|
50231
|
+
await this.pullRequests.mergePullRequest(pullRequest.number, pullRequest.headSha);
|
|
50232
|
+
}
|
|
50233
|
+
else if (action === "enable-auto-merge" && !pullRequest.autoMergeEnabled) {
|
|
50234
|
+
await this.pullRequests.enableAutoMerge(pullRequest.nodeId, pullRequest.headSha);
|
|
50235
|
+
}
|
|
50236
|
+
else if (action === "merge-queue" && !await this.pullRequests.isPullRequestQueued(pullRequest.nodeId)) {
|
|
50237
|
+
await this.pullRequests.enqueuePullRequest(pullRequest.nodeId, pullRequest.headSha);
|
|
50238
|
+
}
|
|
50239
|
+
}
|
|
50240
|
+
catch (cause) {
|
|
50241
|
+
if (cause instanceof application_error_1.ApplicationError)
|
|
50242
|
+
throw cause;
|
|
50243
|
+
throw new application_error_1.ApplicationError("workflow.failed", `Automatic merge action ${action} failed with an unclassified provider rejection.`, { cause, retryable: true });
|
|
50244
|
+
}
|
|
50245
|
+
}
|
|
50246
|
+
}
|
|
50247
|
+
exports.DeploymentMergeEffects = DeploymentMergeEffects;
|
|
50248
|
+
function selectAction(operation, inspection) {
|
|
50249
|
+
if (inspection.decision.mode !== "auto-merge")
|
|
50250
|
+
return inspection.decision.mode;
|
|
50251
|
+
return operation.prMode === "auto" && inspection.capabilities.immediatelyMergeable ? "merge" : "enable-auto-merge";
|
|
50252
|
+
}
|
|
50253
|
+
function assertSamePullRequest(expected, current) {
|
|
50254
|
+
const marker = (0, managed_pull_request_1.parseManagedPullRequestMarker)(expected.body);
|
|
50255
|
+
const currentMarker = (0, managed_pull_request_1.parseManagedPullRequestMarker)(current.body);
|
|
50256
|
+
if (expected.number !== current.number || expected.nodeId !== current.nodeId
|
|
50257
|
+
|| expected.repositoryFullName !== current.repositoryFullName || expected.baseBranch !== current.baseBranch
|
|
50258
|
+
|| expected.headBranch !== current.headBranch || expected.headSha !== current.headSha
|
|
50259
|
+
|| !marker || !currentMarker || marker.operationId !== currentMarker.operationId
|
|
50260
|
+
|| marker.phase !== currentMarker.phase || marker.issue !== currentMarker.issue) {
|
|
50261
|
+
throw new application_error_1.ApplicationError("provider.conflict", "The managed PR identity or frozen head changed during merge setup.", { retryable: false });
|
|
50262
|
+
}
|
|
50263
|
+
}
|
|
50264
|
+
|
|
50265
|
+
|
|
50160
50266
|
/***/ }),
|
|
50161
50267
|
|
|
50162
50268
|
/***/ 77658:
|
|
@@ -50181,6 +50287,7 @@ const deployment_message_catalog_1 = __nccwpck_require__(79364);
|
|
|
50181
50287
|
const deployment_operation_1 = __nccwpck_require__(92730);
|
|
50182
50288
|
const merge_queue_readiness_1 = __nccwpck_require__(12515);
|
|
50183
50289
|
const result_1 = __nccwpck_require__(73817);
|
|
50290
|
+
const deployment_merge_effects_1 = __nccwpck_require__(84387);
|
|
50184
50291
|
exports.DEPLOYMENT_ORCHESTRATION_TASK_ID = "DeploymentOrchestrationUseCase";
|
|
50185
50292
|
class DeploymentOrchestrationRuntime {
|
|
50186
50293
|
constructor(dependencies, stateBoundary) {
|
|
@@ -50255,18 +50362,18 @@ class DeploymentOrchestrationRuntime {
|
|
|
50255
50362
|
result: await this.block(context, operation, category, inspection.reason, true),
|
|
50256
50363
|
};
|
|
50257
50364
|
}
|
|
50258
|
-
|
|
50259
|
-
...operation,
|
|
50260
|
-
selectedPrMode: inspection.decision.mode,
|
|
50261
|
-
};
|
|
50262
|
-
await this.persist(context, managed);
|
|
50365
|
+
let managed = operation;
|
|
50263
50366
|
try {
|
|
50264
|
-
await this.
|
|
50367
|
+
await new deployment_merge_effects_1.DeploymentMergeEffects(this.dependencies.pullRequests).configure(operation, pullRequest, inspection, (current) => this.inspectMergeBehavior(context, operation, current.baseBranch, targetRole, current.headSha, current.number), async (mode) => {
|
|
50368
|
+
managed = { ...operation, selectedPrMode: mode };
|
|
50369
|
+
await this.persist(context, managed);
|
|
50370
|
+
});
|
|
50265
50371
|
}
|
|
50266
50372
|
catch (cause) {
|
|
50267
|
-
const
|
|
50268
|
-
const
|
|
50269
|
-
|
|
50373
|
+
const diagnostic = (0, application_error_1.toApplicationError)(cause, "workflow.failed", "Automatic merge setup failed with an unclassified provider rejection.", { retryable: true });
|
|
50374
|
+
const message = `GitHub could not configure automatic merge for PR #${pullRequest.number}. ${diagnostic.message} Check the PR and retry the stored ${category} phase.`;
|
|
50375
|
+
const error = new application_error_1.ApplicationError(diagnostic.code, message, { cause, retryable: diagnostic.retryable });
|
|
50376
|
+
return { kind: "blocked", result: await this.block(context, managed, category, message, error.retryable, error) };
|
|
50270
50377
|
}
|
|
50271
50378
|
await this.publishDashboard(context, managed);
|
|
50272
50379
|
return { kind: "configured", operation: managed };
|
|
@@ -50321,27 +50428,6 @@ class DeploymentOrchestrationRuntime {
|
|
|
50321
50428
|
// Preserve the original provider failure returned by the coordinator.
|
|
50322
50429
|
}
|
|
50323
50430
|
}
|
|
50324
|
-
async applyMergeBehavior(context, operation, pullRequest, inspection) {
|
|
50325
|
-
if (inspection.decision.mode === "auto-merge") {
|
|
50326
|
-
await this.applyAutoMerge(context, operation, pullRequest, inspection.capabilities);
|
|
50327
|
-
return;
|
|
50328
|
-
}
|
|
50329
|
-
if (inspection.decision.mode === "merge-queue") {
|
|
50330
|
-
const queued = await this.dependencies.pullRequests.isPullRequestQueued(pullRequest.nodeId);
|
|
50331
|
-
if (!queued) {
|
|
50332
|
-
await this.dependencies.pullRequests.enqueuePullRequest(pullRequest.nodeId, pullRequest.headSha);
|
|
50333
|
-
}
|
|
50334
|
-
}
|
|
50335
|
-
}
|
|
50336
|
-
async applyAutoMerge(context, operation, pullRequest, capabilities) {
|
|
50337
|
-
if (operation.prMode === "auto" && capabilities.immediatelyMergeable) {
|
|
50338
|
-
await this.dependencies.pullRequests.mergePullRequest(pullRequest.number, pullRequest.headSha);
|
|
50339
|
-
return;
|
|
50340
|
-
}
|
|
50341
|
-
if (!pullRequest.autoMergeEnabled) {
|
|
50342
|
-
await this.dependencies.pullRequests.enableAutoMerge(pullRequest.nodeId);
|
|
50343
|
-
}
|
|
50344
|
-
}
|
|
50345
50431
|
async unsupportedMergeBehavior(context, operation, targetRole, targetBranch, capabilities, decision) {
|
|
50346
50432
|
const catalog = await this.presentationCatalog('issue', context, operation);
|
|
50347
50433
|
if (capabilities.mergeQueueObservationProblems.length === 0) {
|
|
@@ -71607,6 +71693,47 @@ function isNotFound(error) {
|
|
|
71607
71693
|
}
|
|
71608
71694
|
|
|
71609
71695
|
|
|
71696
|
+
/***/ }),
|
|
71697
|
+
|
|
71698
|
+
/***/ 30873:
|
|
71699
|
+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
71700
|
+
|
|
71701
|
+
"use strict";
|
|
71702
|
+
|
|
71703
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
71704
|
+
exports.githubDeploymentMergeError = githubDeploymentMergeError;
|
|
71705
|
+
const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
|
|
71706
|
+
/** Never copy provider messages, request objects, headers, or arbitrary error types into public state. */
|
|
71707
|
+
function githubDeploymentMergeError(action, cause) {
|
|
71708
|
+
const value = isRecord(cause) ? cause : {};
|
|
71709
|
+
const status = typeof value.status === "number" && Number.isInteger(value.status)
|
|
71710
|
+
&& value.status >= 100 && value.status <= 599 ? value.status : undefined;
|
|
71711
|
+
const rawErrors = Array.isArray(value.errors) ? value.errors : [];
|
|
71712
|
+
const errors = rawErrors.filter(isRecord);
|
|
71713
|
+
const types = errors.map((error) => error.type);
|
|
71714
|
+
const denied = status === 401 || status === 403 || types.includes("FORBIDDEN") || types.includes("UNAUTHORIZED");
|
|
71715
|
+
const limited = status === 429 || types.includes("RATE_LIMITED");
|
|
71716
|
+
const unavailable = (status !== undefined && status >= 500) || types.includes("INTERNAL") || types.includes("SERVICE_UNAVAILABLE");
|
|
71717
|
+
const cleanRejection = rawErrors.length === 1 && errors.length === 1 && errors[0].type === "UNPROCESSABLE"
|
|
71718
|
+
&& typeof errors[0].message === "string"
|
|
71719
|
+
&& ["Pull request is in clean status", "Pull request Pull request is in clean status",
|
|
71720
|
+
"Pull request is in unstable status", "Pull request Pull request is in unstable status"].includes(errors[0].message);
|
|
71721
|
+
const readinessChanged = !denied && !limited && !unavailable
|
|
71722
|
+
&& ((action === "merge" && status === 405) || (action === "enable-auto-merge" && (status === undefined || status === 200) && cleanRejection));
|
|
71723
|
+
const code = denied ? "authorization.denied"
|
|
71724
|
+
: limited ? "provider.rate-limited"
|
|
71725
|
+
: unavailable ? "provider.unavailable"
|
|
71726
|
+
: status === 404 || types.includes("NOT_FOUND") ? "provider.not-found"
|
|
71727
|
+
: status !== undefined || types.length > 0 ? "provider.conflict" : "workflow.failed";
|
|
71728
|
+
const reason = readinessChanged ? "readiness-changed" : code;
|
|
71729
|
+
const http = status === undefined ? "" : `; HTTP ${status}`;
|
|
71730
|
+
return new deployment_merge_effect_error_1.DeploymentMergeEffectError(action, readinessChanged, code, `GitHub rejected ${action} (${reason}${http}).`, cause);
|
|
71731
|
+
}
|
|
71732
|
+
function isRecord(value) {
|
|
71733
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
71734
|
+
}
|
|
71735
|
+
|
|
71736
|
+
|
|
71610
71737
|
/***/ }),
|
|
71611
71738
|
|
|
71612
71739
|
/***/ 96483:
|
|
@@ -71617,6 +71744,8 @@ function isNotFound(error) {
|
|
|
71617
71744
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
71618
71745
|
exports.GithubManagedPullRequestRepository = void 0;
|
|
71619
71746
|
const managed_pull_request_1 = __nccwpck_require__(95914);
|
|
71747
|
+
const github_deployment_merge_error_1 = __nccwpck_require__(30873);
|
|
71748
|
+
const deployment_merge_effect_error_1 = __nccwpck_require__(72594);
|
|
71620
71749
|
class GithubManagedPullRequestRepository {
|
|
71621
71750
|
constructor(clientProvider) {
|
|
71622
71751
|
this.clientProvider = clientProvider;
|
|
@@ -71660,12 +71789,21 @@ class GithubManagedPullRequestRepository {
|
|
|
71660
71789
|
});
|
|
71661
71790
|
return mapPullRequest(data, owner, repository);
|
|
71662
71791
|
}
|
|
71663
|
-
async enableAutoMerge(
|
|
71664
|
-
|
|
71665
|
-
|
|
71666
|
-
|
|
71792
|
+
async enableAutoMerge(_owner, _repository, pullRequestNodeId, expectedHeadSha, token) {
|
|
71793
|
+
let response;
|
|
71794
|
+
try {
|
|
71795
|
+
response = await this.clientProvider.getClient(token).graphql(`mutation EnableDeploymentAutoMerge($pullRequestId: ID!, $expectedHeadOid: GitObjectID!) {
|
|
71796
|
+
enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, expectedHeadOid: $expectedHeadOid, mergeMethod: MERGE}) {
|
|
71797
|
+
pullRequest { id }
|
|
71798
|
+
}
|
|
71799
|
+
}`, { pullRequestId: pullRequestNodeId, expectedHeadOid: expectedHeadSha });
|
|
71800
|
+
}
|
|
71801
|
+
catch (cause) {
|
|
71802
|
+
throw (0, github_deployment_merge_error_1.githubDeploymentMergeError)("enable-auto-merge", cause);
|
|
71803
|
+
}
|
|
71804
|
+
if (response?.enablePullRequestAutoMerge?.pullRequest?.id !== pullRequestNodeId) {
|
|
71805
|
+
throw new deployment_merge_effect_error_1.DeploymentMergeEffectError("enable-auto-merge", false, "provider.contract-invalid", "GitHub did not confirm native auto-merge for the expected PR.");
|
|
71667
71806
|
}
|
|
71668
|
-
}`, { pullRequestId: pullRequestNodeId, owner, repository });
|
|
71669
71807
|
}
|
|
71670
71808
|
async isPullRequestQueued(owner, repository, pullRequestNodeId, token) {
|
|
71671
71809
|
const response = await this.clientProvider.getClient(token).graphql(`query DeploymentPullRequestQueue($pullRequestId: ID!) {
|
|
@@ -71689,15 +71827,18 @@ class GithubManagedPullRequestRepository {
|
|
|
71689
71827
|
}
|
|
71690
71828
|
}
|
|
71691
71829
|
async mergePullRequest(owner, repository, pullRequest, expectedHeadSha, token) {
|
|
71692
|
-
|
|
71693
|
-
|
|
71694
|
-
|
|
71695
|
-
|
|
71696
|
-
|
|
71697
|
-
|
|
71698
|
-
|
|
71699
|
-
|
|
71700
|
-
|
|
71830
|
+
let data;
|
|
71831
|
+
try {
|
|
71832
|
+
({ data } = await this.clientProvider.getClient(token).rest.pulls.merge({
|
|
71833
|
+
owner, repo: repository, pull_number: pullRequest, merge_method: "merge", sha: expectedHeadSha,
|
|
71834
|
+
}));
|
|
71835
|
+
}
|
|
71836
|
+
catch (cause) {
|
|
71837
|
+
throw (0, github_deployment_merge_error_1.githubDeploymentMergeError)("merge", cause);
|
|
71838
|
+
}
|
|
71839
|
+
if (!data?.merged || typeof data.sha !== "string" || !/^[a-f0-9]{40}$/i.test(data.sha)) {
|
|
71840
|
+
throw new deployment_merge_effect_error_1.DeploymentMergeEffectError("merge", false, "provider.contract-invalid", "GitHub did not confirm a completed merge with a valid commit SHA.");
|
|
71841
|
+
}
|
|
71701
71842
|
return data.sha;
|
|
71702
71843
|
}
|
|
71703
71844
|
}
|
|
@@ -84907,7 +85048,7 @@ function bindManagedPullRequests(port, binding) {
|
|
|
84907
85048
|
findManagedPullRequests: (query) => port.findManagedPullRequests({ ...query, owner: binding.owner, repository: binding.repository, token: binding.token }),
|
|
84908
85049
|
createManagedPullRequest: (command) => port.createManagedPullRequest({ ...command, owner: binding.owner, repository: binding.repository, token: binding.token }),
|
|
84909
85050
|
getPullRequest: (pullRequest) => port.getPullRequest(binding.owner, binding.repository, pullRequest, binding.token),
|
|
84910
|
-
enableAutoMerge: (pullRequestNodeId) => port.enableAutoMerge(binding.owner, binding.repository, pullRequestNodeId, binding.token),
|
|
85051
|
+
enableAutoMerge: (pullRequestNodeId, expectedHeadSha) => port.enableAutoMerge(binding.owner, binding.repository, pullRequestNodeId, expectedHeadSha, binding.token),
|
|
84911
85052
|
isPullRequestQueued: (pullRequestNodeId) => port.isPullRequestQueued(binding.owner, binding.repository, pullRequestNodeId, binding.token),
|
|
84912
85053
|
enqueuePullRequest: (pullRequestNodeId, expectedHeadSha) => port.enqueuePullRequest(binding.owner, binding.repository, pullRequestNodeId, expectedHeadSha, binding.token),
|
|
84913
85054
|
mergePullRequest: (pullRequest, expectedHeadSha) => port.mergePullRequest(binding.owner, binding.repository, pullRequest, expectedHeadSha, binding.token),
|