@@ -26,7 +26,7 @@ import { Logger } from '../../../../system/logger';
26
26
import type { LogScope } from '../../../../system/logger.scope' ;
27
27
import { getLogScope } from '../../../../system/logger.scope' ;
28
28
import { maybeStopWatch } from '../../../../system/stopwatch' ;
29
- import type { BitbucketServerPullRequest } from '../bitbucket-server/models' ;
29
+ import type { BitbucketServerCommit , BitbucketServerPullRequest } from '../bitbucket-server/models' ;
30
30
import { normalizeBitbucketServerPullRequest } from '../bitbucket-server/models' ;
31
31
import { fromProviderPullRequest } from '../models' ;
32
32
import type { BitbucketCommit , BitbucketIssue , BitbucketPullRequest , BitbucketRepository } from './models' ;
@@ -519,6 +519,60 @@ export class BitbucketApi implements Disposable {
519
519
}
520
520
}
521
521
522
+ @debug < BitbucketApi [ 'getServerAccountForCommit' ] > ( { args : { 0 : p => p . name , 1 : '<token>' } } )
523
+ async getServerAccountForCommit (
524
+ provider : Provider ,
525
+ token : string ,
526
+ owner : string ,
527
+ repo : string ,
528
+ rev : string ,
529
+ baseUrl : string ,
530
+ _options ?: {
531
+ avatarSize ?: number ;
532
+ } ,
533
+ cancellation ?: CancellationToken ,
534
+ ) : Promise < Account | UnidentifiedAuthor | undefined > {
535
+ const scope = getLogScope ( ) ;
536
+
537
+ try {
538
+ const commit = await this . request < BitbucketServerCommit > (
539
+ provider ,
540
+ token ,
541
+ baseUrl ,
542
+ `projects/${ owner } /repos/${ repo } /commits/${ rev } ` ,
543
+ {
544
+ method : 'GET' ,
545
+ } ,
546
+ scope ,
547
+ cancellation ,
548
+ ) ;
549
+ if ( ! commit ?. author ) {
550
+ return undefined ;
551
+ }
552
+ if ( commit . author . id != null ) {
553
+ return {
554
+ provider : provider ,
555
+ id : commit . author . id . toString ( ) ,
556
+ username : commit . author . name ,
557
+ name : commit . author . name ,
558
+ email : commit . author . emailAddress ,
559
+ avatarUrl : commit . author ?. avatarUrl ,
560
+ } satisfies Account ;
561
+ }
562
+ return {
563
+ provider : provider ,
564
+ id : undefined ,
565
+ username : undefined ,
566
+ name : commit . author . name ,
567
+ email : commit . author . emailAddress ,
568
+ avatarUrl : undefined ,
569
+ } satisfies UnidentifiedAuthor ;
570
+ } catch ( ex ) {
571
+ Logger . error ( ex , scope ) ;
572
+ return undefined ;
573
+ }
574
+ }
575
+
522
576
private async request < T > (
523
577
provider : Provider ,
524
578
token : string ,
0 commit comments