fix(server): GitHub App tokens can merge and use other write actions (#19103)

Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
authored and GitHub committed 2026-10-14 20:34:13 -03:00
1 parent 40a7908df5
commit 742c229957
4 files changed
+37 -8

No files matched your search

@@ -1017,7 +1017,12 @@ describe("repository access decoding", () => {
// The one place an unknown answer is not granted: a Merge button a reader cannot use wastes
// the press, where a missing one still leaves the pull request open on its host.
expect(expectSuccess(decodeViewerPermissionsJson(repositoryJson())).canWrite).toBe(false);
expect(expectSuccess(decodeViewerPermissionsJson(repositoryJson(null))).canWrite).toBe(false);
});
it("grants write and triage to a GitHub App, which GitHub answers with a null permission", () => {
const access = expectSuccess(decodeViewerPermissionsJson(repositoryJson(null)));
expect(access.canWrite).toBe(true);
expect(access.canTriage).toBe(true);
});
});
@@ -708,9 +708,9 @@ const RawRepositoryAccessSchema = Schema.Struct({
squashMergeAllowed: Schema.Boolean,
rebaseMergeAllowed: Schema.Boolean,
/**
* ADMIN, MAINTAIN, WRITE, TRIAGE, READ or NONE. Optional rather than required, unlike the
* three above: an install that does not report it leaves the viewer's standing unknown, which
* is answered by granting rather than by failing the whole detail read.
* ADMIN, MAINTAIN, WRITE, TRIAGE, READ or NONE, or null for a GitHub App. Optional rather than
* required, unlike the three above: an install that does not report it still decodes rather
* than failing the whole detail read, and `toCanWrite` decides what that standing allows.
*/
viewerPermission: Schema.optional(Schema.NullOr(Schema.String)),
});
@@ -2919,8 +2919,13 @@ export interface GitHubRepositoryAccess {
* need, and offering those to a reader who cannot use them wastes the press and reads as the app
* being wrong. Everything softer — commenting, reviewing, resolving — keeps the granting default,
* because being unable to say something is the worse failure there.
*
* A null permission is not that. GitHub answers null only to a GitHub App installation, and no
* API says what an installation may do, so null is granted and GitHub refuses whatever the app
* was not given. A person always gets a role, READ at the least.
*/
function toCanWrite(viewerPermission: string | null | undefined): boolean {
export function toCanWrite(viewerPermission: string | null | undefined): boolean {
if (viewerPermission === null) return true;
switch (viewerPermission?.trim().toUpperCase()) {
case "ADMIN":
case "MAINTAIN":
@@ -325,6 +325,26 @@ it.effect("allows a fork that explicitly permits maintainer updates", () =>
}),
);
it.effect("rebases for a GitHub App, which GitHub gives no permission to read", () =>
Effect.gen(function* () {
gitCalls = [];
const api = fake([
stack,
{
data: {
repository: {
pr2: { headRepository: { viewerPermission: null }, maintainerCanModify: false },
pr3: { headRepository: { viewerPermission: null }, maintainerCanModify: false },
},
},
},
...rebaseResponses,
]);
yield* runGitHubStackAction(api.execute, { ...input, action: "update-branch" });
expect(gitCalls.filter((args) => args[0] === "push")).toHaveLength(2);
}),
);
it.effect("bounds polling and reports a still-running merge without claiming success", () =>
Effect.gen(function* () {
const api = fake([
@@ -10,7 +10,7 @@ import * as Schema from "effect/Schema";
import * as GitHubApi from "./GitHubApi.ts";
import { aliasedGraphQlDocument } from "./githubGraphQl.ts";
import { decodePullRequestStacksJson } from "./gitHubPullRequestJson.ts";
import { decodePullRequestStacksJson, toCanWrite } from "./gitHubPullRequestJson.ts";
import { cascadeRebaseStack } from "./githubStackRebase.ts";
const stackErrorIdentity = {
@@ -216,8 +216,7 @@ export const runGitHubStackAction = Effect.fn("runGitHubStackAction")(function*
const pr = access.data.repository?.[`pr${layer.number}`];
return (
!pr?.headRepository ||
(!pr.maintainerCanModify &&
!["ADMIN", "MAINTAIN", "WRITE"].includes(pr.headRepository.viewerPermission ?? ""))
(!pr.maintainerCanModify && !toCanWrite(pr.headRepository.viewerPermission))
);
})
)