use of jetbrains.buildServer.serverSide.oauth.space.SpaceConnectDescriber in project teamcity-git by JetBrains.
the class SpaceExternalChangeViewerExtension method getAvailableProperties.
@Nullable
@Override
public Map<String, String> getAvailableProperties(@NotNull VcsRoot vcs) {
final VcsRootInstance vcsRoot = (VcsRootInstance) vcs;
if (!Constants.VCS_NAME.equals(vcsRoot.getVcsName()))
return null;
String url = vcsRoot.getProperty(Constants.FETCH_URL);
if (url == null)
return null;
URIish uri;
try {
uri = new URIish(url);
} catch (URISyntaxException e) {
return null;
}
final String gitPath = uri.getPath();
if (uri.getHost().endsWith(".jetbrains.space")) {
// Space is on the Jetbrains side
final String[] strings = gitPath.substring(1).split("/");
if (strings.length == 3) {
final String orgName = strings[0];
final String project = strings[1];
final String repository = strings[2].replaceFirst("\\.git$", "");
final String repositoryUrl = String.format("https://%s.jetbrains.space/p/%s/repositories/%s", orgName, project, repository);
return createResponse(repositoryUrl);
}
} else {
final SVcsRoot vcsRootParent = vcsRoot.getParent();
final List<OAuthConnectionDescriptor> connections = myOAuthConnectionsManager.getAvailableConnectionsOfType(vcsRootParent.getProject(), SpaceOAuthProvider.TYPE);
if (connections.isEmpty())
return null;
for (OAuthConnectionDescriptor connection : connections) {
final SpaceConnectDescriber spaceConnectDescriber = new SpaceConnectDescriber(connection);
final String spaceAddress = spaceConnectDescriber.getAddress();
if (uri.getHost().contains(spaceAddress)) {
// Selfhosted Space
final String[] strings = gitPath.substring(1).split("/");
if (strings.length == 2) {
final String project = strings[0];
final String repository = strings[1].replaceFirst("\\.git$", "");
final String repositoryUrl = String.format("https://%s/p/%s/repositories/%s", spaceAddress, project, repository);
return createResponse(repositoryUrl);
}
}
}
}
return null;
}
Aggregations