@@ -369,6 +369,55 @@ export class BitbucketApi implements Disposable {
369369 }
370370 }
371371
372+ @debug < BitbucketApi [ 'getPullRequestForCommit' ] > ( { args : { 0 : p => p . name , 1 : '<token>' } } )
373+ async getPullRequestForCommit (
374+ provider : Provider ,
375+ token : string ,
376+ owner : string ,
377+ repo : string ,
378+ rev : string ,
379+ baseUrl : string ,
380+ _options ?: {
381+ avatarSize ?: number ;
382+ } ,
383+ cancellation ?: CancellationToken ,
384+ ) : Promise < PullRequest | undefined > {
385+ const scope = getLogScope ( ) ;
386+
387+ try {
388+ const fields = [
389+ '+values.*' ,
390+ '+values.destination.repository' ,
391+ '+values.destination.branch.*' ,
392+ '+values.destination.commit.*' ,
393+ '+values.source.repository.*' ,
394+ '+values.source.branch.*' ,
395+ '+values.source.commit.*' ,
396+ ] ;
397+ const fieldsParam = encodeURIComponent ( fields . join ( ',' ) ) ;
398+ const response = await this . request < { values : BitbucketPullRequest [ ] } > (
399+ provider ,
400+ token ,
401+ baseUrl ,
402+ `repositories/${ owner } /${ repo } /commit/${ rev } /pullrequests?fields=${ fieldsParam } ` ,
403+ {
404+ method : 'GET' ,
405+ } ,
406+ scope ,
407+ cancellation ,
408+ ) ;
409+ const pr = response ?. values ?. reduce < BitbucketPullRequest | undefined > (
410+ ( acc , pr ) => ( ! acc || pr . updated_on > acc . updated_on ? pr : acc ) ,
411+ undefined ,
412+ ) ;
413+ if ( ! pr ) return undefined ;
414+ return fromBitbucketPullRequest ( pr , provider ) ;
415+ } catch ( ex ) {
416+ Logger . error ( ex , scope ) ;
417+ return undefined ;
418+ }
419+ }
420+
372421 private async request < T > (
373422 provider : Provider ,
374423 token : string ,
0 commit comments