Skip to content

Commit b07323e

Browse files
authored
[server] fix BBS metadata latest-commit-metadata not defined cause prebuild trigger failed (#19331)
1 parent 230c190 commit b07323e

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

components/server/src/bitbucket-server/bitbucket-server-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ export namespace BitbucketServer {
499499
}
500500

501501
export interface BranchWithMeta extends Branch {
502-
latestCommitMetadata: Commit;
502+
latestCommitMetadata?: Commit;
503503
htmlUrl: string;
504504
metadata: {
505505
"com.atlassian.bitbucket.server.bitbucket-branch:latest-commit-metadata": Commit;

components/server/src/bitbucket-server/bitbucket-server-repository-provider.ts

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Branch, CommitInfo, Repository, RepositoryInfo, User } from "@gitpod/gi
88
import { inject, injectable } from "inversify";
99
import { RepoURL } from "../repohost";
1010
import { RepositoryProvider } from "../repohost/repository-provider";
11-
import { BitbucketServerApi } from "./bitbucket-server-api";
11+
import { BitbucketServer, BitbucketServerApi } from "./bitbucket-server-api";
1212
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
1313
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
1414
import { 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

Comments
 (0)