{"action":"created","comment":{"url":"https://api.github.com/repos/octokit/octokit.rb/pulls/comments/48183136","id":48183136,"diff_hunk":"@@ -75,11 +75,32 @@ def punch_card_stats(repo, options = {})\n       #\n       # @param repo [Integer, String, Hash, Repository] A GitHub repository\n       # @param metric [String] The metrics you are looking for\n-      # @return [Array<Sawyer::Resource>] Magical unicorn stats\n+      # @return [Array<Sawyer::Resource> or nil] Stats in metric-specific format, or nil if not yet calculated.\n+      # @see https://developer.github.com/v3/repos/statistics/\n       def get_stats(repo, metric, options = {})\n-        data = get(\"#{Repository.path repo}/stats/#{metric}\", options)\n+        path = \"#{Repository.path repo}/stats/#{metric}\"\n+        if retry_timeout = options.delete(:retry_timeout)\n+          get_stats_with_retry(retry_timeout, path, options)\n+        else\n+          get(path, options)\n+        end.tap do\n+          return nil if last_response.status == 202\n+        end\n+      end\n+\n+      # @private Get stats for a repository. Retry call until stats are ready or retry_timeout exceeded.\n+      #\n+      # @param retry_timeout [String] For how long Octokit should keep trying to get stats (in milliseconds)\n+      # @return [Array<Sawyer::Resource> or nil] Stats in metric-specific format, or nil if not yet calculated.\n+      def get_stats_with_retry(retry_timeout, path, options = {})","path":"lib/octokit/client/stats.rb","position":23,"original_position":23,"commit_id":"4fea0cafd2771f4bcd36d74c9f22f0dfcad7162e","original_commit_id":"4fea0cafd2771f4bcd36d74c9f22f0dfcad7162e","user":{"login":"pengwynn","id":865,"avatar_url":"https://avatars.githubusercontent.com/u/865?v=3","gravatar_id":"","url":"https://api.github.com/users/pengwynn","html_url":"https://github.com/pengwynn","followers_url":"https://api.github.com/users/pengwynn/followers","following_url":"https://api.github.com/users/pengwynn/following{/other_user}","gists_url":"https://api.github.com/users/pengwynn/gists{/gist_id}","starred_url":"https://api.github.com/users/pengwynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pengwynn/subscriptions","organizations_url":"https://api.github.com/users/pengwynn/orgs","repos_url":"https://api.github.com/users/pengwynn/repos","events_url":"https://api.github.com/users/pengwynn/events{/privacy}","received_events_url":"https://api.github.com/users/pengwynn/received_events","type":"User","site_admin":true},"body":"I'm fine with leaving this here until we prove the concept, but this is generic enough we could perhaps move to `Client` as `Client#get_with_retry`.","created_at":"2015-12-21T19:48:12Z","updated_at":"2015-12-21T19:48:12Z","html_url":"https://github.com/octokit/octokit.rb/pull/687#discussion_r48183136","pull_request_url":"https://api.github.com/repos/octokit/octokit.rb/pulls/687","_links":{"self":{"href":"https://api.github.com/repos/octokit/octokit.rb/pulls/comments/48183136"},"html":{"href":"https://github.com/octokit/octokit.rb/pull/687#discussion_r48183136"},"pull_request":{"href":"https://api.github.com/repos/octokit/octokit.rb/pulls/687"}}},"pull_request":{"url":"https://api.github.com/repos/octokit/octokit.rb/pulls/687","id":54177312,"html_url":"https://github.com/octokit/octokit.rb/pull/687","diff_url":"https://github.com/octokit/octokit.rb/pull/687.diff","patch_url":"https://github.com/octokit/octokit.rb/pull/687.patch","issue_url":"https://api.github.com/repos/octokit/octokit.rb/issues/687","number":687,"state":"open","locked":false,"title":"Fetch stats via retry and timeout","user":{"login":"kv109","id":399968,"avatar_url":"https://avatars.githubusercontent.com/u/399968?v=3","gravatar_id":"","url":"https://api.github.com/users/kv109","html_url":"https://github.com/kv109","followers_url":"https://api.github.com/users/kv109/followers","following_url":"https://api.github.com/users/kv109/following{/other_user}","gists_url":"https://api.github.com/users/kv109/gists{/gist_id}","starred_url":"https://api.github.com/users/kv109/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kv109/subscriptions","organizations_url":"https://api.github.com/users/kv109/orgs","repos_url":"https://api.github.com/users/kv109/repos","events_url":"https://api.github.com/users/kv109/events{/privacy}","received_events_url":"https://api.github.com/users/kv109/received_events","type":"User","site_admin":false},"body":"Github API [statistics](https://developer.github.com/v3/repos/statistics/) call returns `202` if they are not calculated yet. This PR adds the ability to automatically retry fetching those stats.","created_at":"2015-12-19T11:55:11Z","updated_at":"2015-12-21T19:48:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8c142a0ac8500ce693b2a003772df8d67fe282ea","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/octokit/octokit.rb/pulls/687/commits","review_comments_url":"https://api.github.com/repos/octokit/octokit.rb/pulls/687/comments","review_comment_url":"https://api.github.com/repos/octokit/octokit.rb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/octokit/octokit.rb/issues/687/comments","statuses_url":"https://api.github.com/repos/octokit/octokit.rb/statuses/4fea0cafd2771f4bcd36d74c9f22f0dfcad7162e","head":{"label":"kv109:stats-timeout","ref":"stats-timeout","sha":"4fea0cafd2771f4bcd36d74c9f22f0dfcad7162e","user":{"login":"kv109","id":399968,"avatar_url":"https://avatars.githubusercontent.com/u/399968?v=3","gravatar_id":"","url":"https://api.github.com/users/kv109","html_url":"https://github.com/kv109","followers_url":"https://api.github.com/users/kv109/followers","following_url":"https://api.github.com/users/kv109/following{/other_user}","gists_url":"https://api.github.com/users/kv109/gists{/gist_id}","starred_url":"https://api.github.com/users/kv109/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kv109/subscriptions","organizations_url":"https://api.github.com/users/kv109/orgs","repos_url":"https://api.github.com/users/kv109/repos","events_url":"https://api.github.com/users/kv109/events{/privacy}","received_events_url":"https://api.github.com/users/kv109/received_events","type":"User","site_admin":false},"repo":{"id":48259404,"name":"octokit.rb","full_name":"kv109/octokit.rb","owner":{"login":"kv109","id":399968,"avatar_url":"https://avatars.githubusercontent.com/u/399968?v=3","gravatar_id":"","url":"https://api.github.com/users/kv109","html_url":"https://github.com/kv109","followers_url":"https://api.github.com/users/kv109/followers","following_url":"https://api.github.com/users/kv109/following{/other_user}","gists_url":"https://api.github.com/users/kv109/gists{/gist_id}","starred_url":"https://api.github.com/users/kv109/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kv109/subscriptions","organizations_url":"https://api.github.com/users/kv109/orgs","repos_url":"https://api.github.com/users/kv109/repos","events_url":"https://api.github.com/users/kv109/events{/privacy}","received_events_url":"https://api.github.com/users/kv109/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kv109/octokit.rb","description":"Ruby toolkit for the GitHub API","fork":true,"url":"https://api.github.com/repos/kv109/octokit.rb","forks_url":"https://api.github.com/repos/kv109/octokit.rb/forks","keys_url":"https://api.github.com/repos/kv109/octokit.rb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kv109/octokit.rb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kv109/octokit.rb/teams","hooks_url":"https://api.github.com/repos/kv109/octokit.rb/hooks","issue_events_url":"https://api.github.com/repos/kv109/octokit.rb/issues/events{/number}","events_url":"https://api.github.com/repos/kv109/octokit.rb/events","assignees_url":"https://api.github.com/repos/kv109/octokit.rb/assignees{/user}","branches_url":"https://api.github.com/repos/kv109/octokit.rb/branches{/branch}","tags_url":"https://api.github.com/repos/kv109/octokit.rb/tags","blobs_url":"https://api.github.com/repos/kv109/octokit.rb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kv109/octokit.rb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kv109/octokit.rb/git/refs{/sha}","trees_url":"https://api.github.com/repos/kv109/octokit.rb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kv109/octokit.rb/statuses/{sha}","languages_url":"https://api.github.com/repos/kv109/octokit.rb/languages","stargazers_url":"https://api.github.com/repos/kv109/octokit.rb/stargazers","contributors_url":"https://api.github.com/repos/kv109/octokit.rb/contributors","subscribers_url":"https://api.github.com/repos/kv109/octokit.rb/subscribers","subscription_url":"https://api.github.com/repos/kv109/octokit.rb/subscription","commits_url":"https://api.github.com/repos/kv109/octokit.rb/commits{/sha}","git_commits_url":"https://api.github.com/repos/kv109/octokit.rb/git/commits{/sha}","comments_url":"https://api.github.com/repos/kv109/octokit.rb/comments{/number}","issue_comment_url":"https://api.github.com/repos/kv109/octokit.rb/issues/comments{/number}","contents_url":"https://api.github.com/repos/kv109/octokit.rb/contents/{+path}","compare_url":"https://api.github.com/repos/kv109/octokit.rb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kv109/octokit.rb/merges","archive_url":"https://api.github.com/repos/kv109/octokit.rb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kv109/octokit.rb/downloads","issues_url":"https://api.github.com/repos/kv109/octokit.rb/issues{/number}","pulls_url":"https://api.github.com/repos/kv109/octokit.rb/pulls{/number}","milestones_url":"https://api.github.com/repos/kv109/octokit.rb/milestones{/number}","notifications_url":"https://api.github.com/repos/kv109/octokit.rb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kv109/octokit.rb/labels{/name}","releases_url":"https://api.github.com/repos/kv109/octokit.rb/releases{/id}","created_at":"2015-12-18T22:31:04Z","updated_at":"2015-12-18T22:31:09Z","pushed_at":"2015-12-21T18:06:59Z","git_url":"git://github.com/kv109/octokit.rb.git","ssh_url":"git@github.com:kv109/octokit.rb.git","clone_url":"https://github.com/kv109/octokit.rb.git","svn_url":"https://github.com/kv109/octokit.rb","homepage":"http://octokit.github.io/octokit.rb/","size":12205,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"octokit:master","ref":"master","sha":"1942dc1de0a9a3991ff66e7acbc5b22efdc5a678","user":{"login":"octokit","id":3430433,"avatar_url":"https://avatars.githubusercontent.com/u/3430433?v=3","gravatar_id":"","url":"https://api.github.com/users/octokit","html_url":"https://github.com/octokit","followers_url":"https://api.github.com/users/octokit/followers","following_url":"https://api.github.com/users/octokit/following{/other_user}","gists_url":"https://api.github.com/users/octokit/gists{/gist_id}","starred_url":"https://api.github.com/users/octokit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octokit/subscriptions","organizations_url":"https://api.github.com/users/octokit/orgs","repos_url":"https://api.github.com/users/octokit/repos","events_url":"https://api.github.com/users/octokit/events{/privacy}","received_events_url":"https://api.github.com/users/octokit/received_events","type":"Organization","site_admin":false},"repo":{"id":417862,"name":"octokit.rb","full_name":"octokit/octokit.rb","owner":{"login":"octokit","id":3430433,"avatar_url":"https://avatars.githubusercontent.com/u/3430433?v=3","gravatar_id":"","url":"https://api.github.com/users/octokit","html_url":"https://github.com/octokit","followers_url":"https://api.github.com/users/octokit/followers","following_url":"https://api.github.com/users/octokit/following{/other_user}","gists_url":"https://api.github.com/users/octokit/gists{/gist_id}","starred_url":"https://api.github.com/users/octokit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octokit/subscriptions","organizations_url":"https://api.github.com/users/octokit/orgs","repos_url":"https://api.github.com/users/octokit/repos","events_url":"https://api.github.com/users/octokit/events{/privacy}","received_events_url":"https://api.github.com/users/octokit/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/octokit/octokit.rb","description":"Ruby toolkit for the GitHub API","fork":false,"url":"https://api.github.com/repos/octokit/octokit.rb","forks_url":"https://api.github.com/repos/octokit/octokit.rb/forks","keys_url":"https://api.github.com/repos/octokit/octokit.rb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octokit/octokit.rb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octokit/octokit.rb/teams","hooks_url":"https://api.github.com/repos/octokit/octokit.rb/hooks","issue_events_url":"https://api.github.com/repos/octokit/octokit.rb/issues/events{/number}","events_url":"https://api.github.com/repos/octokit/octokit.rb/events","assignees_url":"https://api.github.com/repos/octokit/octokit.rb/assignees{/user}","branches_url":"https://api.github.com/repos/octokit/octokit.rb/branches{/branch}","tags_url":"https://api.github.com/repos/octokit/octokit.rb/tags","blobs_url":"https://api.github.com/repos/octokit/octokit.rb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octokit/octokit.rb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octokit/octokit.rb/git/refs{/sha}","trees_url":"https://api.github.com/repos/octokit/octokit.rb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octokit/octokit.rb/statuses/{sha}","languages_url":"https://api.github.com/repos/octokit/octokit.rb/languages","stargazers_url":"https://api.github.com/repos/octokit/octokit.rb/stargazers","contributors_url":"https://api.github.com/repos/octokit/octokit.rb/contributors","subscribers_url":"https://api.github.com/repos/octokit/octokit.rb/subscribers","subscription_url":"https://api.github.com/repos/octokit/octokit.rb/subscription","commits_url":"https://api.github.com/repos/octokit/octokit.rb/commits{/sha}","git_commits_url":"https://api.github.com/repos/octokit/octokit.rb/git/commits{/sha}","comments_url":"https://api.github.com/repos/octokit/octokit.rb/comments{/number}","issue_comment_url":"https://api.github.com/repos/octokit/octokit.rb/issues/comments{/number}","contents_url":"https://api.github.com/repos/octokit/octokit.rb/contents/{+path}","compare_url":"https://api.github.com/repos/octokit/octokit.rb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octokit/octokit.rb/merges","archive_url":"https://api.github.com/repos/octokit/octokit.rb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octokit/octokit.rb/downloads","issues_url":"https://api.github.com/repos/octokit/octokit.rb/issues{/number}","pulls_url":"https://api.github.com/repos/octokit/octokit.rb/pulls{/number}","milestones_url":"https://api.github.com/repos/octokit/octokit.rb/milestones{/number}","notifications_url":"https://api.github.com/repos/octokit/octokit.rb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octokit/octokit.rb/labels{/name}","releases_url":"https://api.github.com/repos/octokit/octokit.rb/releases{/id}","created_at":"2009-12-10T21:41:49Z","updated_at":"2015-12-19T21:54:08Z","pushed_at":"2015-12-21T18:07:00Z","git_url":"git://github.com/octokit/octokit.rb.git","ssh_url":"git@github.com:octokit/octokit.rb.git","clone_url":"https://github.com/octokit/octokit.rb.git","svn_url":"https://github.com/octokit/octokit.rb","homepage":"http://octokit.github.io/octokit.rb/","size":14591,"stargazers_count":2112,"watchers_count":2112,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":513,"mirror_url":null,"open_issues_count":15,"forks":513,"open_issues":15,"watchers":2112,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/octokit/octokit.rb/pulls/687"},"html":{"href":"https://github.com/octokit/octokit.rb/pull/687"},"issue":{"href":"https://api.github.com/repos/octokit/octokit.rb/issues/687"},"comments":{"href":"https://api.github.com/repos/octokit/octokit.rb/issues/687/comments"},"review_comments":{"href":"https://api.github.com/repos/octokit/octokit.rb/pulls/687/comments"},"review_comment":{"href":"https://api.github.com/repos/octokit/octokit.rb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/octokit/octokit.rb/pulls/687/commits"},"statuses":{"href":"https://api.github.com/repos/octokit/octokit.rb/statuses/4fea0cafd2771f4bcd36d74c9f22f0dfcad7162e"}}}}