Skip to content

Commit 5a10242

Browse files
committed
fix(server): skip the notifications gate when the app sign-in answers the pull request reads
1 parent c75cec6 commit 5a10242

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎packages/source-control-github/src/server/GitHubRest.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, it } from "@effect/vitest";
22
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
33
import * as Effect from "effect/Effect";
44
import * as Layer from "effect/Layer";
5+
import * as Option from "effect/Option";
56
import * as Redacted from "effect/Redacted";
67
import * as TestClock from "effect/testing/TestClock";
78
import * as Tracer from "effect/Tracer";
@@ -323,11 +324,12 @@ describe("listPullRequestNotifications", () => {
323324
]),
324325
json({ message: "Resource not accessible by personal access token" }, { status: 403 }),
325326
];
327+
let appSignedIn = true;
326328
const { layer, requests } = harness(
327329
() => answers.shift()!,
328330
Layer.mock(GitHubAppSignIn.GitHubAppSignIn)({
329331
enabled: true,
330-
token: () => Effect.succeedSome("app"),
332+
token: () => Effect.sync(() => (appSignedIn ? Option.some("app") : Option.none())),
331333
invalidate: () => Effect.void,
332334
}),
333335
);
@@ -336,6 +338,9 @@ describe("listPullRequestNotifications", () => {
336338
const list = makeListPullRequestNotifications(yield* GitHubRest.GitHubRest);
337339
const since = Date.parse("2026-10-05T11:55:00.400Z");
338340
const input = { host: "github.com", repository: "acme/web", since };
341+
expect(yield* list(input)).toBeNull();
342+
expect(requests).toEqual([]);
343+
appSignedIn = false;
339344
expect(yield* list(input)).toEqual({ threads: [], truncated: false });
340345
expect(yield* list(input)).toEqual({
341346
threads: [{ number: 7, updatedAt: Date.parse("2026-10-05T11:58:03Z") }],

‎packages/source-control-github/src/server/gitHubNotifications.ts‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,28 @@ export const makeListPullRequestNotifications = (rest: GitHubRest.GitHubRest["Se
3232
readonly since: number;
3333
}) {
3434
const since = DateTime.makeUnsafe(Math.floor(input.since / 1000) * 1000);
35-
const response = yield* rest
36-
.rest({
35+
const response = yield* Effect.gen(function* () {
36+
const [read, personal] = yield* Effect.all([
37+
rest.credential(input.host),
38+
rest.credential(input.host, { personal: true }),
39+
]);
40+
if (read.fingerprint !== personal.fingerprint) return null;
41+
return yield* rest.rest({
3742
host: input.host,
3843
operation: OPERATION,
3944
path: `repos/${input.repository}/notifications?all=true&participating=true&since=${DateTime.formatIso(since).replace(".000Z", "Z")}&per_page=${PAGE_SIZE}`,
4045
ifModifiedSince: DateTime.toDateUtc(since).toUTCString(),
4146
personal: true,
42-
})
43-
.pipe(
44-
Effect.catchTags({
45-
GitHubApiNotFoundError: () => Effect.succeed(null),
46-
GitHubNotSignedInError: () => Effect.succeed(null),
47-
GitHubCliMissingError: () => Effect.succeed(null),
48-
GitHubApiResponseError: (error) =>
49-
error.status === 403 ? Effect.succeed(null) : Effect.fail(error),
50-
}),
51-
);
47+
});
48+
}).pipe(
49+
Effect.catchTags({
50+
GitHubApiNotFoundError: () => Effect.succeed(null),
51+
GitHubNotSignedInError: () => Effect.succeed(null),
52+
GitHubCliMissingError: () => Effect.succeed(null),
53+
GitHubApiResponseError: (error) =>
54+
error.status === 403 ? Effect.succeed(null) : Effect.fail(error),
55+
}),
56+
);
5257
if (response === null) return null;
5358
if (response.status === 304) {
5459
return { threads: [], truncated: false } satisfies ProviderChangeRequestNotifications;

0 commit comments

Comments
 (0)