github-api icon indicating copy to clipboard operation
github-api copied to clipboard

Issue with GHRepositoryStatistics.getContibutorStats(true)

Open goldbal330 opened this issue 2 years ago • 0 comments

https://github.com/hub4j/github-api/blob/4bba9680706785d6385ed69243f41a5f36757463/src/main/java/org/kohsuke/github/GHRepositoryStatistics.java#L67

This method will never invoke Thread.sleep if the data is not ready.

if (stats == null && waitTillReady) {
           for (int i = 0; i < MAX_WAIT_ITERATIONS; i += 1) {
               // Wait a few seconds and try again.
               Thread.sleep(WAIT_SLEEP_INTERVAL);
               stats = getContributorStatsImpl();
               if (stats != null) {
                   break;
               }
           }
       }

stats = getContributorStatsImpl() will never return null.

https://github.com/hub4j/github-api/blob/4bba9680706785d6385ed69243f41a5f36757463/src/main/java/org/kohsuke/github/Requester.java#L169

will always create a new instance of GitHubPageContentsIterable. Hence, if the data is still being cached by the server, the blocking will never happen and empty result will be returned back.

Expected behavior Based on GitHub API documentation: https://docs.github.com/en/rest/metrics/statistics#a-word-about-caching code 202 is returned back when the statistics data is not ready. Ideally status code of 202 returned by the REST call would be driving sleep and retry in GHRepositoryStatistics class. If the data is not ready, the method would block till the data is ready and return then.

goldbal330 avatar Oct 03 '22 21:10 goldbal330