From 121e3db806c9f79778f812061533922234fa4d44 Mon Sep 17 00:00:00 2001
From: Vivek Anand <vivekanand1101@gmail.com>
Date: Jul 27 2017 05:31:51 +0000
Subject: [PATCH 1/3] api/issue: tell pylint to not check number of lines/branches/statements


Signed-off-by: Vivek Anand <vivekanand1101@gmail.com>

---

diff --git a/pagure/api/issue.py b/pagure/api/issue.py
index d5b9296..02f5c5e 100644
--- a/pagure/api/issue.py
+++ b/pagure/api/issue.py
@@ -8,6 +8,12 @@
 
 """
 
+
+# pylint: disable=too-many-lines
+# pylint: disable=too-many-branches
+# pylint: disable=too-many-locals
+# pylint: disable=too-many-statements
+
 import datetime
 import flask
 

From 38a14413dcf46c0ed5684260c86dcd84d169c536 Mon Sep 17 00:00:00 2001
From: Vivek Anand <vivekanand1101@gmail.com>
Date: Jul 27 2017 05:31:51 +0000
Subject: [PATCH 2/3] Add redirects for /repo/issue and /api/issue


By this commit, we will stop giving 404 for url
like: https://pagure.io/pagure/issue. We will redirect
it to https://pagure.io/pagure/issues instead. This might
be first step in removing /issue/1234 in future.

---

diff --git a/pagure/api/issue.py b/pagure/api/issue.py
index 02f5c5e..79c793e 100644
--- a/pagure/api/issue.py
+++ b/pagure/api/issue.py
@@ -269,6 +269,18 @@ def api_new_issue(repo, username=None, namespace=None):
     return jsonout
 
 
+@API.route('/<namespace>/<repo>/issue')
+@API.route('/fork/<username>/<repo>/issue')
+@API.route('/<repo>/issue')
+@API.route('/fork/<username>/<namespace>/<repo>/issue')
+@api_login_optional()
+@api_method
+def api_view_issues_redirect(repo, username=None, namespace=None):
+    """ List the issues in the project """
+    return flask.redirect(flask.url_for(
+        'api_ns.api_view_issues', repo=repo, username=username, namespace=namespace))
+
+
 @API.route('/<namespace>/<repo>/issues')
 @API.route('/fork/<username>/<repo>/issues')
 @API.route('/<repo>/issues')
diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py
index 2d6f34b..857c39b 100644
--- a/pagure/ui/issues.py
+++ b/pagure/ui/issues.py
@@ -589,6 +589,21 @@ def remove_tag(repo, username=None, namespace=None):
     )
 
 
+@APP.route('/<repo>/issue/')
+@APP.route('/<repo>/issue')
+@APP.route('/<namespace>/<repo>/issue/')
+@APP.route('/<namespace>/<repo>/issue')
+@APP.route('/fork/<username>/<repo>/issue/')
+@APP.route('/fork/<username>/<repo>/issue')
+@APP.route('/fork/<username>/<namespace>/<repo>/issue/')
+@APP.route('/fork/<username>/<namespace>/<repo>/issue')
+def view_issues_redirect(repo, username=None, namespace=None):
+    """ List all issues associated to a repo
+    """
+    return flask.redirect(flask.url_for(
+        'view_issues', repo=repo, username=username, namespace=namespace))
+
+
 @APP.route('/<repo>/issues/')
 @APP.route('/<repo>/issues')
 @APP.route('/<namespace>/<repo>/issues/')

From cfc404a59df0bd157501e976daff3e446f6cc25b Mon Sep 17 00:00:00 2001
From: Vivek Anand <vivekanand1101@gmail.com>
Date: Jul 27 2017 05:31:51 +0000
Subject: [PATCH 3/3] Unit tests: add redirects for /issue/ and /api/issue


Signed-off-by: Vivek Anand <vivekanand1101@gmail.com>

---

diff --git a/tests/test_pagure_flask_api_issue.py b/tests/test_pagure_flask_api_issue.py
index 2caa287..3985834 100644
--- a/tests/test_pagure_flask_api_issue.py
+++ b/tests/test_pagure_flask_api_issue.py
@@ -797,6 +797,52 @@ class PagureFlaskApiIssuetests(tests.Modeltests):
             }
         )
 
+    def test_api_view_issues_redirect(self):
+        """ Test the api_view_issues redirect method of the flask api. """
+        self.test_api_new_issue()
+
+        output = self.app.get('/api/0/foo/issue')
+        self.assertEqual(output.status_code, 302)
+        # Invalid repo
+        output = self.app.get('/api/0/foo/issue', follow_redirects=True)
+        self.assertEqual(output.status_code, 404)
+        data = json.loads(output.data)
+        self.assertDictEqual(
+            data,
+            {
+              "error": "Project not found",
+              "error_code": "ENOPROJECT",
+            }
+        )
+
+        # List all opened issues
+        output = self.app.get('/api/0/test/issue')
+        self.assertEqual(output.status_code, 302)
+
+        output = self.app.get('/api/0/test/issue', follow_redirects=True)
+        self.assertEqual(output.status_code, 200)
+        data = json.loads(output.data)
+        for idx in range(len(data['issues'])):
+            data['issues'][idx]['date_created'] = '1431414800'
+            data['issues'][idx]['last_updated'] = '1431414800'
+        self.assertDictEqual(
+            data,
+            {
+              "args": {
+                "assignee": None,
+                "author": None,
+                'milestones': [],
+                'no_stones': None,
+                'priority': None,
+                "since": None,
+                "status": None,
+                "tags": [],
+              },
+              "issues": FULL_ISSUE_LIST[3:],
+              "total_issues": 6
+            }
+        )
+
     def test_api_view_issues(self):
         """ Test the api_view_issues method of the flask api. """
         self.test_api_new_issue()
diff --git a/tests/test_pagure_flask_ui_issues.py b/tests/test_pagure_flask_ui_issues.py
index 90109db..7828e4b 100644
--- a/tests/test_pagure_flask_ui_issues.py
+++ b/tests/test_pagure_flask_ui_issues.py
@@ -423,6 +423,34 @@ class PagureFlaskIssuestests(tests.Modeltests):
 
     @patch('pagure.lib.git.update_git')
     @patch('pagure.lib.notify.send_email')
+    def test_view_issues_redirect(self, p_send_email, p_ugt):
+        """ Test the view_issues endpoint. """
+        p_send_email.return_value = True
+        p_ugt.return_value = True
+
+        output = self.app.get('/foo/issue')
+        self.assertEqual(output.status_code, 302)
+
+        output = self.app.get('/foo/issue', follow_redirects=True)
+        self.assertEqual(output.status_code, 404)
+
+        tests.create_projects(self.session)
+        tests.create_projects_git(
+            os.path.join(self.path, 'repos'), bare=True)
+
+        output = self.app.get('/test/issue')
+        self.assertEqual(output.status_code, 302)
+
+        output = self.app.get('/test/issue', follow_redirects=True)
+        self.assertEqual(output.status_code, 200)
+        self.assertIn(
+            'div class="projectinfo m-t-1 m-b-1">\ntest project #1        '
+            '</div>', output.data)
+        self.assertTrue(
+            '<h2>\n      0 Open Issues' in output.data)
+
+    @patch('pagure.lib.git.update_git')
+    @patch('pagure.lib.notify.send_email')
     def test_view_issues(self, p_send_email, p_ugt):
         """ Test the view_issues endpoint. """
         p_send_email.return_value = True

