@devries-cameron20 / t3code-1 / commits / 508f869cb3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

feat(gitlab): merge requests from forks can toggle maintainer edits (#30518)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>

Antony committed Nov 6, 2026 at 02:45 UTC 508f869cb3d3ac07a6d81963da5054e1af0d8f51
5 files changed +312 -64
packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+167 -24
@@ -1643,33 +1643,39 @@ layer("GitLabPullRequestCli.layer", (it) => {
1643 expected: true,
1644 },
1645 { answer: JSON.stringify({ errors: [{ message: "Field unknown" }] }), expected: false },
1646 - ])("reads merge and label permissions without reading the trigger jobs", ({ answer, expected }) =>
1647 - Effect.gen(function* () {
1648 - mockedExecute.mockImplementation(({ args }) =>
1649 - Effect.succeed(
1650 - output(
1651 - args[1] === "graphql"
1652 - ? answer
1653 - : mergeRequestJson({
1654 - head_pipeline: { id: 31, project_id: 12, status: "success" },
1655 - user: { can_merge: false },
1656 - }),
1646 + ])(
1647 + "reads merge and label permissions without reading the trigger jobs or fork settings",
1648 + ({ answer, expected }) =>
1649 + Effect.gen(function* () {
1650 + mockedExecute.mockImplementation(({ args }) =>
1651 + Effect.succeed(
1652 + output(
1653 + args[1] === "graphql"
1654 + ? answer
1655 + : mergeRequestJson({
1656 + head_pipeline: { id: 31, project_id: 12, status: "success" },
1657 + user: { can_merge: false },
1658 + source_project_id: 12,
1659 + target_project_id: 12,
1660 + allow_collaboration: null,
1661 + }),
1662 + ),
1663 ),
1658 - ),
1659 - );
1660 - const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1664 + );
1665 + const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1666
1662 - const detail = yield* cli.getMergeRequestDetail({
1663 - cwd: "/w",
1664 - repository: "acme/web",
1665 - number: 7,
1666 - downstreamChecks: false,
1667 - });
1667 + const detail = yield* cli.getMergeRequestDetail({
1668 + cwd: "/w",
1669 + repository: "acme/web",
1670 + number: 7,
1671 + downstreamChecks: false,
1672 + });
1673
1669 - expect(detail.viewerCanMerge).toBe(false);
1670 - expect(detail.viewerCanEditLabels).toBe(expected);
1671 - expect(mockedExecute).toHaveBeenCalledTimes(2);
1672 - }),
1674 + expect(detail.viewerCanMerge).toBe(false);
1675 + expect(detail.maintainerCanModify).toBeUndefined();
1676 + expect(detail.viewerCanEditLabels).toBe(expected);
1677 + expect(mockedExecute).toHaveBeenCalledTimes(2);
1678 + }),
1679 );
1680
1681 it.effect(
@@ -1888,6 +1894,143 @@ layer("GitLabPullRequestCli.layer", (it) => {
1894 }),
1895 );
1896
1897 + it.effect.each([
1898 + { viewer: "the author who can push to the fork", username: "bilal", allowed: true },
1899 + {
1900 + viewer: "the author who turned them off",
1901 + username: "bilal",
1902 + allowCollaboration: false,
1903 + allowed: true,
1904 + },
1905 + { viewer: "a target maintainer the fork lets push", username: "octocat", allowed: false },
1906 + {
1907 + viewer: "the author without push access",
1908 + username: "bilal",
1909 + pushToSourceBranch: false,
1910 + allowed: false,
1911 + },
1912 + {
1913 + viewer: "a viewer on a host that rejects the permission read",
1914 + username: "bilal",
1915 + rejected: true,
1916 + allowed: false,
1917 + },
1918 + {
1919 + viewer: "the author of a protected source branch",
1920 + username: "bilal",
1921 + sourceBranchProtected: true,
1922 + allowed: false,
1923 + },
1924 + {
1925 + viewer: "the author of a private fork",
1926 + username: "bilal",
1927 + sourceVisibility: "private",
1928 + allowed: false,
1929 + },
1930 + {
1931 + viewer: "the author targeting a private project",
1932 + username: "bilal",
1933 + targetVisibility: "private",
1934 + allowed: false,
1935 + },
1936 + ])("reads a fork's maintainer edits and lets $viewer change them", (row) =>
1937 + Effect.gen(function* () {
1938 + const allowCollaboration = row.allowCollaboration ?? true;
1939 + mockedExecute.mockImplementation(({ args }) =>
1940 + Effect.succeed(
1941 + output(
1942 + args[1] === "graphql"
1943 + ? JSON.stringify(
1944 + row.rejected === true
1945 + ? { errors: [{ message: "Field 'pushToSourceBranch' doesn't exist" }] }
1946 + : {
1947 + data: {
1948 + currentUser: { username: row.username },
1949 + project: {
1950 + visibility: row.targetVisibility ?? "public",
1951 + mergeRequest: {
1952 + author: { username: "bilal" },
1953 + userPermissions: {
1954 + pushToSourceBranch: row.pushToSourceBranch ?? true,
1955 + },
1956 + sourceBranchProtected: row.sourceBranchProtected ?? false,
1957 + sourceProject: { visibility: row.sourceVisibility ?? "public" },
1958 + },
1959 + },
1960 + },
1961 + },
1962 + )
1963 + : mergeRequestJson({
1964 + author,
1965 + source_project_id: 40,
1966 + target_project_id: 12,
1967 + allow_collaboration: allowCollaboration,
1968 + }),
1969 + ),
1970 + ),
1971 + );
1972 + const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1973 +
1974 + const detail = yield* cli.getMergeRequestDetail({
1975 + cwd: "/w",
1976 + repository: "acme/web",
1977 + number: 7,
1978 + downstreamChecks: false,
1979 + });
1980 +
1981 + expect(detail.maintainerCanModify).toBe(allowCollaboration);
1982 + expect(detail.viewerCanEditMaintainerEdits).toBe(row.allowed);
1983 + }),
1984 + );
1985 +
1986 + it.effect("skips a fork's maintainer edits permission read when the caller opts out", () =>
1987 + Effect.gen(function* () {
1988 + mockedExecute
1989 + .mockReturnValueOnce(
1990 + Effect.succeed(
1991 + output(
1992 + mergeRequestJson({
1993 + source_project_id: 40,
1994 + target_project_id: 12,
1995 + allow_collaboration: true,
1996 + }),
1997 + ),
1998 + ),
1999 + )
2000 + .mockReturnValueOnce(Effect.succeed(labelPermission));
2001 + const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
2002 +
2003 + const detail = yield* cli.getMergeRequestDetail({
2004 + cwd: "/w",
2005 + repository: "acme/web",
2006 + number: 7,
2007 + downstreamChecks: false,
2008 + maintainerEdits: false,
2009 + });
2010 +
2011 + expect(detail.maintainerCanModify).toBe(true);
2012 + expect(detail.viewerCanEditMaintainerEdits).toBeUndefined();
2013 + expect(mockedExecute).toHaveBeenCalledTimes(2);
2014 + }),
2015 + );
2016 +
2017 + it.effect("sends maintainer edits as allow_collaboration", () =>
2018 + Effect.gen(function* () {
2019 + mockedExecute.mockReturnValueOnce(Effect.succeed(output("{}")));
2020 + const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
2021 +
2022 + yield* cli.updateMergeRequest({
2023 + cwd: "/w",
2024 + repository: "acme/web",
2025 + number: 7,
2026 + allowCollaboration: false,
2027 + });
2028 +
2029 + expect(argsOfCall(0)).toContain("PUT");
2030 + expect(JSON.parse(callAt(0).stdin ?? "")).toEqual({ allow_collaboration: false });
2031 + }),
2032 + );
2033 +
2034 it.effect.each([
2035 ["th", "projects/acme%2Fweb/users?per_page=100"],
2036 ["tho", "projects/acme%2Fweb/users?per_page=100&search=tho"],
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+50 -35
@@ -42,6 +42,7 @@ import {
42 decodeCommitsJson,
43 decodeDiffRefsJson,
44 decodeDiscussionsJson,
45 + decodeMaintainerEditsPermissionJson,
46 decodeLabelNameJson,
47 decodeLabelPermissionJson,
48 decodeMergeMessagesJson,
@@ -67,6 +68,7 @@ import {
68 decodeTriggerJobChecksJson,
69 decodeViewerJson,
70 gitLabAwardName,
71 + MAINTAINER_EDITS_PERMISSION_GRAPHQL_QUERY,
72 LABEL_PERMISSION_GRAPHQL_QUERY,
73 MERGE_MESSAGES_GRAPHQL_QUERY,
74 MERGE_REQUEST_FILE_STATS_GRAPHQL_QUERY,
@@ -380,6 +382,8 @@ export class GitLabPullRequestCli extends Context.Service<
382 readonly number: number;
383 /** `false` skips the stage and trigger job reads, as write permission checks do. */
384 readonly downstreamChecks?: boolean;
385 + /** `false` skips a fork's maintainer edits permission read, for views that never show it. */
386 + readonly maintainerEdits?: boolean;
387 }) => Effect.Effect<GitLabMergeRequestDetail, GitLabPullRequestCliError>;
388
389 /** Approval and head pipeline state, read in one GraphQL request per 100 merge requests. */
@@ -555,6 +559,7 @@ export class GitLabPullRequestCli extends Context.Service<
559 readonly number: number;
560 readonly title?: string | undefined;
561 readonly description?: string | undefined;
562 + readonly allowCollaboration?: boolean | undefined;
563 }) => Effect.Effect<void, GitLabPullRequestCliError>;
564
565 readonly commentOnMergeRequest: (input: {
@@ -1580,6 +1585,19 @@ export const make = Effect.gen(function* () {
1585 }),
1586 );
1587
1588 + // A read GitLab could not answer (an older host, a field it rejects) is not worth failing the
1589 + // surrounding operation for. An unusable CLI or account still reaches the caller.
1590 + const isOptionalReadFailure = (cause: GitLabPullRequestCliError) =>
1591 + cause._tag !== "GitLabCliUnavailableError" &&
1592 + cause._tag !== "GitLabCliAuthenticationError" &&
1593 + cause._tag !== "GitLabCliRateLimitError";
1594 +
1595 + const orWhenUnanswered = <A>(
1596 + read: Effect.Effect<A, GitLabPullRequestCliError>,
1597 + fallback: A,
1598 + ): Effect.Effect<A, GitLabPullRequestCliError> =>
1599 + read.pipe(Effect.catchIf(isOptionalReadFailure, () => Effect.succeed(fallback)));
1600 +
1601 const graphqlMutation = (input: {
1602 readonly cwd: string;
1603 readonly host?: string | undefined;
@@ -1675,16 +1693,7 @@ export const make = Effect.gen(function* () {
1693 query: LABEL_PERMISSION_GRAPHQL_QUERY,
1694 variables: { fullPath: input.repository, iid: String(input.number) },
1695 decode: decodeLabelPermissionJson,
1678 - }).pipe(
1679 - // The answer gates one optional control; an unusable CLI or account still surfaces.
1680 - Effect.catchIf(
1681 - (cause) =>
1682 - cause._tag !== "GitLabCliUnavailableError" &&
1683 - cause._tag !== "GitLabCliAuthenticationError" &&
1684 - cause._tag !== "GitLabCliRateLimitError",
1685 - () => Effect.succeed(false),
1686 - ),
1687 - );
1696 + }).pipe(Effect.catchIf(isOptionalReadFailure, () => Effect.succeed(false)));
1697
1698 const sourceBranch = (input: {
1699 readonly cwd: string;
@@ -1812,18 +1821,12 @@ export const make = Effect.gen(function* () {
1821 return stat === undefined ? [] : [{ repository: read.repository, number, ...stat }];
1822 }),
1823 ),
1815 - // One read GitLab could not answer costs its own rows their counts, not every other
1816 - // read's on the same page. An unusable CLI or account still reaches the caller.
1817 - Effect.catchIf(
1818 - (cause) =>
1819 - cause._tag !== "GitLabCliUnavailableError" &&
1820 - cause._tag !== "GitLabCliAuthenticationError" &&
1821 - cause._tag !== "GitLabCliRateLimitError",
1822 - (cause) =>
1823 - Effect.logWarning("GitLab merge request line count read failed", {
1824 - repository: read.repository,
1825 - reason: cause._tag,
1826 - }).pipe(Effect.as([])),
1824 + // One failed read costs its own rows their counts, not every other read's on the page.
1825 + Effect.catchIf(isOptionalReadFailure, (cause) =>
1826 + Effect.logWarning("GitLab merge request line count read failed", {
1827 + repository: read.repository,
1828 + reason: cause._tag,
1829 + }).pipe(Effect.as([])),
1830 ),
1831 ),
1832 { concurrency: STAT_REQUEST_CONCURRENCY },
@@ -1998,24 +2001,33 @@ export const make = Effect.gen(function* () {
2001 [mergeRequestDetail(input), labelPermission(input)],
2002 { concurrency: 2 },
2003 );
2001 - // Only a closed or merged merge request offers its branch for deletion, so an open one,
2002 - // the page most often read, skips the extra query.
2004 + // Only a closed or merged merge request offers its branch for deletion, and only an open
2005 + // fork's has maintainer edits to change, so each extra read is skipped elsewhere.
2006 const detail =
2007 read.state === "open"
2005 - ? { ...read, viewerCanEditLabels }
2008 + ? input.maintainerEdits === false || read.maintainerCanModify === undefined
2009 + ? { ...read, viewerCanEditLabels }
2010 + : {
2011 + ...read,
2012 + viewerCanEditLabels,
2013 + viewerCanEditMaintainerEdits: yield* orWhenUnanswered(
2014 + graphqlRead({
2015 + cwd: input.cwd,
2016 + host: input.host,
2017 + operation: "getMaintainerEditsPermission",
2018 + query: MAINTAINER_EDITS_PERMISSION_GRAPHQL_QUERY,
2019 + variables: { fullPath: input.repository, iid: String(input.number) },
2020 + decode: decodeMaintainerEditsPermissionJson,
2021 + }),
2022 + false,
2023 + ),
2024 + }
2025 : {
2026 ...read,
2027 viewerCanEditLabels,
2009 - viewerCanDeleteBranch: yield* sourceBranch(input).pipe(
2010 - Effect.map((source) => source?.canDelete === true),
2011 - // The answer gates one optional action; an unusable CLI or account still surfaces.
2012 - Effect.catchIf(
2013 - (cause) =>
2014 - cause._tag !== "GitLabCliUnavailableError" &&
2015 - cause._tag !== "GitLabCliAuthenticationError" &&
2016 - cause._tag !== "GitLabCliRateLimitError",
2017 - () => Effect.succeed(false),
2018 - ),
2028 + viewerCanDeleteBranch: yield* orWhenUnanswered(
2029 + sourceBranch(input).pipe(Effect.map((source) => source?.canDelete === true)),
2030 + false,
2031 ),
2032 };
2033 if (input.downstreamChecks === false || detail.headPipeline === undefined) return detail;
@@ -2469,6 +2481,9 @@ export const make = Effect.gen(function* () {
2481 stdin: JSON.stringify({
2482 ...(input.title === undefined ? {} : { title: input.title }),
2483 ...(input.description === undefined ? {} : { description: input.description }),
2484 + ...(input.allowCollaboration === undefined
2485 + ? {}
2486 + : { allow_collaboration: input.allowCollaboration }),
2487 }),
2488 }).pipe(Effect.asVoid);
2489 }),
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts
+9 -2
@@ -145,6 +145,7 @@ describe("gitLabViewerPermissions", () => {
145 resolve: true,
146 verdicts: ["comment", "approve", "request-changes"],
147 requestReviewers: true,
148 + maintainerEdits: false,
149 labels: true,
150 updateMethods: ["rebase"],
151 });
@@ -157,6 +158,7 @@ describe("gitLabViewerPermissions", () => {
158 resolve: true,
159 verdicts: ["comment", "approve", "request-changes"],
160 requestReviewers: true,
161 + maintainerEdits: false,
162 labels: false,
163 });
164 });
@@ -190,13 +192,17 @@ describe("getChangeRequest base freshness", () => {
192 };
193
194 it.effect.each(["getChangeRequestPreview", "getChangeRequestSummary"] as const)(
193 - "%s preserves merge request fields without fetching project settings",
195 + "%s preserves merge request fields without fetching project settings or fork permissions",
196 (operation) =>
197 Effect.gen(function* () {
198 + const detailInputs: Array<{ readonly maintainerEdits?: boolean }> = [];
199 const provider = yield* make.pipe(
200 Effect.provide(
201 Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
199 - getMergeRequestDetail: () => Effect.succeed(detail),
202 + getMergeRequestDetail: (input) => {
203 + detailInputs.push(input);
204 + return Effect.succeed(detail);
205 + },
206 getListStates: () => Effect.succeed(new Map()),
207
208 listMergeRequestStats: () => Effect.succeed([]),
@@ -208,6 +214,7 @@ describe("getChangeRequest base freshness", () => {
214 expect(
215 yield* read({ cwd: "/w", repository: "acme/web", host: "gitlab.com", number: 7 }),
216 ).toEqual(detail);
217 + expect(detailInputs.map((input) => input.maintainerEdits)).toEqual([false]);
218 }),
219 );
220
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts
+13 -3
@@ -44,7 +44,7 @@ const CAPABILITIES: PullRequestCapabilities = {
44 },
45 reviewers: { request: true, listCandidates: true },
46 labels: true,
47 - edit: { changeRequest: true, comment: true },
47 + edit: { changeRequest: true, comment: true, maintainerEdits: true },
48 };
49
50 const UNAVAILABLE_REQUIREMENT = {
@@ -68,6 +68,7 @@ const MERGE_ACTIONS: ReadonlySet<string> = new Set([
68 /** Authors may close/reopen/change draft state regardless of role; REST omits authorship. */
69 export function gitLabViewerPermissions(input: {
70 readonly viewerCanMerge: boolean;
71 + readonly viewerCanEditMaintainerEdits?: boolean | undefined;
72 readonly viewerCanDeleteBranch?: boolean;
73 readonly viewerCanEditLabels?: boolean | undefined;
74 }): PullRequestViewerPermissions {
@@ -81,6 +82,7 @@ export function gitLabViewerPermissions(input: {
82 resolve: true,
83 verdicts: CAPABILITIES.review.verdicts,
84 requestReviewers: true,
85 + maintainerEdits: input.viewerCanEditMaintainerEdits === true,
86 labels: input.viewerCanEditLabels === true,
87 ...(input.viewerCanMerge ? { updateMethods: CAPABILITIES.updateMethods } : {}),
88 };
@@ -321,12 +323,17 @@ export const make = Effect.gen(function* () {
323
324 // Merge settings only affect the detail panel's actions.
325 getChangeRequestPreview: (input) =>
324 - cli.getMergeRequestDetail(input).pipe(Effect.mapError(fail("getChangeRequestPreview"))),
326 + cli
327 + .getMergeRequestDetail({ ...input, maintainerEdits: false })
328 + .pipe(Effect.mapError(fail("getChangeRequestPreview"))),
329
330 getChangeRequestSummary: (input) =>
331 Effect.all(
332 [
329 - mergeRequestWithStats(input),
333 + mergeRequestWithStats(
334 + input,
335 + cli.getMergeRequestDetail({ ...input, maintainerEdits: false }),
336 + ),
337 listStates({
338 cwd: input.cwd,
339 host: input.host,
@@ -582,6 +589,9 @@ export const make = Effect.gen(function* () {
589 number: input.number,
590 ...(input.title === undefined ? {} : { title: input.title }),
591 ...(input.body === undefined ? {} : { description: input.body }),
592 + ...(input.maintainerCanModify === undefined
593 + ? {}
594 + : { allowCollaboration: input.maintainerCanModify }),
595 })
596 .pipe(Effect.mapError(fail("updateChangeRequest"))),
597 ),
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+73
@@ -92,6 +92,10 @@ const RawMergeRequestSchema = Schema.Struct({
92 squash: Schema.optional(Schema.NullOr(Schema.Boolean)),
93 /** Only detail reads with include_diverged_commits_count return this expensive count. */
94 diverged_commits_count: Schema.optional(Schema.NullOr(Schema.Int)),
95 + source_project_id: Schema.optional(Schema.NullOr(Schema.Int)),
96 + target_project_id: Schema.optional(Schema.NullOr(Schema.Int)),
97 + /** Null on merge requests from the same project, where it means nothing. */
98 + allow_collaboration: Schema.optional(Schema.NullOr(Schema.Boolean)),
99 diff_refs: Schema.optional(Schema.NullOr(RawMergeRequestDiffRefs)),
100 });
101
@@ -224,6 +228,9 @@ export interface GitLabMergeRequestDetail extends GitLabMergeRequestListItem {
228 readonly diffRefs?: GitLabDiffRefs;
229 /** On a fork the pipeline often belongs to the source project, not the target. */
230 readonly headPipeline?: { readonly id: number; readonly projectId: number };
231 + /** Whether target maintainers may push to the source branch. Only set on merge requests from forks. */
232 + readonly maintainerCanModify?: boolean;
233 + readonly viewerCanEditMaintainerEdits?: boolean;
234 }
235
236 function toActor(raw: Schema.Schema.Type<typeof RawUserSchema> | null | undefined) {
@@ -524,6 +531,11 @@ function toDetail(raw: Schema.Schema.Type<typeof RawMergeRequestSchema>): GitLab
531 ...(raw.head_pipeline?.id == null || raw.head_pipeline.project_id == null
532 ? {}
533 : { headPipeline: { id: raw.head_pipeline.id, projectId: raw.head_pipeline.project_id } }),
534 + ...(raw.source_project_id != null &&
535 + raw.target_project_id != null &&
536 + raw.source_project_id !== raw.target_project_id
537 + ? { maintainerCanModify: raw.allow_collaboration === true }
538 + : {}),
539 };
540 }
541
@@ -1864,6 +1876,67 @@ export function decodeLabelPermissionJson(raw: string): Result.Result<boolean, D
1876 : Result.fail(decoded.failure);
1877 }
1878
1879 +/**
1880 + * GitLab lets whoever can push to a fork's branch allow maintainer pushes, but once allowed the
1881 + * target's maintainers can push too, so only the author may change it, as on GitHub. GitLab
1882 + * drops the setting unless the source branch is unprotected and neither project is private
1883 + * (`MergeRequest#collaborative_push_possible?`).
1884 + */
1885 +export const MAINTAINER_EDITS_PERMISSION_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!) {
1886 + currentUser { username }
1887 + project(fullPath: $fullPath) {
1888 + visibility
1889 + mergeRequest(iid: $iid) {
1890 + author { username }
1891 + userPermissions { pushToSourceBranch }
1892 + sourceBranchProtected
1893 + sourceProject { visibility }
1894 + }
1895 + }
1896 +}`;
1897 +
1898 +const decodeMaintainerEditsPermission = decodeJsonResult(
1899 + Schema.Struct({
1900 + data: Schema.Struct({
1901 + currentUser: Schema.NullOr(Schema.Struct({ username: Schema.String })),
1902 + project: Schema.NullOr(
1903 + Schema.Struct({
1904 + visibility: Schema.NullOr(Schema.String),
1905 + mergeRequest: Schema.NullOr(
1906 + Schema.Struct({
1907 + author: Schema.NullOr(Schema.Struct({ username: Schema.String })),
1908 + userPermissions: Schema.Struct({ pushToSourceBranch: Schema.Boolean }),
1909 + sourceBranchProtected: Schema.Boolean,
1910 + sourceProject: Schema.NullOr(
1911 + Schema.Struct({ visibility: Schema.NullOr(Schema.String) }),
1912 + ),
1913 + }),
1914 + ),
1915 + }),
1916 + ),
1917 + }),
1918 + }),
1919 +);
1920 +
1921 +export function decodeMaintainerEditsPermissionJson(
1922 + raw: string,
1923 +): Result.Result<boolean, DecodeFailure> {
1924 + const decoded = decodeMaintainerEditsPermission(raw);
1925 + if (Result.isFailure(decoded)) return Result.fail(decoded.failure);
1926 + const { currentUser, project } = decoded.success.data;
1927 + const mergeRequest = project?.mergeRequest;
1928 + const isPublicOrInternal = (visibility: string | null | undefined) =>
1929 + visibility === "public" || visibility === "internal";
1930 + return Result.succeed(
1931 + currentUser !== null &&
1932 + mergeRequest?.author?.username === currentUser.username &&
1933 + mergeRequest.userPermissions.pushToSourceBranch &&
1934 + !mergeRequest.sourceBranchProtected &&
1935 + isPublicOrInternal(project?.visibility) &&
1936 + isPublicOrInternal(mergeRequest.sourceProject?.visibility),
1937 + );
1938 +}
1939 +
1940 /** Per-file line counts for one merge request, which the code/tests/generated breakdown sorts. */
1941 export const MERGE_REQUEST_FILE_STATS_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!) {
1942 project(fullPath: $fullPath) {