import Host from './host' ; import GitInfo from '../gitInfo' ; import ConfigInfo from "../configInfo" ; export default class DevOps implements Host { example example example private static urlRegex : RegExp = /(?:https:\/\/)?(?:[\w-]+@)?(?:ssh.)?dev\.azure\.com(?::[v\d]+)?\/([^\/]+\/[^\/]+)\/(?:_git\/)?([^/]+)/i ; public static match ( url ) { return DevOps . urlRegex . test ( url ) ; } public parse ( info ) { return { repoName : info . remoteUrl , ref : info . ref , userName : '' } ; } public assemble ( info ) { const baseUrl = info . repoName . replace ( DevOps . urlRegex , "https://dev.azure.com/$1/_git/$2" ) ; const path = encodeURIComponent ( `/${ info . relativeFilePath }` ) ; let version ; switch ( info . ref . type ) { case "branch" : version = `GB${ info . ref . value }` ; break ; case "commit" : version = `GC${ info . ref . value }` ; break ; } let url = `${ baseUrl }?path=${ path }&version=${ version }&_a=contents` ; if ( info . section && info . section . startLine && info . section . endLine ) { url += `&lineStyle=plain&line=${ info . section . startLine }&lineEnd=${ info . section . endLine }` ; if ( info . section . startColumn && info . section . endColumn ) { url += `&lineStartColumn=${ info . section . startColumn }&lineEndColumn=${ info . section . endColumn }` ; } else { url += "&lineStartColumn=1&lineEndColumn=1" ; } } return url ; } }