@@ -8,7 +8,7 @@ import { Branch, CommitInfo, Repository, RepositoryInfo, User } from "@gitpod/gi
88import { inject , injectable } from "inversify" ;
99import { RepoURL } from "../repohost" ;
1010import { RepositoryProvider } from "../repohost/repository-provider" ;
11- import { BitbucketServerApi } from "./bitbucket-server-api" ;
11+ import { BitbucketServer , BitbucketServerApi } from "./bitbucket-server-api" ;
1212import { log } from "@gitpod/gitpod-protocol/lib/util/logging" ;
1313import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server" ;
1414import { getPrimaryEmail } from "@gitpod/public-api-common/lib/user-utils" ;
@@ -75,24 +75,10 @@ export class BitbucketServerRepositoryProvider implements RepositoryProvider {
7575 repositorySlug : repo ,
7676 branchName,
7777 } ) ;
78- const commit = branch . latestCommitMetadata ;
79-
80- return {
81- htmlUrl : branch . htmlUrl ,
82- name : branch . displayId ,
83- commit : {
84- sha : commit . id ,
85- author : commit . author . displayName ,
86- authorAvatarUrl : commit . author . avatarUrl ,
87- authorDate : new Date ( commit . authorTimestamp ) . toISOString ( ) ,
88- commitMessage : commit . message || "missing commit message" ,
89- } ,
90- } ;
78+ return this . toBranch ( branch ) ;
9179 }
9280
9381 async getBranches ( user : User , owner : string , repo : string ) : Promise < Branch [ ] > {
94- const branches : Branch [ ] = [ ] ;
95-
9682 const repoKind = await this . getOwnerKind ( user , owner ) ;
9783 if ( ! repoKind ) {
9884 throw new Error ( `Could not find project "${ owner } "` ) ;
@@ -102,23 +88,22 @@ export class BitbucketServerRepositoryProvider implements RepositoryProvider {
10288 owner,
10389 repositorySlug : repo ,
10490 } ) ;
105- for ( const entry of branchesResult ) {
106- const commit = entry . latestCommitMetadata ;
107-
108- branches . push ( {
109- htmlUrl : entry . htmlUrl ,
110- name : entry . displayId ,
111- commit : {
112- sha : commit . id ,
113- author : commit . author . displayName ,
114- authorAvatarUrl : commit . author . avatarUrl ,
115- authorDate : new Date ( commit . authorTimestamp ) . toISOString ( ) ,
116- commitMessage : commit . message || "missing commit message" ,
117- } ,
118- } ) ;
119- }
91+ return branchesResult . map ( ( entry ) => this . toBranch ( entry ) ) ;
92+ }
12093
121- return branches ;
94+ private toBranch ( entry : BitbucketServer . BranchWithMeta ) : Branch {
95+ const commit = entry . latestCommitMetadata ;
96+ return {
97+ htmlUrl : entry . htmlUrl ,
98+ name : entry . displayId ,
99+ commit : {
100+ sha : commit ?. id ?? entry . latestCommit ,
101+ author : commit ?. author . displayName || "missing author" ,
102+ authorAvatarUrl : commit ?. author . avatarUrl ,
103+ authorDate : commit ?. authorTimestamp ? new Date ( commit . authorTimestamp ) . toISOString ( ) : undefined ,
104+ commitMessage : commit ?. message || "missing commit message" ,
105+ } ,
106+ } ;
122107 }
123108
124109 async getCommitInfo ( user : User , owner : string , repo : string , ref : string ) : Promise < CommitInfo | undefined > {
0 commit comments