Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Sep 27, 2024
1 parent d5ff0f3 commit 0314a7d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions components/server/src/azure-devops/azure-context-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export class AzureDevOpsContextParser extends AbstractContextParser implements I
try {
const branchName = normalizeBranchName(repository.defaultBranch);
const branch = toBranch(
result.repository,
await this.azureDevOpsApi.getBranch(user, azOrganization, azProject, repo, branchName),
);
if (!branch) {
Expand Down
6 changes: 4 additions & 2 deletions components/server/src/azure-devops/azure-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ export function getOrgAndProject(orgAndProject: Repository["owner"]) {
return [azOrg, azProject] as const;
}

export function toBranch(d: GitBranchStats): Branch | undefined {
export function toBranch(repo: Repository, d: GitBranchStats): Branch | undefined {
if (!d.commit) {
return;
}
const commit = toCommit(d.commit);
if (!commit) {
return;
}
const url = new URL(repo.cloneUrl);
url.searchParams.set("version", `GB${d.name}`);
return {
htmlUrl: d.commit.url!,
htmlUrl: url.toString(),
name: d.name!,
commit,
};
Expand Down
14 changes: 10 additions & 4 deletions components/server/src/azure-devops/azure-repository-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export class AzureDevOpsRepositoryProvider implements RepositoryProvider {

async getBranch(user: User, owner: string, repo: string, branch: string): Promise<Branch> {
const [azOrg, azProject] = getOrgAndProject(owner);
const response = await this.azureDevOpsApi.getBranch(user, azOrg, azProject, repo, branch);
const item = toBranch(response);
const [repository, branchResp] = await Promise.all([
await this.getRepo(user, owner, repo),
await this.azureDevOpsApi.getBranch(user, azOrg, azProject, repo, branch),
]);
const item = toBranch(repository, branchResp);
if (!item) {
// TODO(hw): [AZ]
throw new Error("Failed to fetch commit.");
Expand All @@ -39,9 +42,12 @@ export class AzureDevOpsRepositoryProvider implements RepositoryProvider {
async getBranches(user: User, owner: string, repo: string): Promise<Branch[]> {
const branches: Branch[] = [];
const [azOrg, azProject] = getOrgAndProject(owner);
const response = await this.azureDevOpsApi.getBranches(user, azOrg, azProject, repo);
const [repository, response] = await Promise.all([
await this.getRepo(user, owner, repo),
await this.azureDevOpsApi.getBranches(user, azOrg, azProject, repo),
]);
for (const b of response) {
const item = toBranch(b);
const item = toBranch(repository, b);
if (!item) {
continue;
}
Expand Down

0 comments on commit 0314a7d

Please sign in to comment.