Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as TestClock from "effect/testing/TestClock";
import * as Redacted from "effect/Redacted";

import { HttpClient, HttpClientResponse } from "effect/http";
import { SourceControlProviderKind } from "@t3tools/contracts";

import * as GitHubRest from "./GitHubRest.ts";
import * as GitHubRequestPolicy from "./GitHubRequestPolicy.ts";
Expand Down Expand Up @@ -3037,6 +3038,42 @@ layer("GitHubPullRequestApi.layer", (it) => {
}),
);

it.effect.each([
new GitHubRequestPolicy.GitHubApiRateLimitError({
host: "github.com",
operation: "listWorkflowRunsRequiringApproval",
}),
new SourceControlRateLimit.SourceControlRateLimitPausedError({
provider: SourceControlProviderKind.make("github"),
host: "github.com",
retryAt: Date.parse("2099-08-13T14:00:00Z"),
}),
])("keeps $_tag when the workflow run read is rate-limited", (refusal) =>
Effect.gen(function* () {
mockedExecute.mockImplementation((call) =>
call.kind === "graphql"
? Effect.succeed(output(encodeJson(heads([7]))))
: Effect.fail(refusal),
);
const cli = yield* GitHubPullRequestApi.GitHubPullRequestApi;

const error = yield* Effect.flip(
cli.listWorkflowRunsRequiringApproval({
cwd: "/w",
repository: "acme/web",
host: "github.com",
number: 7,
headSha: "abc123",
headBranch: "feat/page",
headRepositoryOwner: "octocat",
isCrossRepository: true,
}),
);

assert.strictEqual(error._tag, refusal._tag);
}),
);

it.effect("sends a comment body as a variable, never inside the document", () =>
Effect.gen(function* () {
route([NODE_ID_QUERY, nodeIdAnswer("PR_7")]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,15 @@ export const make = Effect.gen(function* () {
operation: "listWorkflowRunsRequiringApproval",
path: `repos/${owner}/${name}/actions/runs?head_sha=${encodeURIComponent(input.headSha)}&branch=${encodeURIComponent(input.headBranch)}&event=pull_request&status=action_required&per_page=100&page=${page}`,
decode: decodeWorkflowRunsJson,
}).pipe(Effect.mapError((error) => workflowApprovalReadError(input.cwd, error)));
}).pipe(
// A rate-limited read is no answer; callers wait instead of reporting approval unknown.
Effect.mapError((error) =>
error._tag === "GitHubApiRateLimitError" ||
error._tag === "SourceControlRateLimitPausedError"
? error
: workflowApprovalReadError(input.cwd, error),
),
);
runs.push(...read.runs);
if (read.rawCount < 100) break;
}
Expand Down
Loading