in commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/tfs/TfsRepositoryInfo.java [75:163]
public static TfsRepositoryInfo parse(@Nullable final String repositoryUrl, @Nullable final String serverUrl) {
if (StringUtil.isEmptyOrSpaces(repositoryUrl)) {
return null;
}
final Matcher urlMatcher = TFS_URL_PATTERN.matcher(repositoryUrl.trim());
if (!urlMatcher.find()) {
return null;
}
String schema = urlMatcher.group(1);
String username = urlMatcher.group(2);
String hostname = urlMatcher.group(3).toLowerCase();
String urlPath = StringUtil.notEmpty(urlMatcher.group(4), StringUtil.EMPTY);
String server;
boolean isDevAzureCom = StringUtil.endsWith(hostname, "dev.azure.com");
if (StringUtil.isEmpty(schema) || "ssh".equalsIgnoreCase(schema)) {
// DevOps URL
if (isDevAzureCom) {
final Matcher pathMatcher = TFS_DEVOPS_PATH_PATTERN.matcher(urlPath);
if (!pathMatcher.find()) {
return null;
}
return new TfsRepositoryInfo(
"https://dev.azure.com/" + pathMatcher.group(1),
pathMatcher.group(3),
pathMatcher.group(2)
);
}
if (StringUtil.endsWith(hostname, ".visualstudio.com:22")) {
// VSTS URL
if (StringUtil.isEmpty(username)) {
return null;
}
server = String.format("https://%s.visualstudio.com", username);
} else if (StringUtil.endsWith(hostname, "vs-ssh.visualstudio.com")) {
// VSTS URL
final Matcher pathMatcher = TFS_DEVOPS_PATH_PATTERN.matcher(urlPath);
if (!pathMatcher.find()) {
return null;
}
return new TfsRepositoryInfo(
String.format("https://%s.visualstudio.com", pathMatcher.group(1)),
pathMatcher.group(3),
pathMatcher.group(2)
);
} else if (!StringUtil.isEmpty(serverUrl)) {
// Has configured server URl for on-premises TFS
final Matcher serverUrlMatcher = TFS_URL_PATTERN.matcher(serverUrl.trim());
if (!serverUrlMatcher.find()) {
return null;
}
server = serverUrlMatcher.group(1) + "://" + serverUrlMatcher.group(3);
} else {
return null;
}
} else {
server = schema + "://" + hostname;
}
final Matcher pathMatcher = TFS_GIT_PROJECT_PATH_PATTERN.matcher(urlPath);
if (!pathMatcher.find()) {
return null;
}
String path = StringUtil.notEmpty(pathMatcher.group(1), StringUtil.EMPTY);
String repository = pathMatcher.group(2);
int lastSlash = path.lastIndexOf('/');
String project = null;
if (isDevAzureCom && lastSlash == 0) {
project = repository;
} else if (lastSlash >= 0) {
final String lastPathSegment = path.substring(lastSlash + 1);
if (!"defaultCollection".equalsIgnoreCase(lastPathSegment)) {
final String collection = path.substring(0, lastSlash);
if (StringUtil.isNotEmpty(collection) && !collection.equals("/tfs") || isHosted(server)) {
project = lastPathSegment;
path = collection;
}
}
}
return new TfsRepositoryInfo(server + path, repository, project);
}