public static VcsHostingRepo getBitbucketServerRepo()

in git-server/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/WellKnownHostingsUtil.java [37:70]


  public static VcsHostingRepo getBitbucketServerRepo(@NotNull URIish uri) {
    String host = uri.getHost();
    if (host == null)
      return null;

    String path = uri.getPath();
    if (uri.getScheme() != null && uri.getScheme().startsWith("http") && path.endsWith(".git") && (path.startsWith("/scm/") || path.startsWith("/git/"))) {
      // probably Bitbucket server
      String ownerAndRepo = path.substring(5); // length of /scm/ or /git/
      int slashIdx = ownerAndRepo.indexOf('/');
      if (slashIdx == -1) return null;
      String owner = ownerAndRepo.substring(0, slashIdx);
      String repo = ownerAndRepo.substring(slashIdx+1, ownerAndRepo.length() - ".git".length());
      if (repo.contains("/")) return null;

      boolean personalRepo = '~' == owner.charAt(0);
      if (personalRepo) {
        owner = owner.substring(1);
      }

      String hostAndPort = host;
      if (uri.getPort() > 0 && uri.getPort() != 80 && uri.getPort() != 443) {
        hostAndPort += ":" + uri.getPort();
      }

      if (personalRepo) {
        return new VcsHostingRepo(uri.getScheme() + "://" + hostAndPort + "/users/" + owner + "/repos/" + repo, owner, repo);
      } else {
        return new VcsHostingRepo(uri.getScheme() + "://" + hostAndPort + "/projects/" + owner + "/repos/" + repo, owner, repo);
      }
    }

    return null;
  }