{"action":"created","comment":{"url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments/58322094","id":58322094,"diff_hunk":"@@ -0,0 +1,69 @@\n+package util;\n+\n+import ui.UI;\n+\n+/**\n+ * This class is used to hold the TickingTimer instance and perform operations associated with it.\n+ */\n+public class TickingTimerManager {\n+\n+\n+    public static final int BUFFER_TIME = 1; //To allow some additional time until next refresh.\n+    private final TickingTimer timer;\n+    public static final int REFRESH_PERIOD = 60;\n+    public static final int APIQUOTA_BUFFER = 200;\n+\n+    public TickingTimerManager(TickingTimer timer) {\n+        this.timer = timer;\n+    }\n+\n+    public void startTimer() {\n+        timer.start();\n+    }\n+\n+    public void restartTimer() {\n+        timer.restart();\n+    }\n+\n+\n+    /* This function updates the TickerTimer period, which is used to periodically refresh the issues.\n+        * @param apiQuota : The remaining allowed api request until the next api request allowance renewal.\n+        * @param remainingTime : The remaining time left until the next api request allowance renewal.\n+        * @param lastApiCallsUsed : The amount of api used in the last api pull.\n+    */\n+    public int updateTickerTimer(int apiQuota, long remainingTime, int lastApiCallsUsed) {\n+\n+        assert apiQuota >= 0 && remainingTime >= 0 && lastApiCallsUsed >= 0;\n+\n+        long refreshTimeInMins;\n+\n+        if (lastApiCallsUsed > 0) {\n+            // If less or equal than APIQUOTA_BUFFER, restricts auto refresh until next apiQuota renewal.\n+            // The APIQUOTA_BUFFER is reserved for Manual refresh and creation of issues, etc.\n+            if (apiQuota <= APIQUOTA_BUFFER) {\n+                refreshTimeInMins = remainingTime + BUFFER_TIME;\n+            } else {\n+                if (apiQuota - APIQUOTA_BUFFER >= lastApiCallsUsed) {\n+                    refreshTimeInMins = (long) Math.ceil(remainingTime /\n+                            Math.floor((apiQuota - APIQUOTA_BUFFER) / (double) lastApiCallsUsed));\n+                } else {\n+                    // Restricts auto refresh until next apiQuota renewal.\n+                    refreshTimeInMins = remainingTime + BUFFER_TIME;\n+                }\n+            }\n+        } else { // Enters here during application initialisation or when apiQuota = 0 and lastApiCallsUsed = 0\n+            if (apiQuota != 0) {\n+                // Set to default during initialisation\n+                refreshTimeInMins = Utility.secsToMins(REFRESH_PERIOD);\n+            } else {\n+                // Restricts auto refresh until next apiQuota renewal.\n+                refreshTimeInMins = remainingTime + BUFFER_TIME;\n+            }\n+\n+        }","path":"src/main/java/util/TickingTimerManager.java","position":63,"original_position":63,"commit_id":"80f515ddd9902bb557e350a9022ab27e5ec25158","original_commit_id":"80f515ddd9902bb557e350a9022ab27e5ec25158","user":{"login":"damithc","id":1673303,"avatar_url":"https://avatars.githubusercontent.com/u/1673303?v=3","gravatar_id":"","url":"https://api.github.com/users/damithc","html_url":"https://github.com/damithc","followers_url":"https://api.github.com/users/damithc/followers","following_url":"https://api.github.com/users/damithc/following{/other_user}","gists_url":"https://api.github.com/users/damithc/gists{/gist_id}","starred_url":"https://api.github.com/users/damithc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damithc/subscriptions","organizations_url":"https://api.github.com/users/damithc/orgs","repos_url":"https://api.github.com/users/damithc/repos","events_url":"https://api.github.com/users/damithc/events{/privacy}","received_events_url":"https://api.github.com/users/damithc/received_events","type":"User","site_admin":false},"body":"To reduce nesting, handle unusual case in conditional blocks and use early returns so that the normal flow of the method is not nested.","created_at":"2016-04-04T01:25:16Z","updated_at":"2016-04-04T01:25:16Z","html_url":"https://github.com/HubTurbo/HubTurbo/pull/1376#discussion_r58322094","pull_request_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1376","_links":{"self":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments/58322094"},"html":{"href":"https://github.com/HubTurbo/HubTurbo/pull/1376#discussion_r58322094"},"pull_request":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1376"}}},"pull_request":{"url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1376","id":63437718,"html_url":"https://github.com/HubTurbo/HubTurbo/pull/1376","diff_url":"https://github.com/HubTurbo/HubTurbo/pull/1376.diff","patch_url":"https://github.com/HubTurbo/HubTurbo/pull/1376.patch","issue_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1376","number":1376,"state":"open","locked":false,"title":"Throttle refresh frequency when the API quota runs low #1365","user":{"login":"yl-coder","id":9070608,"avatar_url":"https://avatars.githubusercontent.com/u/9070608?v=3","gravatar_id":"","url":"https://api.github.com/users/yl-coder","html_url":"https://github.com/yl-coder","followers_url":"https://api.github.com/users/yl-coder/followers","following_url":"https://api.github.com/users/yl-coder/following{/other_user}","gists_url":"https://api.github.com/users/yl-coder/gists{/gist_id}","starred_url":"https://api.github.com/users/yl-coder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yl-coder/subscriptions","organizations_url":"https://api.github.com/users/yl-coder/orgs","repos_url":"https://api.github.com/users/yl-coder/repos","events_url":"https://api.github.com/users/yl-coder/events{/privacy}","received_events_url":"https://api.github.com/users/yl-coder/received_events","type":"User","site_admin":false},"body":"Ready for review\r\nFixes #1365 \r\n\r\n![image](https://cloud.githubusercontent.com/assets/9070608/13899229/300b9748-edbf-11e5-909e-24a7b3d7866b.png)\r\n","created_at":"2016-03-18T21:18:13Z","updated_at":"2016-04-04T01:25:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88a04e613ffc141ebb114cd4bb699a03e7a886a9","assignee":{"login":"ndt93","id":5065989,"avatar_url":"https://avatars.githubusercontent.com/u/5065989?v=3","gravatar_id":"","url":"https://api.github.com/users/ndt93","html_url":"https://github.com/ndt93","followers_url":"https://api.github.com/users/ndt93/followers","following_url":"https://api.github.com/users/ndt93/following{/other_user}","gists_url":"https://api.github.com/users/ndt93/gists{/gist_id}","starred_url":"https://api.github.com/users/ndt93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ndt93/subscriptions","organizations_url":"https://api.github.com/users/ndt93/orgs","repos_url":"https://api.github.com/users/ndt93/repos","events_url":"https://api.github.com/users/ndt93/events{/privacy}","received_events_url":"https://api.github.com/users/ndt93/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1376/commits","review_comments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1376/comments","review_comment_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1376/comments","statuses_url":"https://api.github.com/repos/HubTurbo/HubTurbo/statuses/80f515ddd9902bb557e350a9022ab27e5ec25158","head":{"label":"yl-coder:1365-throttle-refresh-freq-based-on-apiquota","ref":"1365-throttle-refresh-freq-based-on-apiquota","sha":"80f515ddd9902bb557e350a9022ab27e5ec25158","user":{"login":"yl-coder","id":9070608,"avatar_url":"https://avatars.githubusercontent.com/u/9070608?v=3","gravatar_id":"","url":"https://api.github.com/users/yl-coder","html_url":"https://github.com/yl-coder","followers_url":"https://api.github.com/users/yl-coder/followers","following_url":"https://api.github.com/users/yl-coder/following{/other_user}","gists_url":"https://api.github.com/users/yl-coder/gists{/gist_id}","starred_url":"https://api.github.com/users/yl-coder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yl-coder/subscriptions","organizations_url":"https://api.github.com/users/yl-coder/orgs","repos_url":"https://api.github.com/users/yl-coder/repos","events_url":"https://api.github.com/users/yl-coder/events{/privacy}","received_events_url":"https://api.github.com/users/yl-coder/received_events","type":"User","site_admin":false},"repo":{"id":53808527,"name":"HubTurbo","full_name":"yl-coder/HubTurbo","owner":{"login":"yl-coder","id":9070608,"avatar_url":"https://avatars.githubusercontent.com/u/9070608?v=3","gravatar_id":"","url":"https://api.github.com/users/yl-coder","html_url":"https://github.com/yl-coder","followers_url":"https://api.github.com/users/yl-coder/followers","following_url":"https://api.github.com/users/yl-coder/following{/other_user}","gists_url":"https://api.github.com/users/yl-coder/gists{/gist_id}","starred_url":"https://api.github.com/users/yl-coder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yl-coder/subscriptions","organizations_url":"https://api.github.com/users/yl-coder/orgs","repos_url":"https://api.github.com/users/yl-coder/repos","events_url":"https://api.github.com/users/yl-coder/events{/privacy}","received_events_url":"https://api.github.com/users/yl-coder/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yl-coder/HubTurbo","description":"A companion to GitHub for your desktop","fork":true,"url":"https://api.github.com/repos/yl-coder/HubTurbo","forks_url":"https://api.github.com/repos/yl-coder/HubTurbo/forks","keys_url":"https://api.github.com/repos/yl-coder/HubTurbo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yl-coder/HubTurbo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yl-coder/HubTurbo/teams","hooks_url":"https://api.github.com/repos/yl-coder/HubTurbo/hooks","issue_events_url":"https://api.github.com/repos/yl-coder/HubTurbo/issues/events{/number}","events_url":"https://api.github.com/repos/yl-coder/HubTurbo/events","assignees_url":"https://api.github.com/repos/yl-coder/HubTurbo/assignees{/user}","branches_url":"https://api.github.com/repos/yl-coder/HubTurbo/branches{/branch}","tags_url":"https://api.github.com/repos/yl-coder/HubTurbo/tags","blobs_url":"https://api.github.com/repos/yl-coder/HubTurbo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yl-coder/HubTurbo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yl-coder/HubTurbo/git/refs{/sha}","trees_url":"https://api.github.com/repos/yl-coder/HubTurbo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yl-coder/HubTurbo/statuses/{sha}","languages_url":"https://api.github.com/repos/yl-coder/HubTurbo/languages","stargazers_url":"https://api.github.com/repos/yl-coder/HubTurbo/stargazers","contributors_url":"https://api.github.com/repos/yl-coder/HubTurbo/contributors","subscribers_url":"https://api.github.com/repos/yl-coder/HubTurbo/subscribers","subscription_url":"https://api.github.com/repos/yl-coder/HubTurbo/subscription","commits_url":"https://api.github.com/repos/yl-coder/HubTurbo/commits{/sha}","git_commits_url":"https://api.github.com/repos/yl-coder/HubTurbo/git/commits{/sha}","comments_url":"https://api.github.com/repos/yl-coder/HubTurbo/comments{/number}","issue_comment_url":"https://api.github.com/repos/yl-coder/HubTurbo/issues/comments{/number}","contents_url":"https://api.github.com/repos/yl-coder/HubTurbo/contents/{+path}","compare_url":"https://api.github.com/repos/yl-coder/HubTurbo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yl-coder/HubTurbo/merges","archive_url":"https://api.github.com/repos/yl-coder/HubTurbo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yl-coder/HubTurbo/downloads","issues_url":"https://api.github.com/repos/yl-coder/HubTurbo/issues{/number}","pulls_url":"https://api.github.com/repos/yl-coder/HubTurbo/pulls{/number}","milestones_url":"https://api.github.com/repos/yl-coder/HubTurbo/milestones{/number}","notifications_url":"https://api.github.com/repos/yl-coder/HubTurbo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yl-coder/HubTurbo/labels{/name}","releases_url":"https://api.github.com/repos/yl-coder/HubTurbo/releases{/id}","deployments_url":"https://api.github.com/repos/yl-coder/HubTurbo/deployments","created_at":"2016-03-13T21:25:01Z","updated_at":"2016-03-13T21:25:05Z","pushed_at":"2016-04-04T00:53:08Z","git_url":"git://github.com/yl-coder/HubTurbo.git","ssh_url":"git@github.com:yl-coder/HubTurbo.git","clone_url":"https://github.com/yl-coder/HubTurbo.git","svn_url":"https://github.com/yl-coder/HubTurbo","homepage":"http://hubturbo.info","size":135226,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"HubTurbo:master","ref":"master","sha":"37f0b04ad6f03eff5b683805d28f16f3568aeac7","user":{"login":"HubTurbo","id":7955871,"avatar_url":"https://avatars.githubusercontent.com/u/7955871?v=3","gravatar_id":"","url":"https://api.github.com/users/HubTurbo","html_url":"https://github.com/HubTurbo","followers_url":"https://api.github.com/users/HubTurbo/followers","following_url":"https://api.github.com/users/HubTurbo/following{/other_user}","gists_url":"https://api.github.com/users/HubTurbo/gists{/gist_id}","starred_url":"https://api.github.com/users/HubTurbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HubTurbo/subscriptions","organizations_url":"https://api.github.com/users/HubTurbo/orgs","repos_url":"https://api.github.com/users/HubTurbo/repos","events_url":"https://api.github.com/users/HubTurbo/events{/privacy}","received_events_url":"https://api.github.com/users/HubTurbo/received_events","type":"Organization","site_admin":false},"repo":{"id":20919534,"name":"HubTurbo","full_name":"HubTurbo/HubTurbo","owner":{"login":"HubTurbo","id":7955871,"avatar_url":"https://avatars.githubusercontent.com/u/7955871?v=3","gravatar_id":"","url":"https://api.github.com/users/HubTurbo","html_url":"https://github.com/HubTurbo","followers_url":"https://api.github.com/users/HubTurbo/followers","following_url":"https://api.github.com/users/HubTurbo/following{/other_user}","gists_url":"https://api.github.com/users/HubTurbo/gists{/gist_id}","starred_url":"https://api.github.com/users/HubTurbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HubTurbo/subscriptions","organizations_url":"https://api.github.com/users/HubTurbo/orgs","repos_url":"https://api.github.com/users/HubTurbo/repos","events_url":"https://api.github.com/users/HubTurbo/events{/privacy}","received_events_url":"https://api.github.com/users/HubTurbo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HubTurbo/HubTurbo","description":"A companion to GitHub for your desktop","fork":false,"url":"https://api.github.com/repos/HubTurbo/HubTurbo","forks_url":"https://api.github.com/repos/HubTurbo/HubTurbo/forks","keys_url":"https://api.github.com/repos/HubTurbo/HubTurbo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HubTurbo/HubTurbo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HubTurbo/HubTurbo/teams","hooks_url":"https://api.github.com/repos/HubTurbo/HubTurbo/hooks","issue_events_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/events{/number}","events_url":"https://api.github.com/repos/HubTurbo/HubTurbo/events","assignees_url":"https://api.github.com/repos/HubTurbo/HubTurbo/assignees{/user}","branches_url":"https://api.github.com/repos/HubTurbo/HubTurbo/branches{/branch}","tags_url":"https://api.github.com/repos/HubTurbo/HubTurbo/tags","blobs_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/refs{/sha}","trees_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HubTurbo/HubTurbo/statuses/{sha}","languages_url":"https://api.github.com/repos/HubTurbo/HubTurbo/languages","stargazers_url":"https://api.github.com/repos/HubTurbo/HubTurbo/stargazers","contributors_url":"https://api.github.com/repos/HubTurbo/HubTurbo/contributors","subscribers_url":"https://api.github.com/repos/HubTurbo/HubTurbo/subscribers","subscription_url":"https://api.github.com/repos/HubTurbo/HubTurbo/subscription","commits_url":"https://api.github.com/repos/HubTurbo/HubTurbo/commits{/sha}","git_commits_url":"https://api.github.com/repos/HubTurbo/HubTurbo/git/commits{/sha}","comments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/comments{/number}","issue_comment_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/comments{/number}","contents_url":"https://api.github.com/repos/HubTurbo/HubTurbo/contents/{+path}","compare_url":"https://api.github.com/repos/HubTurbo/HubTurbo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HubTurbo/HubTurbo/merges","archive_url":"https://api.github.com/repos/HubTurbo/HubTurbo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HubTurbo/HubTurbo/downloads","issues_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues{/number}","pulls_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls{/number}","milestones_url":"https://api.github.com/repos/HubTurbo/HubTurbo/milestones{/number}","notifications_url":"https://api.github.com/repos/HubTurbo/HubTurbo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HubTurbo/HubTurbo/labels{/name}","releases_url":"https://api.github.com/repos/HubTurbo/HubTurbo/releases{/id}","deployments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/deployments","created_at":"2014-06-17T10:35:39Z","updated_at":"2016-03-24T07:36:39Z","pushed_at":"2016-04-04T00:53:09Z","git_url":"git://github.com/HubTurbo/HubTurbo.git","ssh_url":"git@github.com:HubTurbo/HubTurbo.git","clone_url":"https://github.com/HubTurbo/HubTurbo.git","svn_url":"https://github.com/HubTurbo/HubTurbo","homepage":"http://hubturbo.info","size":136735,"stargazers_count":17,"watchers_count":17,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":190,"forks":36,"open_issues":190,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1376"},"html":{"href":"https://github.com/HubTurbo/HubTurbo/pull/1376"},"issue":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1376"},"comments":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1376/comments"},"review_comments":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1376/comments"},"review_comment":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1376/commits"},"statuses":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/statuses/80f515ddd9902bb557e350a9022ab27e5ec25158"}}}}