@@ -78,6 +78,10 @@ const RawMergeRequestSchema = Schema.Struct({
7878 squash : Schema . optional ( Schema . NullOr ( Schema . Boolean ) ) ,
7979 /** Only detail reads with include_diverged_commits_count return this expensive count. */
8080 diverged_commits_count : Schema . optional ( Schema . NullOr ( Schema . Int ) ) ,
81+ source_project_id : Schema . optional ( Schema . NullOr ( Schema . Int ) ) ,
82+ target_project_id : Schema . optional ( Schema . NullOr ( Schema . Int ) ) ,
83+ /** Null on merge requests from the same project, where it means nothing. */
84+ allow_collaboration : Schema . optional ( Schema . NullOr ( Schema . Boolean ) ) ,
8185} ) ;
8286
8387const RawNoteSchema = Schema . Struct ( {
@@ -209,6 +213,9 @@ export interface GitLabMergeRequestDetail extends GitLabMergeRequestListItem {
209213 readonly headSha ?: string ;
210214 /** On a fork the pipeline often belongs to the source project, not the target. */
211215 readonly headPipeline ?: { readonly id : number ; readonly projectId : number } ;
216+ /** Whether target maintainers may push to the source branch. Only set on merge requests from forks. */
217+ readonly maintainerCanModify ?: boolean ;
218+ readonly viewerCanEditMaintainerEdits ?: boolean ;
212219}
213220
214221function toActor ( raw : Schema . Schema . Type < typeof RawUserSchema > | null | undefined ) {
@@ -345,6 +352,11 @@ function toDetail(raw: Schema.Schema.Type<typeof RawMergeRequestSchema>): GitLab
345352 ...( raw . head_pipeline ?. id == null || raw . head_pipeline . project_id == null
346353 ? { }
347354 : { headPipeline : { id : raw . head_pipeline . id , projectId : raw . head_pipeline . project_id } } ) ,
355+ ...( raw . source_project_id != null &&
356+ raw . target_project_id != null &&
357+ raw . source_project_id !== raw . target_project_id
358+ ? { maintainerCanModify : raw . allow_collaboration === true }
359+ : { } ) ,
348360 } ;
349361}
350362
@@ -1141,6 +1153,52 @@ export function decodeMergeRequestStatsJson(
11411153 return Result . succeed ( stats ) ;
11421154}
11431155
1156+ /**
1157+ * GitLab lets whoever can push to a fork's branch allow maintainer pushes, but once allowed the
1158+ * target's maintainers can push too, so only the author may change it, as on GitHub.
1159+ */
1160+ export const MAINTAINER_EDITS_PERMISSION_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!) {
1161+ currentUser { username }
1162+ project(fullPath: $fullPath) {
1163+ mergeRequest(iid: $iid) {
1164+ author { username }
1165+ userPermissions { pushToSourceBranch }
1166+ }
1167+ }
1168+ }` ;
1169+
1170+ const decodeMaintainerEditsPermission = decodeJsonResult (
1171+ Schema . Struct ( {
1172+ data : Schema . Struct ( {
1173+ currentUser : Schema . NullOr ( Schema . Struct ( { username : Schema . String } ) ) ,
1174+ project : Schema . NullOr (
1175+ Schema . Struct ( {
1176+ mergeRequest : Schema . NullOr (
1177+ Schema . Struct ( {
1178+ author : Schema . NullOr ( Schema . Struct ( { username : Schema . String } ) ) ,
1179+ userPermissions : Schema . Struct ( { pushToSourceBranch : Schema . Boolean } ) ,
1180+ } ) ,
1181+ ) ,
1182+ } ) ,
1183+ ) ,
1184+ } ) ,
1185+ } ) ,
1186+ ) ;
1187+
1188+ export function decodeMaintainerEditsPermissionJson (
1189+ raw : string ,
1190+ ) : Result . Result < boolean , DecodeFailure > {
1191+ const decoded = decodeMaintainerEditsPermission ( raw ) ;
1192+ if ( Result . isFailure ( decoded ) ) return Result . fail ( decoded . failure ) ;
1193+ const { currentUser, project } = decoded . success . data ;
1194+ const mergeRequest = project ?. mergeRequest ;
1195+ return Result . succeed (
1196+ currentUser !== null &&
1197+ mergeRequest ?. author ?. username === currentUser . username &&
1198+ mergeRequest . userPermissions . pushToSourceBranch ,
1199+ ) ;
1200+ }
1201+
11441202/** Per-file line counts for one merge request, which the code/tests/generated breakdown sorts. */
11451203export const MERGE_REQUEST_FILE_STATS_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!) {
11461204 project(fullPath: $fullPath) {
0 commit comments