Repository: chaoss/augur
Issue: `pull_request_closed_no_merge` metric is broken

**Describe the bug:**
The `pull_request_closed_no_merge` metric returns a 500 internal server error.

**To Reproduce:**
Steps to reproduce the behavior:
1. Checkout `dev`
2. Run `augur run --disable-housekeeper`
3. Hit `http://localhost:5000/api/unstable/repo/21000/pull-request-closed-no-merge`
4. Observe error

**Expected behavior:**
I expected the metric to return a valid response object, even if it was empty.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
 - OS: macOS v 10.14.6

**Additional context**
I noticed that there is a missing `GROUP_BY` clause in the SQL query, based on the usage of `COUNT`. This appears to be the main culprit of the issue.

Broken Travis build: https://travis-ci.org/chaoss/augur/builds/657396384


Changed files:
test/api/test_pull_request_routes.py, test/metrics/test_pull_request_metrics.py, augur/metrics/pull_request/routes.py, augur/metrics/pull_request/pull_request.py

diff --git a/augur/metrics/pull_request/pull_request.py b/augur/metrics/pull_request/pull_request.py
index 39f039950..bdb0be7fa 100644
--- a/augur/metrics/pull_request/pull_request.py
+++ b/augur/metrics/pull_request/pull_request.py
@@ -78,9 +78,13 @@ def pull_requests_closed_no_merge(self, repo_group_id, repo_id=None, period='day
     if repo_id:
         closedNoMerge = s.sql.text("""
             SELECT DATE_TRUNC(:period, pull_requests.pr_closed_at) AS closed_date,
-            COUNT(pull_request_id)
-            FROM pull_requests WHERE repo_id = :repo_id and pull_requests.pr_closed_at is NOT NULL and
+            COUNT(pull_request_id) as pr_count
+            FROM pull_requests JOIN repo ON pull_requests.repo_id = repo.repo_id
+            WHERE pull_requests.repo_id = :repo_id
+            AND pull_requests.pr_closed_at is NOT NULL AND
             pull_requests.pr_merged_at is NULL
+            GROUP BY closed_date, pull_request_id
+            ORDER BY closed_date
         """)
         results = pd.read_sql(closedNoMerge, self.database, params={'repo_id': repo_id, 'period': period,
                                                                      'begin_date': begin_date,
@@ -89,9 +93,11 @@ def pull_requests_closed_no_merge(self, repo_group_id, repo_id=None, period='day
     else:
         closedNoMerge = s.sql.text("""
             SELECT DATE_TRUNC(:period, pull_requests.pr_closed_at) AS closed_date,
-            COUNT(pull_request_id)
-            FROM pull_requests WHERE repo_id in (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
+            COUNT(pull_request_id) as pr_count
+            FROM pull_requests JOIN repo ON pull_requests.repo_id = repo.repo_id WHERE pull_requests.repo_id in (SELECT repo_id FROM repo WHERE repo_group_id = :repo_group_id)
             and pull_requests.pr_closed_at is NOT NULL and pull_requests.pr_merged_at is NULL
+            GROUP BY closed_date, pull_request_id
+            ORDER BY closed_date
         """)
 
         results = pd.read_sql(closedNoMerge, self.database,
diff --git a/augur/metrics/pull_request/routes.py b/augur/metrics/pull_request/routes.py
index d075d0b93..a012f0c49 100644
--- a/augur/metrics/pull_request/routes.py
+++ b/augur/metrics/pull_request/routes.py
@@ -384,7 +384,6 @@ def create_pull_request_routes(server):
     @apiName pull-request-closed-no-merge
     @apiGroup Experimental
     @apiDescription Timeseries of pull request which were closed but not merged
-    @apiParam {string} repo_group_id Repository Group ID.
     @apiParam {string} repo_id Repository ID.
     @apiParam {string} [begin_date="1970-1-1 0:0:0"] Beginning date specification. E.g. values: `2018`, `2018-05`, `2019-05-01`
     @apiParam {string} [end_date="current date"] Ending date specification. E.g. values: `2018`, `2018-05`, `2019-05-01`
@@ -392,8 +391,26 @@ def create_pull_request_routes(server):
                     [
                         {
                             "date": "2019-01-01T00:00:00.000Z",
-                            "rate": 5.3333333333
+                            "pr_count": 3
                         }
                     ]
     """
     server.addRepoMetric(metrics.pull_requests_closed_no_merge, 'pull-requests-closed-no-merge')
+
+    """
+    @api {get} /repo-groups/:repo_group_id/pull-request-closed-no-merge Pull Request Closed but not merged(Repo)
+    @apiName pull-request-closed-no-merge
+    @apiGroup Experimental
+    @apiDescription Timeseries of pull request which were closed but not merged
+    @apiParam {string} repo_group_id Repository Group ID.
+    @apiParam {string} [begin_date="1970-1-1 0:0:0"] Beginning date specification. E.g. values: `2018`, `2018-05`, `2019-05-01`
+    @apiParam {string} [end_date="current date"] Ending date specification. E.g. values: `2018`, `2018-05`, `2019-05-01`
+    @apiSuccessExample {json} Success-Response:
+                    [
+                        {
+                            "date": "2019-01-01T00:00:00.000Z",
+                            "pr_count": 3
+                        }
+                    ]
+    """
+    server.addRepoGroupMetric(metrics.pull_requests_closed_no_merge, 'pull-requests-closed-no-merge')
diff --git a/test/api/test_pull_request_routes.py b/test/api/test_pull_request_routes.py
index 96d4408d7..a5e8ff0c0 100644
--- a/test/api/test_pull_request_routes.py
+++ b/test/api/test_pull_request_routes.py
@@ -20,8 +20,9 @@ def test_pull_requests_merge_contributor_new_by_repo(metrics):
     assert data[0]["count"] > 0
 
 def test_pull_requests_closed_no_merge(metrics):
-    response = requests.get('http://localhost:5000/api/unstable/repo/20/pull-request-closed-no-merge')
+    response = requests.get('http://localhost:5000/api/unstable/repos/21000/pull-requests-closed-no-merge')
     data = response.json()
     assert response.status_code == 200
     assert len(data) >= 1
-    assert data[0]["count"] > 0
+    assert data[0]["pr_count"] > 0
+
diff --git a/test/metrics/test_pull_request_metrics.py b/test/metrics/test_pull_request_metrics.py
index 65532869b..6d1a4466f 100644
--- a/test/metrics/test_pull_request_metrics.py
+++ b/test/metrics/test_pull_request_metrics.py
@@ -28,7 +28,7 @@ def test_pull_request_acceptance_rate(metrics):
                                      end_date='2019-12-31 23:59:59',group_by='year').iloc[0]['rate'] > 0
 
 def test_pull_request_closed_no_merge(metrics):
-    assert metrics.pull_requests_closed_no_merge(24).iloc[0]['count'] > 0
+    assert metrics.pull_requests_closed_no_merge(24).iloc[0]['pr_count'] > 0
     assert metrics.pull_requests_closed_no_merge(24, 21000, begin_date='2018-1-1 00:00:00',
-                                     end_date='2019-12-31 23:59:59', group_by='year').iloc[0]['count'] > 0
+                                     end_date='2019-12-31 23:59:59').iloc[0]['pr_count'] > 0