Skip to content

Commit 39ac8ac

Browse files
sergeibbbaxosoft-ramint
authored andcommitted
fixup! Retrieves a pull request from Azure
1 parent ce27c36 commit 39ac8ac

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

src/plus/integrations/providers/azure/azure.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type { AzurePullRequest, AzureWorkItemState, AzureWorkItemStateCategory,
2626
import {
2727
azurePullRequestStatusToState,
2828
azureWorkItemsStateCategoryToState,
29-
getPullRequestUrl,
29+
getAzurePullRequestWebUrl,
3030
isClosedAzurePullRequestStatus,
3131
isClosedAzureWorkItemStateCategory,
3232
} from './models';
@@ -148,7 +148,7 @@ export class AzureDevOpsApi implements Disposable {
148148
state: azurePullRequestStatusToState(prResult.status),
149149
closed: isClosedAzurePullRequestStatus(prResult.status),
150150
title: prResult.title,
151-
url: getPullRequestUrl(options.baseUrl, owner, projectName, repoName, prResult.pullRequestId),
151+
url: getAzurePullRequestWebUrl(prResult),
152152
};
153153
}
154154

src/plus/integrations/providers/azure/models.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,34 @@ export function isClosedAzurePullRequestStatus(status: AzurePullRequestStatus):
9393
return azurePullRequestStatusToState(status) !== 'opened';
9494
}
9595

96-
export function getPullRequestUrl(
97-
baseUrl: string,
98-
owner: string,
99-
projectName: string,
100-
repoName: string,
101-
pullRequestId: number,
102-
): string {
103-
return `${baseUrl}/${owner}/${projectName}/_git/${repoName}/pullrequest/${pullRequestId}`;
96+
export type AzureProjectState = 'createPending' | 'deleted' | 'deleting' | 'new' | 'unchanged' | 'wellFormed';
97+
export type AzureProjectVisibility = 'private' | 'public';
98+
99+
export interface AzureProject {
100+
id: string;
101+
name: string;
102+
url: string;
103+
state: AzureProjectState;
104+
revision: number;
105+
visibility: AzureProjectVisibility;
106+
lastUpdateTime: string;
107+
}
108+
109+
export interface AzureRepository {
110+
id: string;
111+
name: string;
112+
url: string;
113+
project: AzureProject;
114+
size: number;
115+
remoteUrl: string;
116+
sshUrl: string;
117+
webUrl: string;
118+
isDisabled: boolean;
119+
isInMaintenance: boolean;
104120
}
105121

106122
export interface AzurePullRequest {
107-
repository: unknown;
123+
repository: AzureRepository;
108124
pullRequestId: number;
109125
codeReviewId: number;
110126
status: AzurePullRequestStatus;
@@ -142,3 +158,21 @@ export interface AzurePullRequest {
142158
supportsIterations: boolean;
143159
artifactId: string;
144160
}
161+
export function getAzureDevOpsOwner(url: URL): string {
162+
return url.pathname.split('/')[1];
163+
}
164+
export function getAzureRepo(pr: AzurePullRequest): string {
165+
return `${pr.repository.project.name}/_git/${pr.repository.name}`;
166+
}
167+
168+
export function getAzurePullRequestWebUrl(pr: AzurePullRequest): string {
169+
const url = new URL(pr.url);
170+
const baseUrl = new URL(url.origin).toString();
171+
const repoPath = getAzureRepo(pr);
172+
const isVSTS = url.hostname.endsWith('visualstudio.com');
173+
if (isVSTS) {
174+
return `${baseUrl}/${repoPath}/pullrequest/${pr.pullRequestId}`;
175+
}
176+
const owner = getAzureDevOpsOwner(url);
177+
return `${baseUrl}/${owner}/${repoPath}/pullrequest/${pr.pullRequestId}`;
178+
}

0 commit comments

Comments
 (0)