@@ -185,6 +185,114 @@ it.effect("parses pull request responses from the Bitbucket REST API", () => {
185185 } ) . pipe ( Effect . provide ( layer ) ) ;
186186} ) ;
187187
188+ it . effect . each ( [ false , true ] ) ( "honors PR URL repositories, context=%s" , ( withContext ) => {
189+ const { execute, git, layer } = makeLayer ( {
190+ response : ( request ) =>
191+ Response . json (
192+ request . url . endsWith ( "/pullrequests/42" )
193+ ? {
194+ ...bitbucketPullRequest ,
195+ source : {
196+ branch : { name : "feature/source-control" } ,
197+ repository : { full_name : "another/app" } ,
198+ } ,
199+ destination : { branch : { name : "main" } , repository : { full_name : "another/app" } } ,
200+ }
201+ : {
202+ ...repositoryJson ,
203+ full_name : "another/app" ,
204+ links :
{ clone :
[ { name :
"ssh" , href :
"[email protected] :another/app.git" } ] } , 205+ } ,
206+ ) ,
207+ } ) ;
208+ return Effect . gen ( function * ( ) {
209+ const bitbucket = yield * BitbucketApi . BitbucketApi ;
210+ const input = {
211+ cwd : "/repo" ,
212+ reference : "https://bitbucket.org/another/app/pull-requests/42" ,
213+ ...( withContext
214+ ? {
215+ context : {
216+ provider : {
217+ kind : SourceControlProviderKind . make ( "bitbucket" ) ,
218+ name : "Bitbucket" ,
219+ baseUrl : "https://bitbucket.org" ,
220+ } ,
221+ remoteName : "origin" ,
222+ remoteUrl :
"[email protected] :pingdotgg/t3code.git" , 223+ } ,
224+ }
225+ : { } ) ,
226+ } ;
227+ yield * bitbucket . getPullRequest ( input ) ;
228+ yield * bitbucket . checkoutPullRequest ( input ) ;
229+ assert . deepStrictEqual (
230+ execute . mock . calls . slice ( 0 , 2 ) . map ( ( [ request ] ) => request . url ) ,
231+ [
232+ "https://api.test.local/2.0/repositories/another/app/pullrequests/42" ,
233+ "https://api.test.local/2.0/repositories/another/app/pullrequests/42" ,
234+ ] ,
235+ ) ;
236+ assert . deepStrictEqual ( git . ensureRemote . mock . calls [ 0 ] ?. [ 0 ] , {
237+ cwd : "/repo" ,
238+ preferredName : "another" ,
239+ url :
"[email protected] :another/app.git" , 240+ } ) ;
241+ assert . deepStrictEqual ( git . fetchRemoteBranch . mock . calls [ 0 ] ?. [ 0 ] , {
242+ cwd : "/repo" ,
243+ remoteName : "octocat" ,
244+ remoteBranch : "feature/source-control" ,
245+ localBranch : "feature/source-control" ,
246+ } ) ;
247+ assert . deepStrictEqual ( git . setBranchUpstream . mock . calls [ 0 ] ?. [ 0 ] , {
248+ cwd : "/repo" ,
249+ branch : "feature/source-control" ,
250+ remoteName : "octocat" ,
251+ remoteBranch : "feature/source-control" ,
252+ } ) ;
253+ } ) . pipe ( Effect . provide ( layer ) ) ;
254+ } ) ;
255+
256+ it . effect . each ( [ false , true ] ) (
257+ "reuses matching checkout remotes for numeric references, context=%s" ,
258+ ( withContext ) => {
259+ const { git, layer } = makeLayer ( {
260+ response : ( ) =>
261+ Response . json ( {
262+ ...bitbucketPullRequest ,
263+ source : { ...bitbucketPullRequest . source , repository : { full_name : "pingdotgg/t3code" } } ,
264+ } ) ,
265+ } ) ;
266+ return Effect . gen ( function * ( ) {
267+ const bitbucket = yield * BitbucketApi . BitbucketApi ;
268+ yield * bitbucket . checkoutPullRequest ( {
269+ cwd : "/repo" ,
270+ reference : "#42" ,
271+ ...( withContext
272+ ? {
273+ context : {
274+ provider : {
275+ kind : SourceControlProviderKind . make ( "bitbucket" ) ,
276+ name : "Bitbucket" ,
277+ baseUrl : "https://bitbucket.org" ,
278+ } ,
279+ remoteName : "upstream" ,
280+ remoteUrl :
"[email protected] :PingDotGG/T3Code.git" , 281+ } ,
282+ }
283+ : { } ) ,
284+ } ) ;
285+ assert . strictEqual ( git . ensureRemote . mock . calls . length , 0 ) ;
286+ assert . deepStrictEqual ( git . fetchRemoteBranch . mock . calls [ 0 ] ?. [ 0 ] , {
287+ cwd : "/repo" ,
288+ remoteName : withContext ? "upstream" : "origin" ,
289+ remoteBranch : "feature/source-control" ,
290+ localBranch : "feature/source-control" ,
291+ } ) ;
292+ } ) . pipe ( Effect . provide ( layer ) ) ;
293+ } ,
294+ ) ;
295+
188296it . effect ( "lists pull requests with Bitbucket state and source branch query params" , ( ) => {
189297 const { execute, layer } = makeLayer ( {
190298 response : ( ) =>
0 commit comments