public void testConnection()

in commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/bitbucketCloud/BitbucketCloudSettings.java [187:229]


  public void testConnection(@NotNull BuildTypeIdentity buildTypeOrTemplate, @NotNull VcsRoot root, @NotNull Map<String, String> params) throws PublisherException {
    Repository repository = VCS_PROPERTIES_PARSER.parseRepository(root);
    if (null == repository)
      throw new PublisherException("Cannot parse repository URL from VCS root " + root.getName());
    final String repoName = repository.repositoryName();
    String url = getDefaultApiUrl() + "/2.0/repositories/" + repository.owner() + "/" + repoName;
    HttpResponseProcessor<HttpPublisherException> processor = new DefaultHttpResponseProcessor() {
      @Override
      public void processResponse(HttpHelper.HttpResponse response) throws HttpPublisherException, IOException {

        super.processResponse(response);

        final String json = response.getContent();
        if (null == json) {
          throw new HttpPublisherException("Stash publisher has received no response");
        }
        BitbucketCloudRepoInfo repoInfo = myGson.fromJson(json, BitbucketCloudRepoInfo.class);
        if (null == repoInfo)
          throw new HttpPublisherException("Bitbucket Cloud publisher has received a malformed response");
        if (null == repoInfo.slug || !repoInfo.slug.equals(repoName)) {
          throw new HttpPublisherException("No repository found");
        }
      }
    };

    final Map<String, String> headers = new HashMap<>();
    headers.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);

    final HttpCredentials credentials = getCredentials(buildTypeOrTemplate.getProject(), root, params);

    try {
      IOGuard.allowNetworkCall(() -> {
        HttpHelper.get(url,
                       credentials,
                       headers,
                       BaseCommitStatusPublisher.DEFAULT_CONNECTION_TIMEOUT,
                       trustStore(),
                       processor);
      });
    } catch (Exception ex) {
      throw new PublisherException(String.format("Bitbucket Cloud publisher has failed to connect to \"%s\" repository", repository.url()), ex);
    }
  }