@@ -37,6 +37,10 @@ import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
3737import * as VcsProcess from "../vcs/VcsProcess.ts" ;
3838import * as GitHubSourceControlProvider from "../sourceControl/GitHubSourceControlProvider.ts" ;
3939import * as GitLabSourceControlProvider from "../sourceControl/GitLabSourceControlProvider.ts" ;
40+ import {
41+ ForgejoPullRequestSchema ,
42+ toForgejoChangeRequest ,
43+ } from "../sourceControl/forgejoPullRequests.ts" ;
4044import type { SourceControlProvider } from "../sourceControl/SourceControlProvider.ts" ;
4145import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts" ;
4246import * as ServerConfig from "../config.ts" ;
@@ -46,6 +50,7 @@ import * as ServerSettings from "../serverSettings.ts";
4650import * as GitManager from "./GitManager.ts" ;
4751
4852const encodeCliJson = Schema . encodeSync ( Schema . fromJsonString ( Schema . Unknown ) ) ;
53+ const decodeForgejoPullRequest = Schema . decodeEffect ( ForgejoPullRequestSchema ) ;
4954
5055interface FakeGhScenario {
5156 prListSequence ?: string [ ] ;
@@ -3851,6 +3856,69 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
38513856 20_000 ,
38523857 ) ;
38533858
3859+ it . effect ( "matches mounted Forgejo heads without confusing forks sharing a branch" , ( ) =>
3860+ Effect . gen ( function * ( ) {
3861+ for ( const owner of [ "maria" , "reviewer" ] ) {
3862+ const mapped = toForgejoChangeRequest (
3863+ yield * decodeForgejoPullRequest ( {
3864+ number : 42 ,
3865+ title : "Greeting" ,
3866+ html_url : "https://forgejo.example/forgejo/maria/project/pulls/42" ,
3867+ state : "open" ,
3868+ merged : false ,
3869+ base : {
3870+ ref : "main" ,
3871+ sha : "base" ,
3872+ repo : { full_name : "maria/project" , owner : { login : "maria" } } ,
3873+ } ,
3874+ head : {
3875+ ref : "greeting" ,
3876+ sha : "head" ,
3877+ repo : { full_name : `${ owner } /project` , owner : { login : owner } } ,
3878+ } ,
3879+ } ) ,
3880+ ) ;
3881+ const pr = {
3882+ ...mapped ,
3883+ isDraft : mapped . isDraft ?? false ,
3884+ closedAt : mapped . closedAt ?? null ,
3885+ mergedAt : mapped . mergedAt ?? null ,
3886+ } ;
3887+ const repository = GitManager . parseRepositoryNameWithOwnerFromRemoteUrl (
3888+ `https://forgejo.example/forgejo/${ owner } /project.git` ,
3889+ "forgejo" ,
3890+ ) ;
3891+ expect ( repository ) . toBe ( `${ owner } /project` ) ;
3892+ const context = {
3893+ headBranch : "greeting" ,
3894+ headRepositoryNameWithOwner : repository ,
3895+ headRepositoryOwnerLogin : repository ?. split ( "/" ) [ 0 ] ?? null ,
3896+ isCrossRepository : owner !== "maria" ,
3897+ } ;
3898+ expect ( GitManager . matchesBranchHeadContext ( pr , context ) ) . toBe ( true ) ;
3899+ expect (
3900+ GitManager . matchesBranchHeadContext ( pr , {
3901+ ...context ,
3902+ headRepositoryNameWithOwner : "other/project" ,
3903+ headRepositoryOwnerLogin : "other" ,
3904+ } ) ,
3905+ ) . toBe ( false ) ;
3906+ }
3907+ expect (
3908+ GitManager . parseRepositoryNameWithOwnerFromRemoteUrl (
3909+ "[email protected] :maria/project.git" , 3910+ "forgejo" ,
3911+ ) ,
3912+ ) . toBe ( "maria/project" ) ;
3913+ expect (
3914+ GitManager . parseRepositoryNameWithOwnerFromRemoteUrl (
3915+ "https://gitlab.example/group/maria/project.git" ,
3916+ "gitlab" ,
3917+ ) ,
3918+ ) . toBe ( "group/maria/project" ) ;
3919+ } ) ,
3920+ ) ;
3921+
38543922 it . effect ( "rejects same-repo PR metadata when matching a cross-repo head context" , ( ) =>
38553923 Effect . sync ( ( ) => {
38563924 const headContext = {
0 commit comments