private List getContributorsForRepository()

in src/main/java/org/apache/tomee/website/contributors/Github.java [84:129]


    private List<Contributor> getContributorsForRepository(final URI repositoryUri) {
        final Response response = client.target(repositoryUri.toASCIIString())
                .path("graphs/contributors-data")
                .request()
                .header("referer", repositoryUri.toASCIIString() + "/graphs/contributors")
                .header("authority", "github.com")
                .header("pragma", "no-cache")
                .header("cache-control", "no-cache")
                .header("sec-ch-ua", "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"")
                .header("accept", "application/json")
                .header("sec-ch-ua-mobile", "?0")
                .header("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
                .header("sec-fetch-site", "same-origin")
                .header("sec-fetch-mode", "cors")
                .header("sec-fetch-dest", "empty")
                .header("accept-language", "en-US,en;q=0.9,es;q=0.8")
                .get();

        if (response.getStatus() != 200) {
            log.severe("Unexpected status from " + repositoryUri + ": " + response.getStatus());
            return Collections.EMPTY_LIST;
        }

        if (!response.getHeaderString("content-type").startsWith("application/json")) {
            log.severe("Unexpected content-type from " + repositoryUri + ": " + response.getHeaderString("content-type"));
            return Collections.EMPTY_LIST;
        }
        
        final String json;
        try {
            json = IO.slurp((InputStream) response.getEntity());
        } catch (IOException e) {
            throw new UncheckedIOException("Unable to read response from " + repositoryUri, e);
        }
        
        final ContributorData[] data;
        try {
            final Jsonb jsonb = JsonbBuilder.create();
            data = jsonb.fromJson(json, ContributorData[].class);
        } catch (final Exception e) {
            throw new IllegalStateException("Unable to unmarshal response from " + repositoryUri + "\n\n" + json, e);
        }
        return Stream.of(data)
                .map(ContributorData::asContributor)
                .collect(Collectors.toList());
    }