@@ -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
106122export 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