{"action":"created","comment":{"url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments/52461865","id":52461865,"diff_hunk":"@@ -136,28 +133,74 @@ public static boolean process(IModel model, FilterExpression expr, TurboIssue is\n         return exprWithNormalQualifiers.isSatisfiedBy(model, issue, new MetaQualifierInfo(metaQualifiers));\n     }\n \n-    private static Optional<Integer> getCurrentMilestoneIndex(List<TurboMilestone> allMilestones) {\n-        if (allMilestones.isEmpty()) {\n-            return Optional.empty();\n+    /**\n+     * Get all milestones that can be aliased with current-[n] to current+[n]\n+     */\n+    private static List<TurboMilestone> getMilestonesWithinAliasRange(List<TurboMilestone> milestonesOfRepos) {\n+        List<TurboMilestone> milestones = new ArrayList<>();\n+        // add milestones with due date first\n+        milestones.addAll(milestonesOfRepos.stream()\n+                .filter(ms -> ms.getDueDate().isPresent())\n+                .collect(Collectors.toList()));\n+\n+        // Special case: if there is only one open milestone, it should be included regardless of whether\n+        // it has due date or not.\n+        // In this case, if it is not included already (the open milestone does not\n+        // have due date), add it to the milestone list.\n+        List<TurboMilestone> openMilestones = TurboMilestone.getOpenMilestones(milestonesOfRepos);\n+        if (openMilestones.size() == 1) {\n+            TurboMilestone openMilestone = openMilestones.get(0);\n+            boolean hasDueDate = openMilestone.getDueDate().isPresent();\n+            if (!hasDueDate) {\n+                milestones.add(openMilestone);\n+            }\n         }\n \n-        int currentIndex = 0;\n+        return milestones;\n+    }\n \n-        for (TurboMilestone checker : allMilestones) {\n-            boolean overdue = checker.getDueDate().isPresent() &&\n-                    checker.getDueDate().get().isBefore(LocalDate.now());\n-            boolean relevant = !(overdue && checker.getOpenIssues() == 0);\n+    /**\n+     * Returns a map where the key denotes offset from \"current\" milestone.\n+     * i.e. 0 for \"current\" milestone, -1 for \"current-1\" milestone, etc.\n+     */\n+    private static Map<Integer, TurboMilestone> getMilestoneAliasIndex(List<TurboMilestone> milestones) {\n+        List<TurboMilestone> sortedMilestones = TurboMilestone.getSortedMilestonesByDueDate(milestones);\n+        Optional<Integer> currentMilestoneIndex = getCurrentMilestoneIndex(sortedMilestones);\n \n-            if (checker.isOpen() && relevant) {\n-                return Optional.of(currentIndex);\n-            }\n+        return IntStream\n+                .range(0, sortedMilestones.size())\n+                .boxed()\n+                .collect(Collectors.toMap(\n+                        i -> i - currentMilestoneIndex.get(),\n+                        i -> sortedMilestones.get(i)));\n+    }\n \n-            currentIndex++;\n+    private static Optional<Integer> getCurrentMilestoneIndex(List<TurboMilestone> milestones) {\n+        if (milestones.isEmpty()) {\n+            return Optional.empty();\n         }\n \n-        // if no open milestone, set current as one after last milestone\n-        // - this means that no such milestone, which will return no issue\n-        return Optional.of(allMilestones.size());\n+        long openMilestonesCount = milestones.stream().filter(TurboMilestone::isOpen).count();\n+        if (openMilestonesCount == 1) {\n+            return IntStream\n+                    .range(0, milestones.size())\n+                    .boxed()\n+                    .filter(i -> milestones.get(i).isOpen())\n+                    .findFirst();\n+        } else {\n+            // Look for the first milestone in the (sorted) list that is both open and ongoing.\n+            int currentIndex = 0;\n+            for (TurboMilestone checker : milestones) {\n+                if (checker.isOpen() && checker.isOngoing()) {","path":"src/main/java/filter/expression/Qualifier.java","position":112,"original_position":112,"commit_id":"9c301acedd773cf3cd741cff830f3bf871663c62","original_commit_id":"9c301acedd773cf3cd741cff830f3bf871663c62","user":{"login":"HansNewbie","id":3381536,"avatar_url":"https://avatars.githubusercontent.com/u/3381536?v=3","gravatar_id":"","url":"https://api.github.com/users/HansNewbie","html_url":"https://github.com/HansNewbie","followers_url":"https://api.github.com/users/HansNewbie/followers","following_url":"https://api.github.com/users/HansNewbie/following{/other_user}","gists_url":"https://api.github.com/users/HansNewbie/gists{/gist_id}","starred_url":"https://api.github.com/users/HansNewbie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HansNewbie/subscriptions","organizations_url":"https://api.github.com/users/HansNewbie/orgs","repos_url":"https://api.github.com/users/HansNewbie/repos","events_url":"https://api.github.com/users/HansNewbie/events{/privacy}","received_events_url":"https://api.github.com/users/HansNewbie/received_events","type":"User","site_admin":false},"body":"From the way it's used, `isOngoing` only refers to open milestones. How about adding `isOpen` as part of `isOngoing` instead? I don't think any closed milestone will be ongoing. We can then `stream` the milestones and `findFirst`.","created_at":"2016-02-10T14:17:55Z","updated_at":"2016-02-10T14:17:55Z","html_url":"https://github.com/HubTurbo/HubTurbo/pull/1226#discussion_r52461865","pull_request_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1226","_links":{"self":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments/52461865"},"html":{"href":"https://github.com/HubTurbo/HubTurbo/pull/1226#discussion_r52461865"},"pull_request":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1226"}}},"pull_request":{"url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1226","id":57764834,"html_url":"https://github.com/HubTurbo/HubTurbo/pull/1226","diff_url":"https://github.com/HubTurbo/HubTurbo/pull/1226.diff","patch_url":"https://github.com/HubTurbo/HubTurbo/pull/1226.patch","issue_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1226","number":1226,"state":"open","locked":false,"title":"If there is only one open milestone, consider it as the current milestone #1147","user":{"login":"raisfathin","id":9299240,"avatar_url":"https://avatars.githubusercontent.com/u/9299240?v=3","gravatar_id":"","url":"https://api.github.com/users/raisfathin","html_url":"https://github.com/raisfathin","followers_url":"https://api.github.com/users/raisfathin/followers","following_url":"https://api.github.com/users/raisfathin/following{/other_user}","gists_url":"https://api.github.com/users/raisfathin/gists{/gist_id}","starred_url":"https://api.github.com/users/raisfathin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raisfathin/subscriptions","organizations_url":"https://api.github.com/users/raisfathin/orgs","repos_url":"https://api.github.com/users/raisfathin/repos","events_url":"https://api.github.com/users/raisfathin/events{/privacy}","received_events_url":"https://api.github.com/users/raisfathin/received_events","type":"User","site_admin":false},"body":"Fixes #1147 \r\n","created_at":"2016-01-31T10:03:12Z","updated_at":"2016-02-10T14:17:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c58a198109fc1613508b3000021a3f3ec0fa4d91","assignee":{"login":"HansNewbie","id":3381536,"avatar_url":"https://avatars.githubusercontent.com/u/3381536?v=3","gravatar_id":"","url":"https://api.github.com/users/HansNewbie","html_url":"https://github.com/HansNewbie","followers_url":"https://api.github.com/users/HansNewbie/followers","following_url":"https://api.github.com/users/HansNewbie/following{/other_user}","gists_url":"https://api.github.com/users/HansNewbie/gists{/gist_id}","starred_url":"https://api.github.com/users/HansNewbie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HansNewbie/subscriptions","organizations_url":"https://api.github.com/users/HansNewbie/orgs","repos_url":"https://api.github.com/users/HansNewbie/repos","events_url":"https://api.github.com/users/HansNewbie/events{/privacy}","received_events_url":"https://api.github.com/users/HansNewbie/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1226/commits","review_comments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1226/comments","review_comment_url":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1226/comments","statuses_url":"https://api.github.com/repos/HubTurbo/HubTurbo/statuses/9c301acedd773cf3cd741cff830f3bf871663c62","head":{"label":"raisfathin:1147-consider-open-milestone-as-curr","ref":"1147-consider-open-milestone-as-curr","sha":"9c301acedd773cf3cd741cff830f3bf871663c62","user":{"login":"raisfathin","id":9299240,"avatar_url":"https://avatars.githubusercontent.com/u/9299240?v=3","gravatar_id":"","url":"https://api.github.com/users/raisfathin","html_url":"https://github.com/raisfathin","followers_url":"https://api.github.com/users/raisfathin/followers","following_url":"https://api.github.com/users/raisfathin/following{/other_user}","gists_url":"https://api.github.com/users/raisfathin/gists{/gist_id}","starred_url":"https://api.github.com/users/raisfathin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raisfathin/subscriptions","organizations_url":"https://api.github.com/users/raisfathin/orgs","repos_url":"https://api.github.com/users/raisfathin/repos","events_url":"https://api.github.com/users/raisfathin/events{/privacy}","received_events_url":"https://api.github.com/users/raisfathin/received_events","type":"User","site_admin":false},"repo":{"id":49590110,"name":"HubTurbo","full_name":"raisfathin/HubTurbo","owner":{"login":"raisfathin","id":9299240,"avatar_url":"https://avatars.githubusercontent.com/u/9299240?v=3","gravatar_id":"","url":"https://api.github.com/users/raisfathin","html_url":"https://github.com/raisfathin","followers_url":"https://api.github.com/users/raisfathin/followers","following_url":"https://api.github.com/users/raisfathin/following{/other_user}","gists_url":"https://api.github.com/users/raisfathin/gists{/gist_id}","starred_url":"https://api.github.com/users/raisfathin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raisfathin/subscriptions","organizations_url":"https://api.github.com/users/raisfathin/orgs","repos_url":"https://api.github.com/users/raisfathin/repos","events_url":"https://api.github.com/users/raisfathin/events{/privacy}","received_events_url":"https://api.github.com/users/raisfathin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/raisfathin/HubTurbo","description":"A companion to GitHub for your desktop","fork":true,"url":"https://api.github.com/repos/raisfathin/HubTurbo","forks_url":"https://api.github.com/repos/raisfathin/HubTurbo/forks","keys_url":"https://api.github.com/repos/raisfathin/HubTurbo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/raisfathin/HubTurbo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/raisfathin/HubTurbo/teams","hooks_url":"https://api.github.com/repos/raisfathin/HubTurbo/hooks","issue_events_url":"https://api.github.com/repos/raisfathin/HubTurbo/issues/events{/number}","events_url":"https://api.github.com/repos/raisfathin/HubTurbo/events","assignees_url":"https://api.github.com/repos/raisfathin/HubTurbo/assignees{/user}","branches_url":"https://api.github.com/repos/raisfathin/HubTurbo/branches{/branch}","tags_url":"https://api.github.com/repos/raisfathin/HubTurbo/tags","blobs_url":"https://api.github.com/repos/raisfathin/HubTurbo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/raisfathin/HubTurbo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/raisfathin/HubTurbo/git/refs{/sha}","trees_url":"https://api.github.com/repos/raisfathin/HubTurbo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/raisfathin/HubTurbo/statuses/{sha}","languages_url":"https://api.github.com/repos/raisfathin/HubTurbo/languages","stargazers_url":"https://api.github.com/repos/raisfathin/HubTurbo/stargazers","contributors_url":"https://api.github.com/repos/raisfathin/HubTurbo/contributors","subscribers_url":"https://api.github.com/repos/raisfathin/HubTurbo/subscribers","subscription_url":"https://api.github.com/repos/raisfathin/HubTurbo/subscription","commits_url":"https://api.github.com/repos/raisfathin/HubTurbo/commits{/sha}","git_commits_url":"https://api.github.com/repos/raisfathin/HubTurbo/git/commits{/sha}","comments_url":"https://api.github.com/repos/raisfathin/HubTurbo/comments{/number}","issue_comment_url":"https://api.github.com/repos/raisfathin/HubTurbo/issues/comments{/number}","contents_url":"https://api.github.com/repos/raisfathin/HubTurbo/contents/{+path}","compare_url":"https://api.github.com/repos/raisfathin/HubTurbo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/raisfathin/HubTurbo/merges","archive_url":"https://api.github.com/repos/raisfathin/HubTurbo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/raisfathin/HubTurbo/downloads","issues_url":"https://api.github.com/repos/raisfathin/HubTurbo/issues{/number}","pulls_url":"https://api.github.com/repos/raisfathin/HubTurbo/pulls{/number}","milestones_url":"https://api.github.com/repos/raisfathin/HubTurbo/milestones{/number}","notifications_url":"https://api.github.com/repos/raisfathin/HubTurbo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/raisfathin/HubTurbo/labels{/name}","releases_url":"https://api.github.com/repos/raisfathin/HubTurbo/releases{/id}","deployments_url":"https://api.github.com/repos/raisfathin/HubTurbo/deployments","created_at":"2016-01-13T17:32:35Z","updated_at":"2016-01-13T17:32:38Z","pushed_at":"2016-02-08T13:14:05Z","git_url":"git://github.com/raisfathin/HubTurbo.git","ssh_url":"git@github.com:raisfathin/HubTurbo.git","clone_url":"https://github.com/raisfathin/HubTurbo.git","svn_url":"https://github.com/raisfathin/HubTurbo","homepage":"http://hubturbo.info","size":132676,"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":"2a4bf730b15d626a39cb7dde88fa33500b445746","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-01-13T06:03:59Z","pushed_at":"2016-02-10T11:29:56Z","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":133011,"stargazers_count":15,"watchers_count":15,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":25,"mirror_url":null,"open_issues_count":154,"forks":25,"open_issues":154,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1226"},"html":{"href":"https://github.com/HubTurbo/HubTurbo/pull/1226"},"issue":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1226"},"comments":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/issues/1226/comments"},"review_comments":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1226/comments"},"review_comment":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/pulls/1226/commits"},"statuses":{"href":"https://api.github.com/repos/HubTurbo/HubTurbo/statuses/9c301acedd773cf3cd741cff830f3bf871663c62"}}}}