private CompletableFuture generateInstallationToken()

in src/main/java/com/spotify/github/v3/clients/GitHubClient.java [1062:1100]


  private CompletableFuture<AccessToken> generateInstallationToken(
      final String jwtToken, final int installationId) {
    log.info("Got JWT Token. Now getting GitHub access_token for installation {}", installationId);
    final String url = String.format(urlFor(GET_ACCESS_TOKEN_URL), installationId);
    final HttpRequest request =
        ImmutableHttpRequest.builder()
            .url(url)
            .putHeaders("Accept", List.of("application/vnd.github.machine-man-preview+json"))
            .putHeaders("Authorization", List.of("Bearer " + jwtToken))
            .method("POST")
            .body("")
            .build();

    return this.client
        .send(request)
        .thenApply(
            response -> {
              if (!response.isSuccessful()) {
                throw new RuntimeException(
                    String.format(
                        "Got non-2xx status %s when getting an access token from GitHub: %s",
                        response.statusCode(), response.statusMessage()));
              }

              if (response.bodyString() == null) {
                throw new RuntimeException(
                    String.format(
                        "Got empty response body when getting an access token from GitHub, HTTP status was: %s",
                        response.statusMessage()));
              }
              final String text = response.bodyString();
              try {
                return Json.create().fromJson(text, AccessToken.class);
              } catch (IOException e) {
                throw new RuntimeException(e);
              }
            })
        .toCompletableFuture();
  }