@atolis-hq/wake 0.4.105 → 0.4.106
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/dist/src/activities/agent/agent-activity.js +7 -0
- package/dist/src/activities/contracts/activity.d.ts +12 -0
- package/dist/src/activities/contracts/event-schema.d.ts +314 -8
- package/dist/src/activities/contracts/event-schema.js +20 -2
- package/dist/src/activities/contracts/events.d.ts +10 -0
- package/dist/src/activities/contracts/vocabulary.d.ts +2 -0
- package/dist/src/activities/contracts/vocabulary.js +2 -0
- package/dist/src/activities/index.d.ts +2 -0
- package/dist/src/activities/index.js +2 -0
- package/dist/src/activities/pr/activity-support.d.ts +1 -1
- package/dist/src/activities/pr/activity-support.js +10 -0
- package/dist/src/activities/pr/application.js +8 -1
- package/dist/src/activities/pr/approve.d.ts +2 -1
- package/dist/src/activities/pr/approve.js +33 -11
- package/dist/src/activities/pr/check-evidence.d.ts +10 -0
- package/dist/src/activities/pr/check-evidence.js +16 -0
- package/dist/src/activities/pr/contracts.d.ts +14 -0
- package/dist/src/activities/pr/event-data.js +5 -1
- package/dist/src/activities/pr/merge.d.ts +2 -1
- package/dist/src/activities/pr/merge.js +54 -38
- package/dist/src/activities/pr/parent-scope.d.ts +65 -0
- package/dist/src/activities/pr/parent-scope.js +24 -0
- package/dist/src/activities/pr/parent-target.d.ts +45 -0
- package/dist/src/activities/pr/parent-target.js +59 -0
- package/dist/src/activities/pr/projection.js +10 -2
- package/dist/src/activities/pr/vocabulary.d.ts +8 -0
- package/dist/src/activities/pr/vocabulary.js +8 -0
- package/dist/src/bootstrap/activity-registry.d.ts +2 -2
- package/dist/src/bootstrap/activity-registry.js +3 -3
- package/dist/src/bootstrap/composition-root.js +11 -2
- package/dist/src/bootstrap/config/root-schema.d.ts +6 -0
- package/dist/src/bootstrap/delivery-integration.d.ts +9 -0
- package/dist/src/bootstrap/delivery-integration.js +46 -0
- package/dist/src/bootstrap/surface-api-delivery.js +27 -0
- package/dist/src/bootstrap/version.js +1 -1
- package/dist/src/control-plane/application/activation-scheduler-ports.d.ts +3 -1
- package/dist/src/control-plane/application/advance-once-dispatch.js +10 -6
- package/dist/src/execution/application/execution-service.js +10 -0
- package/dist/src/execution/application/maintenance-workspaces.d.ts +17 -0
- package/dist/src/execution/application/maintenance-workspaces.js +84 -0
- package/dist/src/execution/application/run-lifecycle.js +1 -0
- package/dist/src/execution/contracts/commands.d.ts +2 -0
- package/dist/src/execution/contracts/events.d.ts +13 -0
- package/dist/src/execution/contracts/events.js +2 -0
- package/dist/src/execution/contracts/maintenance.d.ts +36 -0
- package/dist/src/execution/contracts/maintenance.js +44 -0
- package/dist/src/execution/contracts/views.d.ts +2 -0
- package/dist/src/execution/contracts/workspace.d.ts +2 -0
- package/dist/src/execution/index.d.ts +1 -0
- package/dist/src/execution/index.js +1 -0
- package/dist/src/integrations/application/delegation-outputs.js +1 -1
- package/dist/src/integrations/application/delivery-integration-verification.d.ts +13 -0
- package/dist/src/integrations/application/delivery-integration-verification.js +68 -0
- package/dist/src/integrations/delivery/application/delivery-projector.js +3 -0
- package/dist/src/integrations/delivery/application/merged-delivery-evidence.js +9 -1
- package/dist/src/integrations/delivery/contracts/views.d.ts +2 -0
- package/dist/src/integrations/fake/external-source.d.ts +5 -2
- package/dist/src/integrations/fake/external-source.js +12 -2
- package/dist/src/integrations/fake/inbound-translator.js +7 -2
- package/dist/src/integrations/fake/provider.d.ts +17 -0
- package/dist/src/integrations/fake/provider.js +18 -2
- package/dist/src/integrations/github/application/pull-request-translation.js +2 -0
- package/dist/src/integrations/github/contracts/events.d.ts +3 -1
- package/dist/src/integrations/github/contracts/events.js +3 -1
- package/dist/src/integrations/github/contracts/payloads.d.ts +23 -0
- package/dist/src/integrations/github/infrastructure/check-execution.d.ts +9 -0
- package/dist/src/integrations/github/infrastructure/check-execution.js +68 -0
- package/dist/src/integrations/github/infrastructure/checkout-revision.d.ts +2 -0
- package/dist/src/integrations/github/infrastructure/checkout-revision.js +23 -0
- package/dist/src/integrations/github/infrastructure/client.d.ts +2 -0
- package/dist/src/integrations/github/infrastructure/client.js +4 -0
- package/dist/src/integrations/github/infrastructure/pr-check-subject.d.ts +7 -0
- package/dist/src/integrations/github/infrastructure/pr-check-subject.js +77 -0
- package/dist/src/integrations/github/infrastructure/pr-evidence.d.ts +6 -3
- package/dist/src/integrations/github/infrastructure/pr-evidence.js +1 -1
- package/dist/src/integrations/github/infrastructure/pr-source.d.ts +3 -5
- package/dist/src/integrations/github/infrastructure/pr-source.js +11 -1
- package/dist/src/integrations/github/infrastructure/workflow-run-evidence.d.ts +5 -0
- package/dist/src/integrations/github/infrastructure/workflow-run-evidence.js +22 -0
- package/dist/src/integrations/index.d.ts +1 -0
- package/dist/src/integrations/index.js +1 -0
- package/dist/src/orchestration/application/delegation-commands.d.ts +3 -0
- package/dist/src/orchestration/application/delivery-coordinator.d.ts +70 -1
- package/dist/src/orchestration/application/delivery-coordinator.js +31 -5
- package/dist/src/orchestration/application/delivery-facts-reader.js +1 -0
- package/dist/src/orchestration/application/delivery-integration-reader.d.ts +9 -0
- package/dist/src/orchestration/application/delivery-integration-reader.js +23 -0
- package/dist/src/orchestration/application/delivery-integration-service.d.ts +50 -0
- package/dist/src/orchestration/application/delivery-integration-service.js +228 -0
- package/dist/src/orchestration/application/delivery-preparation.d.ts +1 -0
- package/dist/src/orchestration/application/delivery-preparation.js +7 -2
- package/dist/src/orchestration/application/orchestration-service.d.ts +74 -3
- package/dist/src/orchestration/application/orchestration-service.js +55 -2
- package/dist/src/orchestration/contracts/config.d.ts +6 -0
- package/dist/src/orchestration/contracts/config.js +6 -0
- package/dist/src/orchestration/contracts/delivery-ports.d.ts +44 -0
- package/dist/src/orchestration/contracts/delivery.d.ts +58 -0
- package/dist/src/orchestration/contracts/delivery.js +53 -1
- package/dist/src/orchestration/contracts/event-decoder.js +2 -1
- package/dist/src/orchestration/contracts/event-factory.js +2 -0
- package/dist/src/orchestration/contracts/events.d.ts +3 -1
- package/dist/src/orchestration/contracts/events.js +1 -0
- package/dist/src/orchestration/contracts/vocabulary.d.ts +44 -1
- package/dist/src/orchestration/contracts/vocabulary.js +40 -1
- package/dist/src/orchestration/domain/compile-diagnostics.d.ts +1 -1
- package/dist/src/orchestration/domain/compile-diagnostics.js +5 -0
- package/dist/src/orchestration/domain/delivery-candidate.js +13 -0
- package/dist/src/orchestration/domain/delivery-facts.d.ts +7 -1
- package/dist/src/orchestration/domain/delivery-facts.js +33 -1
- package/dist/src/orchestration/domain/delivery-integration-policy.d.ts +7 -0
- package/dist/src/orchestration/domain/delivery-integration-policy.js +15 -0
- package/dist/src/orchestration/domain/delivery-integration.d.ts +54 -0
- package/dist/src/orchestration/domain/delivery-integration.js +144 -0
- package/dist/src/orchestration/domain/delivery-qa.d.ts +2 -1
- package/dist/src/orchestration/domain/delivery-qa.js +24 -4
- package/dist/src/orchestration/domain/delivery-workflow-policy.d.ts +3 -1
- package/dist/src/orchestration/domain/delivery-workflow-policy.js +19 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +1 -0
- package/dist/src/orchestration/index.d.ts +3 -2
- package/dist/src/orchestration/index.js +1 -1
- package/dist/src/surfaces/api/contracts/transport-values.js +1 -0
- package/dist/src/surfaces/api/contracts/work.d.ts +26 -0
- package/dist/src/surfaces/api/presenters/execution.js +1 -0
- package/dist/src/surfaces/mcp/delegation.js +5 -1
- package/dist/src/surfaces/web-assets/assets/index-ih1h3dxC.js +1192 -0
- package/dist/src/surfaces/web-assets/index.html +1 -1
- package/package.json +1 -1
- package/dist/src/surfaces/web-assets/assets/index-BfhxlN_h.js +0 -1192
|
@@ -4,6 +4,7 @@ import { activationId, activityName, activityOrchestrationGroupId, activityWorkf
|
|
|
4
4
|
import { brandedStringSchema, offsetIsoTimestampSchema } from '../../kernel/index.js';
|
|
5
5
|
import { preparedCandidateSchema } from './candidate.js';
|
|
6
6
|
import { runId } from './identifiers.js';
|
|
7
|
+
import { preparedMaintenanceSchema } from './maintenance.js';
|
|
7
8
|
import { repositoryAssignmentSchema } from './repository-assignment.js';
|
|
8
9
|
import { ExecutionStreamKind } from './streams.js';
|
|
9
10
|
import { ExecutionCancellationReason, ExecutionFailureCode, RunStatus, WorkspaceMode, } from './vocabulary.js';
|
|
@@ -35,6 +36,7 @@ export const runStartedPayloadSchema = z
|
|
|
35
36
|
repositoryResourceId: z.string().min(1).optional(),
|
|
36
37
|
checkoutRevision: z.string().min(1).optional(),
|
|
37
38
|
candidate: preparedCandidateSchema.optional(),
|
|
39
|
+
maintenance: preparedMaintenanceSchema.optional(),
|
|
38
40
|
})
|
|
39
41
|
.strict()
|
|
40
42
|
.optional(),
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Selected pull requests an agent may maintain, chosen by Orchestration for one activation.
|
|
4
|
+
* Each target is leased through the child's own recorded branch workspace; the PR keeps its
|
|
5
|
+
* original owner and the maintaining Run is recorded as the actual producer.
|
|
6
|
+
*/
|
|
7
|
+
export declare const executionMaintenanceSchema: z.ZodObject<{
|
|
8
|
+
targets: z.ZodArray<z.ZodObject<{
|
|
9
|
+
childWorkItemId: z.ZodString;
|
|
10
|
+
outputName: z.ZodString;
|
|
11
|
+
resourceId: z.ZodString;
|
|
12
|
+
repository: z.ZodObject<{
|
|
13
|
+
resourceId: z.ZodString;
|
|
14
|
+
sourceRef: z.ZodString;
|
|
15
|
+
sourceRevision: z.ZodString;
|
|
16
|
+
pullRequestBase: z.ZodString;
|
|
17
|
+
}, z.core.$strict>;
|
|
18
|
+
branch: z.ZodString;
|
|
19
|
+
revision: z.ZodString;
|
|
20
|
+
pullRequestBase: z.ZodString;
|
|
21
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
22
|
+
}, z.core.$strict>>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
export type ExecutionMaintenance = z.infer<typeof executionMaintenanceSchema>;
|
|
25
|
+
export declare const preparedMaintenanceSchema: z.ZodObject<{
|
|
26
|
+
targets: z.ZodArray<z.ZodObject<{
|
|
27
|
+
childWorkItemId: z.ZodString;
|
|
28
|
+
outputName: z.ZodString;
|
|
29
|
+
resourceId: z.ZodString;
|
|
30
|
+
branch: z.ZodString;
|
|
31
|
+
revision: z.ZodString;
|
|
32
|
+
path: z.ZodString;
|
|
33
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
34
|
+
}, z.core.$strict>>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
export type PreparedMaintenance = z.infer<typeof preparedMaintenanceSchema>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { repositoryAssignmentSchema } from './repository-assignment.js';
|
|
3
|
+
/**
|
|
4
|
+
* Selected pull requests an agent may maintain, chosen by Orchestration for one activation.
|
|
5
|
+
* Each target is leased through the child's own recorded branch workspace; the PR keeps its
|
|
6
|
+
* original owner and the maintaining Run is recorded as the actual producer.
|
|
7
|
+
*/
|
|
8
|
+
export const executionMaintenanceSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
targets: z
|
|
11
|
+
.array(z
|
|
12
|
+
.object({
|
|
13
|
+
childWorkItemId: z.string().min(1),
|
|
14
|
+
outputName: z.string().min(1),
|
|
15
|
+
resourceId: z.string().min(1),
|
|
16
|
+
/** The repository assignment the child's workspace was created from. */
|
|
17
|
+
repository: repositoryAssignmentSchema,
|
|
18
|
+
branch: z.string().min(1),
|
|
19
|
+
revision: z.string().min(1),
|
|
20
|
+
pullRequestBase: z.string().min(1),
|
|
21
|
+
/** Why integration cannot proceed yet, when it cannot. */
|
|
22
|
+
reason: z.string().min(1).optional(),
|
|
23
|
+
})
|
|
24
|
+
.strict())
|
|
25
|
+
.min(1),
|
|
26
|
+
})
|
|
27
|
+
.strict();
|
|
28
|
+
export const preparedMaintenanceSchema = z
|
|
29
|
+
.object({
|
|
30
|
+
targets: z
|
|
31
|
+
.array(z
|
|
32
|
+
.object({
|
|
33
|
+
childWorkItemId: z.string().min(1),
|
|
34
|
+
outputName: z.string().min(1),
|
|
35
|
+
resourceId: z.string().min(1),
|
|
36
|
+
branch: z.string().min(1),
|
|
37
|
+
revision: z.string().min(1),
|
|
38
|
+
path: z.string().min(1),
|
|
39
|
+
reason: z.string().min(1).optional(),
|
|
40
|
+
})
|
|
41
|
+
.strict())
|
|
42
|
+
.min(1),
|
|
43
|
+
})
|
|
44
|
+
.strict();
|
|
@@ -2,6 +2,7 @@ import type { ActivationId, ActivityName, ActivityOrchestrationGroupId, Activity
|
|
|
2
2
|
import type { PreparedCandidate } from './candidate.js';
|
|
3
3
|
import type { RunId } from './identifiers.js';
|
|
4
4
|
import type { Cancellation, ExternalExecutionReference, Lease } from './liveness.js';
|
|
5
|
+
import type { PreparedMaintenance } from './maintenance.js';
|
|
5
6
|
import type { RepositoryAssignment } from './repository-assignment.js';
|
|
6
7
|
import type { ExecutionFailure } from './results.js';
|
|
7
8
|
import type { AgentRunResponse } from './runner.js';
|
|
@@ -45,6 +46,7 @@ export interface RunView {
|
|
|
45
46
|
readonly repositoryResourceId?: string | undefined;
|
|
46
47
|
readonly checkoutRevision?: string | undefined;
|
|
47
48
|
readonly candidate?: PreparedCandidate | undefined;
|
|
49
|
+
readonly maintenance?: PreparedMaintenance | undefined;
|
|
48
50
|
};
|
|
49
51
|
readonly lease?: Lease;
|
|
50
52
|
readonly externalExecution?: ExternalExecutionReference;
|
|
@@ -2,6 +2,7 @@ import type { ResourceView } from '../../resources/index.js';
|
|
|
2
2
|
import type { WorkItemId } from '../../work/index.js';
|
|
3
3
|
import type { PreparedCandidate } from './candidate.js';
|
|
4
4
|
import type { RunId } from './identifiers.js';
|
|
5
|
+
import type { PreparedMaintenance } from './maintenance.js';
|
|
5
6
|
import type { RepositoryAssignment } from './repository-assignment.js';
|
|
6
7
|
import type { RunView } from './views.js';
|
|
7
8
|
import type { WorkspaceMode } from './vocabulary.js';
|
|
@@ -18,6 +19,7 @@ export interface WorkspaceRequest {
|
|
|
18
19
|
}
|
|
19
20
|
export interface WorkspaceLease {
|
|
20
21
|
readonly candidate?: PreparedCandidate;
|
|
22
|
+
readonly maintenance?: PreparedMaintenance;
|
|
21
23
|
readonly workspaceId: string;
|
|
22
24
|
readonly path: string;
|
|
23
25
|
/** Branch actually checked out for this lease, when the provider can attest it. */
|
|
@@ -38,3 +38,4 @@ export { resolveGitSource } from './infrastructure/workspace/git-source.js';
|
|
|
38
38
|
export * from './contracts/repository-assignment.js';
|
|
39
39
|
export { createRepositoryAssignments } from './application/repository-assignments.js';
|
|
40
40
|
export * from './contracts/candidate.js';
|
|
41
|
+
export * from './contracts/maintenance.js';
|
|
@@ -38,3 +38,4 @@ export { resolveGitSource } from './infrastructure/workspace/git-source.js';
|
|
|
38
38
|
export * from './contracts/repository-assignment.js';
|
|
39
39
|
export { createRepositoryAssignments } from './application/repository-assignments.js';
|
|
40
40
|
export * from './contracts/candidate.js';
|
|
41
|
+
export * from './contracts/maintenance.js';
|
|
@@ -101,7 +101,7 @@ async function qualifyingChange(input, child, output, condition) {
|
|
|
101
101
|
branch,
|
|
102
102
|
pullRequestBase: assignment.pullRequestBase,
|
|
103
103
|
runId: run.runId,
|
|
104
|
-
|
|
104
|
+
baseRevision: observed.baseRevision,
|
|
105
105
|
...(observed.state === PullRequestState.Merged ? { merged: true } : {}),
|
|
106
106
|
},
|
|
107
107
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PullRequestService } from '../../activities/index.js';
|
|
2
|
+
import type { RunView } from '../../execution/index.js';
|
|
3
|
+
import type { DeliveryIntegration } from '../../orchestration/index.js';
|
|
4
|
+
import { type ResourceService } from '../../resources/index.js';
|
|
5
|
+
import type { ProviderInstance } from '../contracts/provider.js';
|
|
6
|
+
export type DeliveryIntegrationVerification = Pick<DeliveryIntegration, 'verifyTarget'>;
|
|
7
|
+
/** Reuses provider artifact verification and the target's own current review/check authority. */
|
|
8
|
+
export declare function createDeliveryIntegrationVerification(input: {
|
|
9
|
+
readonly resources: ResourceService;
|
|
10
|
+
readonly pullRequests: PullRequestService;
|
|
11
|
+
readonly runs: () => Promise<readonly RunView[]>;
|
|
12
|
+
readonly providers: () => Promise<readonly ProviderInstance[]>;
|
|
13
|
+
}): DeliveryIntegrationVerification;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ActivityEventType, decidePullRequestOutputAuthority, } from '../../activities/index.js';
|
|
2
|
+
import { BuiltInResourceKind, resourceId } from '../../resources/index.js';
|
|
3
|
+
/** Reuses provider artifact verification and the target's own current review/check authority. */
|
|
4
|
+
export function createDeliveryIntegrationVerification(input) {
|
|
5
|
+
return {
|
|
6
|
+
async verifyTarget(request) {
|
|
7
|
+
const resource = await input.resources.get(resourceId(request.resourceId));
|
|
8
|
+
const repository = await input.resources.get(resourceId(request.repositoryResourceId));
|
|
9
|
+
const owner = await input.resources.primaryCorrelation(resourceId(request.resourceId));
|
|
10
|
+
if (resource === null || repository === null || owner?.workItemId !== request.ownerWorkItemId)
|
|
11
|
+
return false;
|
|
12
|
+
const provider = (await input.providers()).find((entry) => entry.adapter === resource.externalKey.adapter);
|
|
13
|
+
if (provider === undefined)
|
|
14
|
+
return false;
|
|
15
|
+
const verified = await provider.verifyArtifact(BuiltInResourceKind.PullRequest, resource.externalKey, {
|
|
16
|
+
repository: repository.externalKey,
|
|
17
|
+
workspaceBranch: request.branch,
|
|
18
|
+
workspaceRevision: request.revision,
|
|
19
|
+
pullRequestBase: request.pullRequestBase,
|
|
20
|
+
});
|
|
21
|
+
if (!matchesVerifiedTarget(verified, resource.externalKey, request.revision))
|
|
22
|
+
return false;
|
|
23
|
+
if (!(await freshEvidence(request, input, resource.resourceId)))
|
|
24
|
+
return false;
|
|
25
|
+
const decision = decidePullRequestOutputAuthority(await input.pullRequests.authorityInput(owner.workItemId), {
|
|
26
|
+
target: { resourceId: resource.resourceId },
|
|
27
|
+
requireAcceptedReview: request.requireReview,
|
|
28
|
+
requireChecks: request.requireChecks,
|
|
29
|
+
});
|
|
30
|
+
return decision.allowed && decision.revision.toLowerCase() === request.revision.toLowerCase();
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async function freshEvidence(request, input, id) {
|
|
35
|
+
if (request.maintenanceRunId === undefined)
|
|
36
|
+
return true;
|
|
37
|
+
const run = (await input.runs()).find((entry) => entry.runId === request.maintenanceRunId);
|
|
38
|
+
if (run === undefined)
|
|
39
|
+
return false;
|
|
40
|
+
if (!(await freshChecks(request, input.pullRequests, id, run)))
|
|
41
|
+
return false;
|
|
42
|
+
if (!request.requireReview)
|
|
43
|
+
return true;
|
|
44
|
+
return (await input.pullRequests.factsFor(id)).some(({ event }) => event.eventType === ActivityEventType.ReviewAcceptanceSignalRecorded &&
|
|
45
|
+
event.payload.trusted &&
|
|
46
|
+
event.payload.revision.toLowerCase() === request.revision.toLowerCase() &&
|
|
47
|
+
event.occurredAt >= (run.executionStartedAt ?? run.startedAt));
|
|
48
|
+
}
|
|
49
|
+
function matchesVerifiedTarget(verified, key, revision) {
|
|
50
|
+
return (typeof verified !== 'string' &&
|
|
51
|
+
verified.kind === BuiltInResourceKind.PullRequest &&
|
|
52
|
+
verified.externalKey.adapter === key.adapter &&
|
|
53
|
+
verified.externalKey.key === key.key &&
|
|
54
|
+
verified.revision?.toLowerCase() === revision.toLowerCase());
|
|
55
|
+
}
|
|
56
|
+
async function freshChecks(request, pullRequests, id, run) {
|
|
57
|
+
if (!request.requireChecks)
|
|
58
|
+
return true;
|
|
59
|
+
const view = await pullRequests.get(id);
|
|
60
|
+
const evidence = view?.checkEvidence;
|
|
61
|
+
if (evidence?.testedRevision === undefined || request.baseRevision === undefined)
|
|
62
|
+
return false;
|
|
63
|
+
return (evidence.headRevision.toLowerCase() === request.revision.toLowerCase() &&
|
|
64
|
+
evidence.baseRevision.toLowerCase() === request.baseRevision.toLowerCase() &&
|
|
65
|
+
evidence.baseRevision.toLowerCase() === view.baseRevision.toLowerCase() &&
|
|
66
|
+
Date.parse(evidence.startedAt) >=
|
|
67
|
+
Math.max(Date.parse(request.maintenanceRecordedAt ?? run.finishedAt ?? ''), Date.parse(run.executionStartedAt ?? run.startedAt)));
|
|
68
|
+
}
|
|
@@ -105,6 +105,9 @@ function activityIntentView(event) {
|
|
|
105
105
|
revision: intent.event.payload.revision,
|
|
106
106
|
method: intent.event.payload.method,
|
|
107
107
|
autoMerge: intent.event.payload.autoMerge,
|
|
108
|
+
...(intent.event.payload.parent === undefined
|
|
109
|
+
? {}
|
|
110
|
+
: { ownerWorkItemId: intent.event.payload.parent.ownerWorkItemId }),
|
|
108
111
|
},
|
|
109
112
|
state: DeliveryState.Pending,
|
|
110
113
|
attempts: 0,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventActorKind, EventSourceKind, } from '@atolis-hq/eventing';
|
|
2
2
|
import { ActivityEventType, PullRequestState, selectPrimaryPullRequest, } from '../../../activities/index.js';
|
|
3
3
|
import { ActivityActivationStatus, workflowInstanceId, } from '../../../orchestration/index.js';
|
|
4
|
+
import { workItemId } from '../../../work/index.js';
|
|
4
5
|
import { deliveryStream, IntegrationStreamKind } from '../../contracts/streams.js';
|
|
5
6
|
import { createDeliveryEventData } from '../contracts/event-factory.js';
|
|
6
7
|
import { DeliveryEventType, selectDeliveryEvent } from '../contracts/events.js';
|
|
@@ -10,6 +11,12 @@ export async function reconcileMergedDeliveries(input) {
|
|
|
10
11
|
await confirmMergedDelivery(entry.value, input.journal, input.orchestration, input.pullRequests);
|
|
11
12
|
}
|
|
12
13
|
}
|
|
14
|
+
/** A parent delivery merges a pull request its child owns; the requester never becomes owner. */
|
|
15
|
+
function owningWorkItem(payload, requester) {
|
|
16
|
+
return 'ownerWorkItemId' in payload && payload.ownerWorkItemId !== undefined
|
|
17
|
+
? workItemId(payload.ownerWorkItemId)
|
|
18
|
+
: requester;
|
|
19
|
+
}
|
|
13
20
|
/** Reconcile durable merged evidence only after the exact intent's wait exists. */
|
|
14
21
|
export async function confirmMergedDelivery(intent, journal, orchestration, pullRequests) {
|
|
15
22
|
if (intent.payload.kind !== DeliveryIntentKind.PrMerge ||
|
|
@@ -19,7 +26,8 @@ export async function confirmMergedDelivery(intent, journal, orchestration, pull
|
|
|
19
26
|
const instance = await orchestration.get(workflowInstanceId(intent.workflowInstanceId));
|
|
20
27
|
if (!isMatchingWait(instance, intent))
|
|
21
28
|
return;
|
|
22
|
-
const
|
|
29
|
+
const owner = owningWorkItem(intent.payload, instance.workItemId);
|
|
30
|
+
const selected = selectPrimaryPullRequest(await pullRequests.authorityInput(owner), owner);
|
|
23
31
|
if (selected?.pullRequest.resourceId !== intent.resourceId ||
|
|
24
32
|
selected.pullRequest.state !== PullRequestState.Merged ||
|
|
25
33
|
selected.pullRequest.headRevision !== intent.payload.revision)
|
|
@@ -20,6 +20,8 @@ export interface DeliveryIntentView {
|
|
|
20
20
|
readonly revision: string;
|
|
21
21
|
readonly method: MergeMethod;
|
|
22
22
|
readonly autoMerge: boolean;
|
|
23
|
+
/** Set when a parent delivery merges a child-owned PR: the owner, not the requester. */
|
|
24
|
+
readonly ownerWorkItemId?: string;
|
|
23
25
|
} | {
|
|
24
26
|
readonly kind: typeof DeliveryIntentKind.IssueComplete;
|
|
25
27
|
} | {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ReviewActorKind } from '../../activities/index.js';
|
|
2
|
-
import { PullRequestCheckState } from '../../activities/index.js';
|
|
1
|
+
import type { PullRequestCheckEvidence, PullRequestMergeability, ReviewActorKind } from '../../activities/index.js';
|
|
2
|
+
import { PullRequestCheckState, PullRequestState } from '../../activities/index.js';
|
|
3
3
|
import type { AdapterId } from '../contracts/identifiers.js';
|
|
4
4
|
import type { ExternalEventSource, ProviderEventData } from '../contracts/intake.js';
|
|
5
5
|
export declare const FakeEventType: {
|
|
@@ -13,7 +13,10 @@ export interface FakeWorkEvidence {
|
|
|
13
13
|
readonly kind?: 'issue' | 'pull-request' | undefined;
|
|
14
14
|
readonly revision?: string | undefined;
|
|
15
15
|
readonly baseBranch?: string | undefined;
|
|
16
|
+
readonly checkEvidence?: PullRequestCheckEvidence | undefined;
|
|
16
17
|
readonly baseRevision?: string | undefined;
|
|
18
|
+
readonly state?: PullRequestState | undefined;
|
|
19
|
+
readonly mergeability?: PullRequestMergeability | undefined;
|
|
17
20
|
readonly checks?: typeof PullRequestCheckState.Unknown | typeof PullRequestCheckState.Pending | typeof PullRequestCheckState.Passing | typeof PullRequestCheckState.Failing | undefined;
|
|
18
21
|
readonly acceptedReview?: boolean | undefined;
|
|
19
22
|
readonly reviewActorId?: string | undefined;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { causationId, correlationId, EventActorKind, eventId, EventSourceKind, } from '@atolis-hq/eventing';
|
|
2
|
-
import { PullRequestCheckState } from '../../activities/index.js';
|
|
2
|
+
import { PullRequestCheckState, PullRequestState } from '../../activities/index.js';
|
|
3
3
|
export const FakeEventType = {
|
|
4
4
|
WorkObserved: 'fake.work-observed',
|
|
5
5
|
ReviewRequested: 'fake.review-requested',
|
|
6
6
|
};
|
|
7
7
|
const missingIdentityPart = '_';
|
|
8
|
+
// New provider facts about an unchanged head (merged, moved base) must not collapse into the old event.
|
|
9
|
+
function observationIdentity(payload) {
|
|
10
|
+
const parts = [
|
|
11
|
+
payload.state === undefined || payload.state === PullRequestState.Open ? '' : payload.state,
|
|
12
|
+
payload.baseRevision ?? '',
|
|
13
|
+
payload.checkEvidence?.startedAt ?? '',
|
|
14
|
+
payload.mergeability ?? '',
|
|
15
|
+
];
|
|
16
|
+
return parts.every((part) => part === '') ? '' : `:${parts.join(':')}`;
|
|
17
|
+
}
|
|
8
18
|
export class FakeExternalEventSource {
|
|
9
19
|
adapter;
|
|
10
20
|
events;
|
|
@@ -15,7 +25,7 @@ export class FakeExternalEventSource {
|
|
|
15
25
|
async poll(signal) {
|
|
16
26
|
void signal;
|
|
17
27
|
return this.events.flatMap((payload, ordinal) => {
|
|
18
|
-
const identity = `fake:${this.adapter}:${payload.key}:${payload.revision ?? missingIdentityPart}:${payload.checks ?? PullRequestCheckState.Unknown}:${payload.watchEvent ?? missingIdentityPart}:${ordinal}`;
|
|
28
|
+
const identity = `fake:${this.adapter}:${payload.key}:${payload.revision ?? missingIdentityPart}:${payload.checks ?? PullRequestCheckState.Unknown}:${payload.watchEvent ?? missingIdentityPart}:${ordinal}${observationIdentity(payload)}`;
|
|
19
29
|
const metadata = {
|
|
20
30
|
schemaVersion: 1,
|
|
21
31
|
occurredAt: '2026-08-01T00:00:00.000Z',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { correlationId, defineEventProcessor, EventActorKind, EventProcessorCategory, EventProcessorReplayPolicy, } from '@atolis-hq/eventing';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { PullRequestCheckState, PullRequestState, ReviewActorKind, ReviewerAuthorizationSource, } from '../../activities/index.js';
|
|
3
|
+
import { pullRequestCheckEvidenceSchema, PullRequestCheckState, PullRequestState, ReviewActorKind, ReviewerAuthorizationSource, } from '../../activities/index.js';
|
|
4
4
|
import { BuiltInResourceCapability, BuiltInResourceKind, ResourceCorrelationRole, resourceId, } from '../../resources/index.js';
|
|
5
5
|
import { workItemId } from '../../work/index.js';
|
|
6
6
|
import { admitObservedWork } from '../application/work-admission.js';
|
|
@@ -16,6 +16,9 @@ const evidenceSchema = z
|
|
|
16
16
|
branch: z.string().min(1).optional(),
|
|
17
17
|
baseBranch: z.string().min(1).optional(),
|
|
18
18
|
baseRevision: z.string().min(1).optional(),
|
|
19
|
+
checkEvidence: pullRequestCheckEvidenceSchema.optional(),
|
|
20
|
+
state: z.enum(['open', 'closed', 'merged']).optional(),
|
|
21
|
+
mergeability: z.enum(['unknown', 'clean', 'conflicting']).optional(),
|
|
19
22
|
checks: z.enum(['unknown', 'pending', 'passing', 'failing']).optional(),
|
|
20
23
|
acceptedReview: z.boolean().optional(),
|
|
21
24
|
reviewActorId: z.string().min(1).optional(),
|
|
@@ -134,10 +137,12 @@ export class FakeInboundTranslator {
|
|
|
134
137
|
await this.services.pullRequests.observe({
|
|
135
138
|
resourceId,
|
|
136
139
|
workItemId,
|
|
137
|
-
state: PullRequestState.Open,
|
|
140
|
+
state: evidence.state ?? PullRequestState.Open,
|
|
138
141
|
headRevision: revision,
|
|
142
|
+
checkEvidence: evidence.checkEvidence,
|
|
139
143
|
baseRevision: evidence.baseRevision ?? 'unknown',
|
|
140
144
|
checks: evidence.checks ?? PullRequestCheckState.Unknown,
|
|
145
|
+
...(evidence.mergeability === undefined ? {} : { mergeability: evidence.mergeability }),
|
|
141
146
|
...(evidence.changedFiles === undefined ? {} : { changedFiles: evidence.changedFiles }),
|
|
142
147
|
}, context);
|
|
143
148
|
if (evidence.acceptedReview === true)
|
|
@@ -13,6 +13,22 @@ declare const configSchema: z.ZodObject<{
|
|
|
13
13
|
branch: z.ZodOptional<z.ZodString>;
|
|
14
14
|
baseBranch: z.ZodOptional<z.ZodString>;
|
|
15
15
|
baseRevision: z.ZodOptional<z.ZodString>;
|
|
16
|
+
checkEvidence: z.ZodOptional<z.ZodObject<{
|
|
17
|
+
testedRevision: z.ZodOptional<z.ZodString>;
|
|
18
|
+
headRevision: z.ZodString;
|
|
19
|
+
baseRevision: z.ZodString;
|
|
20
|
+
startedAt: z.ZodString;
|
|
21
|
+
}, z.core.$strict>>;
|
|
22
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
23
|
+
open: "open";
|
|
24
|
+
closed: "closed";
|
|
25
|
+
merged: "merged";
|
|
26
|
+
}>>;
|
|
27
|
+
mergeability: z.ZodOptional<z.ZodEnum<{
|
|
28
|
+
unknown: "unknown";
|
|
29
|
+
clean: "clean";
|
|
30
|
+
conflicting: "conflicting";
|
|
31
|
+
}>>;
|
|
16
32
|
checks: z.ZodOptional<z.ZodEnum<{
|
|
17
33
|
unknown: "unknown";
|
|
18
34
|
pending: "pending";
|
|
@@ -31,6 +47,7 @@ declare const configSchema: z.ZodObject<{
|
|
|
31
47
|
eligible: z.ZodOptional<z.ZodBoolean>;
|
|
32
48
|
}, z.core.$strict>>>;
|
|
33
49
|
deliveryEffects: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
50
|
+
eventsFile: z.ZodOptional<z.ZodString>;
|
|
34
51
|
effectsFile: z.ZodOptional<z.ZodString>;
|
|
35
52
|
connectivityError: z.ZodOptional<z.ZodString>;
|
|
36
53
|
createError: z.ZodOptional<z.ZodString>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
import { PullRequestCheckState, ReviewActorKind } from '../../activities/index.js';
|
|
3
|
+
import { pullRequestCheckEvidenceSchema, PullRequestCheckState, PullRequestMergeability, PullRequestState, ReviewActorKind, } from '../../activities/index.js';
|
|
3
4
|
import { BuiltInResourceCapability, BuiltInResourceKind } from '../../resources/index.js';
|
|
4
5
|
import { matchesArtifactSource } from '../application/artifact-source.js';
|
|
5
6
|
import { ArtifactVerificationResult } from '../contracts/artifact-vocabulary.js';
|
|
@@ -19,6 +20,17 @@ const configSchema = z
|
|
|
19
20
|
branch: z.string().min(1).optional(),
|
|
20
21
|
baseBranch: z.string().min(1).optional(),
|
|
21
22
|
baseRevision: z.string().min(1).optional(),
|
|
23
|
+
checkEvidence: pullRequestCheckEvidenceSchema.optional(),
|
|
24
|
+
state: z
|
|
25
|
+
.enum([PullRequestState.Open, PullRequestState.Closed, PullRequestState.Merged])
|
|
26
|
+
.optional(),
|
|
27
|
+
mergeability: z
|
|
28
|
+
.enum([
|
|
29
|
+
PullRequestMergeability.Unknown,
|
|
30
|
+
PullRequestMergeability.Mergeable,
|
|
31
|
+
PullRequestMergeability.Conflicting,
|
|
32
|
+
])
|
|
33
|
+
.optional(),
|
|
22
34
|
checks: z
|
|
23
35
|
.enum([
|
|
24
36
|
PullRequestCheckState.Unknown,
|
|
@@ -38,6 +50,7 @@ const configSchema = z
|
|
|
38
50
|
.strict())
|
|
39
51
|
.default([]),
|
|
40
52
|
deliveryEffects: z.record(z.string(), z.string()).default({}),
|
|
53
|
+
eventsFile: z.string().min(1).optional(),
|
|
41
54
|
effectsFile: z.string().min(1).optional(),
|
|
42
55
|
// Deterministic test hook: when set, checkConnectivity rejects with this
|
|
43
56
|
// message instead of resolving, so doctor's failure path is exercisable
|
|
@@ -73,7 +86,10 @@ export const fakeProviderDefinition = {
|
|
|
73
86
|
verifyArtifact: async (kind, externalKey, context) => {
|
|
74
87
|
if (kind !== BuiltInResourceKind.PullRequest)
|
|
75
88
|
return ArtifactVerificationResult.NotFound;
|
|
76
|
-
const
|
|
89
|
+
const events = config.eventsFile === undefined
|
|
90
|
+
? config.events
|
|
91
|
+
: configSchema.shape.events.parse(JSON.parse(await readFile(config.eventsFile, 'utf8')));
|
|
92
|
+
const evidence = events.find((event) => event.key === externalKey.key);
|
|
77
93
|
if (evidence === undefined || (evidence.kind ?? 'issue') !== 'pull-request')
|
|
78
94
|
return ArtifactVerificationResult.NotFound;
|
|
79
95
|
if (!matchesArtifactSource(externalKey, {
|
|
@@ -3,9 +3,11 @@ export function observePullRequest(resourceId, workItemId, payload) {
|
|
|
3
3
|
resourceId,
|
|
4
4
|
workItemId,
|
|
5
5
|
state: payload.state,
|
|
6
|
+
...(payload.mergeRevision === undefined ? {} : { mergeRevision: payload.mergeRevision }),
|
|
6
7
|
...(payload.mergeability === undefined ? {} : { mergeability: payload.mergeability }),
|
|
7
8
|
headRevision: payload.headRevision ?? payload.revision,
|
|
8
9
|
baseRevision: payload.baseRevision ?? 'unknown',
|
|
10
|
+
...(payload.checkEvidence === undefined ? {} : { checkEvidence: payload.checkEvidence }),
|
|
9
11
|
checks: payload.checks ?? 'unknown',
|
|
10
12
|
...(payload.changedFiles === undefined ? {} : { changedFiles: payload.changedFiles }),
|
|
11
13
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type EventDataUnion, type EventEnvelope, type EventUnion } from '@atolis-hq/eventing';
|
|
2
|
-
import { ProviderPermission, PullRequestCheckState, PullRequestMergeability, PullRequestState, ReviewActorKind, ReviewerAuthorizationSource, type ReviewerAuthorizationEvidence } from '../../../activities/index.js';
|
|
2
|
+
import { ProviderPermission, PullRequestCheckState, PullRequestMergeability, PullRequestState, ReviewActorKind, ReviewerAuthorizationSource, type PullRequestCheckEvidence, type ReviewerAuthorizationEvidence } from '../../../activities/index.js';
|
|
3
3
|
import { type ResourceId } from '../../../resources/index.js';
|
|
4
4
|
import { type WorkItemId } from '../../../work/index.js';
|
|
5
5
|
import { ExternalWorkOutcome } from '../../contracts/outcome-vocabulary.js';
|
|
@@ -26,7 +26,9 @@ export interface ExternalWorkObservedPayload {
|
|
|
26
26
|
readonly outcome?: ExternalWorkOutcome | undefined;
|
|
27
27
|
readonly revision: string;
|
|
28
28
|
readonly headRevision?: string | undefined;
|
|
29
|
+
readonly checkEvidence?: PullRequestCheckEvidence | undefined;
|
|
29
30
|
readonly baseRevision?: string | undefined;
|
|
31
|
+
readonly mergeRevision?: string | undefined;
|
|
30
32
|
readonly checks?: typeof PullRequestCheckState.Unknown | typeof PullRequestCheckState.Pending | typeof PullRequestCheckState.Passing | typeof PullRequestCheckState.Failing | undefined;
|
|
31
33
|
readonly actor: {
|
|
32
34
|
readonly id: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { eventDataSchema, eventEnvelopeSchema, } from '@atolis-hq/eventing';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { ProviderPermission, PullRequestCheckState, PullRequestMergeability, PullRequestState, ReviewActorKind, ReviewerAuthorizationSource, } from '../../../activities/index.js';
|
|
3
|
+
import { ProviderPermission, pullRequestCheckEvidenceSchema, PullRequestCheckState, PullRequestMergeability, PullRequestState, ReviewActorKind, ReviewerAuthorizationSource, } from '../../../activities/index.js';
|
|
4
4
|
import { brandedStringSchema } from '../../../kernel/index.js';
|
|
5
5
|
import { resourceId } from '../../../resources/index.js';
|
|
6
6
|
import { workItemId } from '../../../work/index.js';
|
|
@@ -72,6 +72,8 @@ const githubEventSchemas = {
|
|
|
72
72
|
.optional(),
|
|
73
73
|
headRevision: z.string().optional(),
|
|
74
74
|
baseRevision: z.string().optional(),
|
|
75
|
+
checkEvidence: pullRequestCheckEvidenceSchema.optional(),
|
|
76
|
+
mergeRevision: z.string().min(1).optional(),
|
|
75
77
|
checks: z
|
|
76
78
|
.enum([
|
|
77
79
|
PullRequestCheckState.Unknown,
|
|
@@ -43,8 +43,13 @@ export interface GitHubPullRequestPayload extends GitHubIssuePayload {
|
|
|
43
43
|
readonly sha?: string;
|
|
44
44
|
};
|
|
45
45
|
readonly merged_at?: string | null;
|
|
46
|
+
readonly merge_commit_sha?: string | null;
|
|
46
47
|
}
|
|
47
48
|
export interface GitHubCheckRunPayload {
|
|
49
|
+
readonly check_suite?: {
|
|
50
|
+
readonly id: number;
|
|
51
|
+
} | null;
|
|
52
|
+
readonly head_sha?: string;
|
|
48
53
|
readonly id?: number;
|
|
49
54
|
readonly name?: string;
|
|
50
55
|
readonly status?: string;
|
|
@@ -73,3 +78,21 @@ export interface GitHubReviewPayload {
|
|
|
73
78
|
readonly type?: string;
|
|
74
79
|
} | null;
|
|
75
80
|
}
|
|
81
|
+
export interface GitHubWorkflowRunPayload {
|
|
82
|
+
readonly run_attempt?: number;
|
|
83
|
+
readonly id: number;
|
|
84
|
+
readonly check_suite_id?: number;
|
|
85
|
+
readonly head_sha: string;
|
|
86
|
+
readonly event: string;
|
|
87
|
+
readonly status: string | null;
|
|
88
|
+
readonly conclusion: string | null;
|
|
89
|
+
readonly pull_requests?: readonly {
|
|
90
|
+
readonly number: number;
|
|
91
|
+
readonly head: {
|
|
92
|
+
readonly sha: string;
|
|
93
|
+
};
|
|
94
|
+
readonly base: {
|
|
95
|
+
readonly sha: string;
|
|
96
|
+
};
|
|
97
|
+
}[] | null;
|
|
98
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/rest';
|
|
2
|
+
export interface TestedCommit {
|
|
3
|
+
readonly sha: string;
|
|
4
|
+
readonly parents: readonly {
|
|
5
|
+
readonly sha: string;
|
|
6
|
+
}[];
|
|
7
|
+
}
|
|
8
|
+
/** Completed job logs and Git objects are immutable; failed reads are never cached. */
|
|
9
|
+
export declare function createCheckExecutionReader(octokit: Octokit): (owner: string, repo: string, runId: number, attempt: number, checkId: number) => Promise<TestedCommit | undefined>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { GitHubCheckRunStatus } from '../contracts/vocabulary.js';
|
|
2
|
+
import { checkoutRevision } from './checkout-revision.js';
|
|
3
|
+
/** Completed job logs and Git objects are immutable; failed reads are never cached. */
|
|
4
|
+
export function createCheckExecutionReader(octokit) {
|
|
5
|
+
const jobs = new Map();
|
|
6
|
+
const commits = new Map();
|
|
7
|
+
const checkouts = new Map();
|
|
8
|
+
async function loadJobs(owner, repo, runId) {
|
|
9
|
+
const result = await octokit.rest.actions.listJobsForWorkflowRun({
|
|
10
|
+
owner,
|
|
11
|
+
repo,
|
|
12
|
+
run_id: runId,
|
|
13
|
+
per_page: 100,
|
|
14
|
+
});
|
|
15
|
+
return result.data.total_count >= 100 ? [] : result.data.jobs;
|
|
16
|
+
}
|
|
17
|
+
function completeJobs(entries) {
|
|
18
|
+
return (entries.length > 0 && entries.every((job) => job.status === GitHubCheckRunStatus.Completed));
|
|
19
|
+
}
|
|
20
|
+
return async (owner, repo, runId, attempt, checkId) => {
|
|
21
|
+
const prefix = `${owner}/${repo}`;
|
|
22
|
+
const key = `${prefix}:${runId}:${attempt}`;
|
|
23
|
+
let entries = jobs.get(key);
|
|
24
|
+
if (entries === undefined) {
|
|
25
|
+
entries = await loadJobs(owner, repo, runId);
|
|
26
|
+
if (completeJobs(entries))
|
|
27
|
+
remember(jobs, key, entries);
|
|
28
|
+
}
|
|
29
|
+
const matches = entries.filter((job) => job.check_run_url?.endsWith(`/check-runs/${checkId}`));
|
|
30
|
+
if (matches.length !== 1)
|
|
31
|
+
return undefined;
|
|
32
|
+
const job = matches[0];
|
|
33
|
+
if (job.run_id !== runId ||
|
|
34
|
+
job.status !== GitHubCheckRunStatus.Completed ||
|
|
35
|
+
job.conclusion !== 'success')
|
|
36
|
+
return undefined;
|
|
37
|
+
const jobKey = `${prefix}:${job.id}`;
|
|
38
|
+
let revision = checkouts.get(jobKey);
|
|
39
|
+
if (revision === undefined) {
|
|
40
|
+
const response = await octokit.rest.actions.downloadJobLogsForWorkflowRun({
|
|
41
|
+
owner,
|
|
42
|
+
repo,
|
|
43
|
+
job_id: job.id,
|
|
44
|
+
});
|
|
45
|
+
if (typeof response.data !== 'string')
|
|
46
|
+
return undefined;
|
|
47
|
+
revision = checkoutRevision(response.data);
|
|
48
|
+
if (revision === undefined)
|
|
49
|
+
return undefined;
|
|
50
|
+
remember(checkouts, jobKey, revision);
|
|
51
|
+
}
|
|
52
|
+
const commitKey = `${prefix}:${revision}`;
|
|
53
|
+
let commit = commits.get(commitKey);
|
|
54
|
+
if (commit === undefined) {
|
|
55
|
+
const result = await octokit.rest.git.getCommit({ owner, repo, commit_sha: revision });
|
|
56
|
+
if (result.data.sha !== revision)
|
|
57
|
+
return undefined;
|
|
58
|
+
commit = { sha: result.data.sha, parents: result.data.parents.map(({ sha }) => ({ sha })) };
|
|
59
|
+
remember(commits, commitKey, commit);
|
|
60
|
+
}
|
|
61
|
+
return commit;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function remember(cache, key, value) {
|
|
65
|
+
if (cache.size >= 1000)
|
|
66
|
+
cache.delete(cache.keys().next().value);
|
|
67
|
+
cache.set(key, value);
|
|
68
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Read actions/checkout's full Git log result, never the mutable PR merge ref. */
|
|
2
|
+
export function checkoutRevision(log) {
|
|
3
|
+
let checkout = false;
|
|
4
|
+
let expectingSha = false;
|
|
5
|
+
const revisions = [];
|
|
6
|
+
for (const line of log.split('\n')) {
|
|
7
|
+
const message = line.replace(/^\S+\s/, '').trim();
|
|
8
|
+
if (message.startsWith('##[group]Run ')) {
|
|
9
|
+
checkout = message.startsWith('##[group]Run actions/checkout@');
|
|
10
|
+
expectingSha = false;
|
|
11
|
+
}
|
|
12
|
+
if (!checkout)
|
|
13
|
+
continue;
|
|
14
|
+
if (expectingSha) {
|
|
15
|
+
if (/^[a-f0-9]{40}$/.test(message))
|
|
16
|
+
revisions.push(message);
|
|
17
|
+
expectingSha = false;
|
|
18
|
+
}
|
|
19
|
+
if (/^\[command\].*\/git log -1 --format=%H$/.test(message))
|
|
20
|
+
expectingSha = true;
|
|
21
|
+
}
|
|
22
|
+
return revisions.length === 1 ? revisions[0] : undefined;
|
|
23
|
+
}
|