MCPcopy Create free account
hub / github.com/cli/cli / Actor

Class Actor

evals/src/suites/events/actor.ts:11–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9export type Phase = ActorStep["kind"];
10
11export class Actor {
12 readonly actions: Action[] = [];
13 private step: ActorStep;
14 private readonly remaining: ActorStep[];
15 private phaseStartedAt: number;
16 private verifiedHead?: string;
17 private phaseHead: string;
18 private fallbackStartedAt: number;
19 done = false;
20
21 constructor(
22 private readonly github: EventsGitHub,
23 private readonly reviewer: EventsGitHub,
24 readonly fixture: Fixture,
25 private readonly fallbackMs: number,
26 now: number,
27 ) {
28 const [first, ...remaining] = scenarios[fixture.scenario].steps;
29 this.step = first;
30 this.remaining = remaining;
31 this.phaseStartedAt = now;
32 this.fallbackStartedAt = now;
33 this.phaseHead = fixture.initialHead;
34 }
35
36 get phase(): Phase {
37 return this.step.kind;
38 }
39
40 async tick(now: number, wait?: Call, source: "timer" | "post-tool" = "timer"): Promise<void> {
41 if (this.done) return;
42 const { fixture } = this;
43 if (!fixture.pr) {
44 const pulls = await this.github.api<Array<{ number: number }>>(
45 "GET", `/repos/${fixture.repo}/pulls?state=all&base=main&per_page=100`,
46 );
47 if (!pulls.length) return;
48 if (pulls.length !== 1 || !pulls[0]) throw new Error("Expected exactly one fixture PR");
49 fixture.pr = await this.github.pull(fixture.repo, pulls[0].number);
50 }
51 const pr = await this.github.pull(fixture.repo, fixture.pr.number);
52 fixture.pr = pr;
53 if (pr.state !== "open") {
54 this.done = true;
55 return;
56 }
57 if (this.step.kind === "merge" && pr.mergeable !== true) {
58 if (pr.mergeable === false) throw new Error("The fixture PR has an unexpected merge conflict");
59 return;
60 }
61 const expectedFix = this.step.kind === "approval" ? this.step.greeting
62 : this.step.kind === "review" ? this.step.afterFix : undefined;
63 if (expectedFix !== undefined && this.verifiedHead !== pr.head.sha) {
64 if (pr.head.sha === this.phaseHead) return;
65 if (await this.github.greeting(fixture.repo, pr.head.sha) !== expectedFix) return;
66 this.actions.push({ kind: "fix", at: now, pr: pr.number, head: pr.head.sha, trigger: "verification" });
67 this.verifiedHead = pr.head.sha;
68 this.fallbackStartedAt = now;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected