From c99ccdea71a1817e82ddc948a33ebec17d3edc10 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 29 2016 09:25:52 +0000 Subject: [PATCH 1/22] Pep8 fixes to the pagure.hooks --- diff --git a/pagure/hooks/files/pagure_block_unsigned.py b/pagure/hooks/files/pagure_block_unsigned.py index c9bee63..111b813 100755 --- a/pagure/hooks/files/pagure_block_unsigned.py +++ b/pagure/hooks/files/pagure_block_unsigned.py @@ -54,7 +54,7 @@ def run_as_pre_receive_hook(): print 'Processing commit: %s' % commit signed = False for line in pagure.lib.git.read_git_lines( - ['log', '--no-walk', commit], abspath): + ['log', '--no-walk', commit], abspath): if line.lower().strip().startswith('signed-off-by'): signed = True break diff --git a/pagure/hooks/mail.py b/pagure/hooks/mail.py index cf67419..941e54c 100644 --- a/pagure/hooks/mail.py +++ b/pagure/hooks/mail.py @@ -66,8 +66,9 @@ class Mail(BaseHook): ''' Mail hooks. ''' name = 'Mail' - description = 'Generate notification emails for pushes to a git repository. '\ - 'This hook sends emails describing changes introduced by pushes to a git repository.' + description = 'Generate notification emails for pushes to a git '\ + 'repository. This hook sends emails describing changes introduced '\ + 'by pushes to a git repository.' form = MailForm db_object = MailTable backref = 'mail_hook' diff --git a/pagure/hooks/pagure_ci.py b/pagure/hooks/pagure_ci.py index 12c2576..3998477 100644 --- a/pagure/hooks/pagure_ci.py +++ b/pagure/hooks/pagure_ci.py @@ -60,7 +60,8 @@ class PagureCITable(BASE): tmpl = """ -{% if repo | hasattr('ci_hook') and repo.ci_hook and repo.ci_hook[0].pagure_ci_token %} +{% if repo | hasattr('ci_hook') and repo.ci_hook and + repo.ci_hook[0].pagure_ci_token %} The token to be used by jenkins to trigger the build is:
diff --git a/pagure/hooks/pagure_request_hook.py b/pagure/hooks/pagure_request_hook.py
index 7182531..b65f060 100644
--- a/pagure/hooks/pagure_request_hook.py
+++ b/pagure/hooks/pagure_request_hook.py
@@ -64,7 +64,8 @@ class PagureRequestHook(BaseHook):
 
     name = 'Pagure requests'
     description = 'Pagure specific hook to update pull-requests stored '\
-        'in the database based on the information pushed in the requests git repository.'
+        'in the database based on the information pushed in the requests '\
+        'git repository.'
     form = PagureRequestsForm
     db_object = PagureRequestsTable
     backref = 'pagure_hook_requests'

From 2c3a3fa373df1fae09097b85fe3741025616fb0c Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 2/22] Drop un-used imports (thanks pylint)


---

diff --git a/pagure/hooks/fedmsg.py b/pagure/hooks/fedmsg.py
index 69cf3f5..e7ed0bb 100644
--- a/pagure/hooks/fedmsg.py
+++ b/pagure/hooks/fedmsg.py
@@ -1,18 +1,16 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2015 - Copyright Red Hat Inc
+ (c) 2015-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
 
 """
 
-import os
-
+import flask_wtf as wtf
 import sqlalchemy as sa
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
diff --git a/pagure/hooks/irc.py b/pagure/hooks/irc.py
index c9ff494..f1d26a0 100644
--- a/pagure/hooks/irc.py
+++ b/pagure/hooks/irc.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -10,10 +10,10 @@
 
 import os
 
+import flask_wtf as wtf
 import sqlalchemy as sa
 import pygit2
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
diff --git a/pagure/hooks/mail.py b/pagure/hooks/mail.py
index 941e54c..667538d 100644
--- a/pagure/hooks/mail.py
+++ b/pagure/hooks/mail.py
@@ -8,12 +8,10 @@
 
 """
 
-import os
-
+import flask_wtf as wtf
 import sqlalchemy as sa
 import pygit2
-import wtforms
-from flask.ext import wtf
+import wtforms\
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
diff --git a/pagure/hooks/pagure_ci.py b/pagure/hooks/pagure_ci.py
index 3998477..fa33272 100644
--- a/pagure/hooks/pagure_ci.py
+++ b/pagure/hooks/pagure_ci.py
@@ -8,18 +8,16 @@
 
 """
 
-import os
-
+import flask_wtf as wtf
 import sqlalchemy as sa
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
 import pagure.lib
 from pagure.hooks import BaseHook, RequiredIf
 from pagure.lib.model import BASE, Project
-from pagure import get_repo_path, SESSION, APP
+from pagure import SESSION, APP
 
 
 class PagureCITable(BASE):
diff --git a/pagure/hooks/pagure_force_commit.py b/pagure/hooks/pagure_force_commit.py
index b90f047..2ef2d3b 100644
--- a/pagure/hooks/pagure_force_commit.py
+++ b/pagure/hooks/pagure_force_commit.py
@@ -8,18 +8,16 @@
 
 """
 
-import os
-
+import flask_wtf as wtf
 import sqlalchemy as sa
 import pygit2
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
 from pagure.hooks import BaseHook, RequiredIf
 from pagure.lib.model import BASE, Project
-from pagure import APP, get_repo_path
+from pagure import get_repo_path
 
 
 class PagureForceCommitTable(BASE):
diff --git a/pagure/hooks/pagure_hook.py b/pagure/hooks/pagure_hook.py
index 3f35f99..541cae5 100644
--- a/pagure/hooks/pagure_hook.py
+++ b/pagure/hooks/pagure_hook.py
@@ -10,10 +10,9 @@
 
 import os
 
+import flask_wtf as wtf
 import sqlalchemy as sa
-import pygit2
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
diff --git a/pagure/hooks/pagure_request_hook.py b/pagure/hooks/pagure_request_hook.py
index b65f060..ee0529c 100644
--- a/pagure/hooks/pagure_request_hook.py
+++ b/pagure/hooks/pagure_request_hook.py
@@ -11,10 +11,9 @@
 import os
 
 import flask
+import flask_wtf as wtf
 import sqlalchemy as sa
-import pygit2
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
diff --git a/pagure/hooks/pagure_ticket_hook.py b/pagure/hooks/pagure_ticket_hook.py
index 83b1a8b..d2379c1 100644
--- a/pagure/hooks/pagure_ticket_hook.py
+++ b/pagure/hooks/pagure_ticket_hook.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -11,10 +11,9 @@
 import os
 
 import flask
+import flask_wtf as wtf
 import sqlalchemy as sa
-import pygit2
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
diff --git a/pagure/hooks/pagure_unsigned_commits.py b/pagure/hooks/pagure_unsigned_commits.py
index 745abb7..117139f 100644
--- a/pagure/hooks/pagure_unsigned_commits.py
+++ b/pagure/hooks/pagure_unsigned_commits.py
@@ -8,18 +8,15 @@
 
 """
 
-import os
-
+import flask_wtf as wtf
 import sqlalchemy as sa
-import pygit2
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
-from pagure.hooks import BaseHook, RequiredIf
+from pagure.hooks import BaseHook
 from pagure.lib.model import BASE, Project
-from pagure import APP, get_repo_path
+from pagure import get_repo_path
 
 
 class PagureUnsignedCommitTable(BASE):
diff --git a/pagure/hooks/rtd.py b/pagure/hooks/rtd.py
index 0a0e586..5f072b2 100644
--- a/pagure/hooks/rtd.py
+++ b/pagure/hooks/rtd.py
@@ -8,18 +8,15 @@
 
 """
 
-import os
-
+import flask_wtf as wtf
 import sqlalchemy as sa
-import pygit2
 import wtforms
-from flask.ext import wtf
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
 from pagure.hooks import BaseHook, RequiredIf
 from pagure.lib.model import BASE, Project
-from pagure import APP, get_repo_path
+from pagure import get_repo_path
 
 
 class RtdTable(BASE):

From 362b15ce56df4b641a84fab0f2afe3dc29bdd07d Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 3/22] Fix last imports on flask-wtf


---

diff --git a/pagure/forms.py b/pagure/forms.py
index f3a2652..e23598b 100644
--- a/pagure/forms.py
+++ b/pagure/forms.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -9,8 +9,9 @@
 """
 
 import re
-from flask.ext import wtf
+
 import flask
+import flask_wtf as wtf
 import wtforms
 import tempfile
 # pylint: disable=R0903,W0232,E1002
diff --git a/pagure/hooks/mail.py b/pagure/hooks/mail.py
index 667538d..f6e70c4 100644
--- a/pagure/hooks/mail.py
+++ b/pagure/hooks/mail.py
@@ -11,7 +11,7 @@
 import flask_wtf as wtf
 import sqlalchemy as sa
 import pygit2
-import wtforms\
+import wtforms
 from sqlalchemy.orm import relation
 from sqlalchemy.orm import backref
 
diff --git a/pagure/login_forms.py b/pagure/login_forms.py
index 0819762..dd0d631 100644
--- a/pagure/login_forms.py
+++ b/pagure/login_forms.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -19,7 +19,7 @@
 # pylint: disable=W0232
 
 
-from flask.ext import wtf
+import flask_wtf as wtf
 import wtforms
 
 from pagure.forms import ConfirmationForm

From 0074a54ba5e79f9f539ff2bd8dbf799ae2505f53 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 4/22] Small style fixes in the model


---

diff --git a/pagure/lib/model.py b/pagure/lib/model.py
index 6b8b1ea..75622ea 100644
--- a/pagure/lib/model.py
+++ b/pagure/lib/model.py
@@ -70,7 +70,7 @@ def create_tables(db_url, alembic_ini=None, acls=None, debug=False):
     if db_url.startswith('sqlite:'):
         # Ignore the warning about con_record
         # pylint: disable=W0613
-        def _fk_pragma_on_connect(dbapi_con, con_record):  # pragma: no cover
+        def _fk_pragma_on_connect(dbapi_con, _):  # pragma: no cover
             ''' Tries to enforce referential constraints on sqlite. '''
             dbapi_con.execute('pragma foreign_keys=ON')
         sa.event.listen(engine, 'connect', _fk_pragma_on_connect)
@@ -1144,6 +1144,8 @@ class PullRequestComment(BASE):
         return self.pull_request
 
     def to_json(self, public=False):
+        ''' Return a dict representation of the pull-request comment. '''
+
         return {
             'id': self.id,
             'commit': self.commit_id,

From d1e05379c38564cb821ec395843f1a5a32e8b780 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 5/22] Some more code and style fixes in pagure.lib


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index 0bd36f6..03d674d 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -50,10 +50,10 @@ from pagure.lib import model
 REDIS = None
 PAGURE_CI = None
 
-def set_redis(host, port, db):
+def set_redis(host, port, dbname):
     """ Set the redis connection with the specified information. """
     global REDIS
-    pool = redis.ConnectionPool(host=host, port=port, db=db)
+    pool = redis.ConnectionPool(host=host, port=port, db=dbname)
     REDIS = redis.StrictRedis(connection_pool=pool)
 
 def set_pagure_ci(services):
@@ -178,6 +178,10 @@ def search_user(session, username=None, email=None, token=None, pattern=None):
 
 
 def create_user_ssh_keys_on_disk(user, gitolite_keydir):
+    ''' Create the ssh keys for the user on the specific folder.
+
+    This is the method allowing to have multiple ssh keys per user.
+    '''
     if gitolite_keydir:
         # First remove any old keyfiles for the user
         # Assumption: we populated the keydir. This means that files
@@ -1055,13 +1059,14 @@ def new_project(session, user, name, blacklist, allowed_prefix,
             userobj.default_email.encode('utf-8') if six.PY2 else userobj.fullname
         )
         content = u"# %s\n\n%s" % (name, description)
-        f = open(os.path.join(temp_gitrepo.workdir,"README.md"), 'wb')
-        f.write(content.encode('utf-8'))
-        f.close()
+        with open(os.path.join(temp_gitrepo.workdir, "README.md"), 'wb') \
+                as stream:
+            stream.write(content.encode('utf-8'))
         temp_gitrepo.index.add_all()
         temp_gitrepo.index.write()
         tree = temp_gitrepo.index.write_tree()
-        temp_gitrepo.create_commit('HEAD', author,author, 'Added the README', tree, [])
+        temp_gitrepo.create_commit(
+            'HEAD', author,author, 'Added the README', tree, [])
         pygit2.clone_repository(temp_gitrepo_path, gitrepo, bare=True)
         shutil.rmtree(temp_gitrepo_path)
 
@@ -1421,7 +1426,7 @@ def fork_project(session, user, repo, gitfolder,
     # Create the git-daemin-export-ok file on the clone
     http_clone_file = os.path.join(forkreponame, 'git-daemon-export-ok')
     if not os.path.exists(http_clone_file):
-        with open(http_clone_file, 'w') as stream:
+        with open(http_clone_file, 'w'):
             pass
 
     docrepo = os.path.join(docfolder, project.path)
@@ -2365,7 +2370,7 @@ def resend_pending_email(session, userobj, email):
             'This email address has already been confirmed'
         )
 
-    pending_email.token=pagure.lib.login.id_generator(40)
+    pending_email.token = pagure.lib.login.id_generator(40)
     session.add(pending_email)
     session.flush()
 

From f9f1323c1de28e4556039c759dc577d47f7a5463 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 6/22] Some more code style fixes in the pagure.lib module


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index 03d674d..5908de3 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -44,7 +44,14 @@ import pagure.lib.notify
 import pagure.pfmarkdown
 from pagure.lib import model
 
+# too-many-branches
+# pylint: disable=R0912
+# too-many-arguments
 # pylint: disable=R0913
+# too-many-locals
+# pylint: disable=R0914
+# too-many-statements
+# pylint: disable=R0915
 
 
 REDIS = None
@@ -1059,14 +1066,14 @@ def new_project(session, user, name, blacklist, allowed_prefix,
             userobj.default_email.encode('utf-8') if six.PY2 else userobj.fullname
         )
         content = u"# %s\n\n%s" % (name, description)
-        with open(os.path.join(temp_gitrepo.workdir, "README.md"), 'wb') \
-                as stream:
+        readme_file = os.path.join(temp_gitrepo.workdir, "README.md")
+        with open(readme_file, 'wb') as stream:
             stream.write(content.encode('utf-8'))
         temp_gitrepo.index.add_all()
         temp_gitrepo.index.write()
         tree = temp_gitrepo.index.write_tree()
         temp_gitrepo.create_commit(
-            'HEAD', author,author, 'Added the README', tree, [])
+            'HEAD', author, author, 'Added the README', tree, [])
         pygit2.clone_repository(temp_gitrepo_path, gitrepo, bare=True)
         shutil.rmtree(temp_gitrepo_path)
 
@@ -1417,11 +1424,12 @@ def fork_project(session, user, repo, gitfolder,
     frepo = pygit2.clone_repository(reponame, forkreponame, bare=True)
     # Clone all the branches as well
     for branch in frepo.listall_branches(pygit2.GIT_BRANCH_REMOTE):
-        br = frepo.lookup_branch(branch, pygit2.GIT_BRANCH_REMOTE)
-        name = br.branch_name.replace(br.remote_name, '')[1:]
+        branch_obj = frepo.lookup_branch(branch, pygit2.GIT_BRANCH_REMOTE)
+        name = branch_obj.branch_name.replace(
+            branch_obj.remote_name, '')[1:]
         if name in frepo.listall_branches(pygit2.GIT_BRANCH_LOCAL):
             continue
-        frepo.create_branch(name, frepo.get(br.target.hex))
+        frepo.create_branch(name, frepo.get(branch_obj.target.hex))
 
     # Create the git-daemin-export-ok file on the clone
     http_clone_file = os.path.join(forkreponame, 'git-daemon-export-ok')
@@ -1489,7 +1497,7 @@ def search_projects(
                 model.User.id == model.Project.user_id,
             )
         )
-        q2 = session.query(
+        sub_q2 = session.query(
             model.Project.id
         ).filter(
             # User got commit right
@@ -1499,7 +1507,7 @@ def search_projects(
                 model.ProjectUser.project_id == model.Project.id
             )
         )
-        q3 = session.query(
+        sub_q3 = session.query(
             model.Project.id
         ).filter(
             # User created a group that has commit right
@@ -1511,7 +1519,7 @@ def search_projects(
                 model.Project.id == model.ProjectGroup.project_id,
             )
         )
-        q4 = session.query(
+        sub_q4 = session.query(
             model.Project.id
         ).filter(
             # User is part of a group that has commit right
@@ -1525,7 +1533,7 @@ def search_projects(
             )
         )
 
-        projects = projects.union(q2).union(q3).union(q4)
+        projects = projects.union(sub_q2).union(sub_q3).union(sub_q4)
 
     if fork is not None:
         if fork is True:
@@ -1706,7 +1714,7 @@ def search_issues(
                 ytags.append(tag)
 
         if ytags:
-            q2 = session.query(
+            sub_q2 = session.query(
                 sqlalchemy.distinct(model.Issue.uid)
             ).filter(
                 model.Issue.project_id == repo.id
@@ -1716,7 +1724,7 @@ def search_issues(
                 model.TagIssue.tag.in_(ytags)
             )
         if notags:
-            q3 = session.query(
+            sub_q3 = session.query(
                 sqlalchemy.distinct(model.Issue.uid)
             ).filter(
                 model.Issue.project_id == repo.id
@@ -1727,11 +1735,11 @@ def search_issues(
             )
         # Adjust the main query based on the parameters specified
         if ytags and not notags:
-            query = query.filter(model.Issue.uid.in_(q2))
+            query = query.filter(model.Issue.uid.in_(sub_q2))
         elif not ytags and notags:
-            query = query.filter(~model.Issue.uid.in_(q3))
+            query = query.filter(~model.Issue.uid.in_(sub_q3))
         elif ytags and notags:
-            final_set = set(q2.all()) - set(q3.all())
+            final_set = set(sub_q2.all()) - set(sub_q3.all())
             if final_set:
                 query = query.filter(model.Issue.uid.in_(list(final_set)))
 
@@ -2733,10 +2741,10 @@ def add_token_to_user(session, project, acls, username):
 def text2markdown(text, extended=True):
     """ Simple text to html converter using the markdown library.
     """
-    md = markdown.Markdown(safe_mode="escape")
+    md_processor = markdown.Markdown(safe_mode="escape")
     if extended:
         # Install our markdown modifications
-        md = markdown.Markdown(extensions=['pagure.pfmarkdown'])
+        md_processor = markdown.Markdown(extensions=['pagure.pfmarkdown'])
 
     if text:
         # Hack to allow blockquotes to be marked by ~~~
@@ -2749,7 +2757,7 @@ def text2markdown(text, extended=True):
             if indent:
                 line = '    %s' % line
             ntext.append(line)
-        return clean_input(md.convert('\n'.join(ntext)))
+        return clean_input(md_processor.convert('\n'.join(ntext)))
 
     return ''
 
@@ -2759,8 +2767,8 @@ def filter_img_src(name, value):
     if name in ('alt', 'height', 'width', 'class'):
         return True
     if name == 'src':
-        p = urlparse.urlparse(value)
-        return (not p.netloc) or p.netloc == urlparse.urlparse(
+        parsed = urlparse.urlparse(value)
+        return (not parsed.netloc) or parsed.netloc == urlparse.urlparse(
             pagure.APP.config['APP_URL']).netloc
     return False
 
@@ -2816,7 +2824,7 @@ def get_pull_request_of_user(session, username):
             model.User.id == model.Project.user_id,
         )
     )
-    q2 = session.query(
+    sub_q2 = session.query(
         model.Project.id
     ).filter(
         # User got commit right
@@ -2826,7 +2834,7 @@ def get_pull_request_of_user(session, username):
             model.ProjectUser.project_id == model.Project.id
         )
     )
-    q3 = session.query(
+    sub_q3 = session.query(
         model.Project.id
     ).filter(
         # User created a group that has commit right
@@ -2838,7 +2846,7 @@ def get_pull_request_of_user(session, username):
             model.Project.id == model.ProjectGroup.project_id,
         )
     )
-    q4 = session.query(
+    sub_q4 = session.query(
         model.Project.id
     ).filter(
         # User is part of a group that has commit right
@@ -2852,7 +2860,7 @@ def get_pull_request_of_user(session, username):
         )
     )
 
-    projects = projects.union(q2).union(q3).union(q4)
+    projects = projects.union(sub_q2).union(sub_q3).union(sub_q4)
 
     query = session.query(
         model.PullRequest

From 341785d61b48784a7bcd2979f24e1986a32c1be0 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 7/22] Fix copyright year in pagure.lib and style fix pagure.lib.link


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index 5908de3..177d054 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014-2015 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
diff --git a/pagure/lib/link.py b/pagure/lib/link.py
index 6cdf46d..8749439 100644
--- a/pagure/lib/link.py
+++ b/pagure/lib/link.py
@@ -1,13 +1,16 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2015 - Copyright Red Hat Inc
+ (c) 2015-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
 
 """
 
+# too-many-arguments
+# pylint: disable=R0913
+
 
 import re
 

From 5b20c87638a8bb46f98faf336bee62ca9e729cd9 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 8/22] Style fix to pagure.lib.lib_ci


---

diff --git a/pagure/lib/lib_ci.py b/pagure/lib/lib_ci.py
index d2ea609..5d77e70 100644
--- a/pagure/lib/lib_ci.py
+++ b/pagure/lib/lib_ci.py
@@ -10,14 +10,8 @@
 
 """
 
-import json
-import logging
-
-import requests
-
-from sqlalchemy.orm import scoped_session, sessionmaker
-from sqlalchemy.exc import SQLAlchemyError
-from sqlalchemy import create_engine
+# too-many-locals
+# pylint: disable=R0914
 
 import pagure.exceptions
 import pagure.lib
@@ -80,7 +74,7 @@ def process_jenkins_build(session, project, build_id, requestfolder):
 
     comment, percent = BUILD_STATS[result]
 
-    message = pagure.lib.add_pull_request_flag(
+    pagure.lib.add_pull_request_flag(
         session,
         request=request,
         username=project.ci_hook[0].ci_type,

From c70df4d232940f49d228284f348a0d6712203882 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 9/22] Style fixes to pagure.lib.git


---

diff --git a/pagure/lib/git.py b/pagure/lib/git.py
index ceba03a..1b720d4 100644
--- a/pagure/lib/git.py
+++ b/pagure/lib/git.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2015 - Copyright Red Hat Inc
+ (c) 2015-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -16,7 +16,6 @@ import os
 import shutil
 import subprocess
 import tempfile
-import re
 
 import pygit2
 import werkzeug
@@ -30,7 +29,19 @@ import pagure.lib.notify
 from pagure.lib import model
 from pagure.lib.repo import PagureRepo
 
-# pylint: disable=R0913,E1101,R0914
+
+# too-many-branches
+# pylint: disable=R0912
+# too-many-arguments
+# pylint: disable=R0913
+# too-many-locals
+# pylint: disable=R0914
+# too-many-statements
+# pylint: disable=R0915
+# no-member
+# pylint: disable=E1101
+# C0302
+# pylint: disable=C0302
 
 
 def commit_to_patch(repo_obj, commits):
@@ -189,11 +200,11 @@ def update_git(obj, repo, repofolder):
     # Retrieve the list of files that changed
     diff = new_repo.diff()
     files = []
-    for p in diff:
-        if hasattr(p, 'new_file_path'):
-            files.append(p.new_file_path)
-        elif hasattr(p, 'delta'):
-            files.append(p.delta.new_file.path)
+    for patch in diff:
+        if hasattr(patch, 'new_file_path'):
+            files.append(patch.new_file_path)
+        elif hasattr(patch, 'delta'):
+            files.append(patch.delta.new_file.path)
 
     # Add the changes to the index
     if added:
@@ -380,6 +391,8 @@ def get_project_from_json(
                 user=user.username)
 
         else:
+            gitfolder = os.path.join(
+                gitfolder, 'forks', user.username) if parent else gitfolder
             pagure.lib.new_project(
                 session,
                 user=user.username,
@@ -387,8 +400,8 @@ def get_project_from_json(
                 description=jsondata.get('description'),
                 parent_id=parent.id if parent else None,
                 blacklist=pagure.APP.config.get('BLACKLISTED_PROJECTS', []),
-                gitfolder=os.path.join(gitfolder, 'forks', user.username)
-                    if parent else gitfolder,
+                allowed_prefix=pagure.APP.config.get('ALLOWED_PREFIX', []),
+                gitfolder=gitfolder,
                 docfolder=docfolder,
                 ticketfolder=ticketfolder,
                 requestfolder=requestfolder,
@@ -738,11 +751,11 @@ def update_file_in_git(
     # Retrieve the list of files that changed
     diff = new_repo.diff()
     files = []
-    for p in diff:
-        if hasattr(p, 'new_file_path'):
-            files.append(p.new_file_path)
-        elif hasattr(p, 'delta'):
-            files.append(p.delta.new_file.path)
+    for patch in diff:
+        if hasattr(patch, 'new_file_path'):
+            files.append(patch.new_file_path)
+        elif hasattr(patch, 'delta'):
+            files.append(patch.delta.new_file.path)
 
     # Add the changes to the index
     added = False
@@ -1176,11 +1189,14 @@ def diff_pull_request(
                         if i.oid.hex == request.commit_stop:
                             break
                         new_commits_count = new_commits_count + 1
-                        commenttext = '%s * %s\n' % (commenttext, i.message.strip().split('\n')[0])
+                        commenttext = '%s * %s\n' % (
+                            commenttext, i.message.strip().split('\n')[0])
                     if new_commits_count == 1:
-                        commenttext = "**%d new commit added**\n\n%s" % (new_commits_count, commenttext)
+                        commenttext = "**%d new commit added**\n\n%s" % (
+                            new_commits_count, commenttext)
                     else:
-                        commenttext = "**%d new commits added**\n\n%s" % (new_commits_count, commenttext)
+                        commenttext = "**%d new commits added**\n\n%s" % (
+                            new_commits_count, commenttext)
                 if request.commit_start and \
                         request.commit_start != first_commit.oid.hex:
                     commenttext = 'rebased'
@@ -1272,7 +1288,7 @@ def get_git_tags_objects(project):
 
             tags[commit_time] = {
                 "object": repo_obj[repo_obj.lookup_reference(tag).target],
-                "tagname": tag.replace("refs/tags/",""),
+                "tagname": tag.replace("refs/tags/", ""),
                 "date": commit_time,
                 "objecttype": objecttype,
                 "head_msg": None,

From c3b072a5411af30634aad47aca420f5826f606a7 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 10/22] Be consistent in where we're placing the pylint instructions


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index 177d054..e8d7ddd 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -8,6 +8,16 @@
 
 """
 
+# too-many-branches
+# pylint: disable=R0912
+# too-many-arguments
+# pylint: disable=R0913
+# too-many-locals
+# pylint: disable=R0914
+# too-many-statements
+# pylint: disable=R0915
+
+
 try:
     import simplejson as json
 except ImportError:
@@ -44,15 +54,6 @@ import pagure.lib.notify
 import pagure.pfmarkdown
 from pagure.lib import model
 
-# too-many-branches
-# pylint: disable=R0912
-# too-many-arguments
-# pylint: disable=R0913
-# too-many-locals
-# pylint: disable=R0914
-# too-many-statements
-# pylint: disable=R0915
-
 
 REDIS = None
 PAGURE_CI = None

From 6123e5cec3937ffce8606bb995e201e9d1647b8c Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 11/22] Style fixes on pagure.lib.model


---

diff --git a/pagure/lib/model.py b/pagure/lib/model.py
index 75622ea..25d7752 100644
--- a/pagure/lib/model.py
+++ b/pagure/lib/model.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014-2015 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -40,7 +40,16 @@ BASE = declarative_base(metadata=MetaData(naming_convention=CONVENTION))
 
 ERROR_LOG = logging.getLogger('pagure.model')
 
-# pylint: disable=C0103,R0903,W0232,E1101
+# invalid-name  - hit w/ all the id field we use
+# pylint: disable=C0103
+# too-few-public-methods
+# pylint: disable=R0903
+# no-init
+# pylint: disable=W0232
+# no-member
+# pylint: disable=E1101
+# too-many-lines
+# pylint: disable=C0302
 
 
 def create_tables(db_url, alembic_ini=None, acls=None, debug=False):
@@ -731,10 +740,15 @@ class IssueComment(BASE):
             order_by="IssueComment.date_created"
         ),
     )
-    user = relation('User', foreign_keys=[user_id],
-                    remote_side=[User.id], backref='comment_issues')
-    editor = relation('User', foreign_keys=[editor_id],
-                         remote_side=[User.id])
+    user = relation(
+        'User',
+        foreign_keys=[user_id],
+        remote_side=[User.id],
+        backref='comment_issues')
+    editor = relation(
+        'User',
+        foreign_keys=[editor_id],
+        remote_side=[User.id])
 
     @property
     def mail_id(self):
@@ -1122,13 +1136,16 @@ class PullRequestComment(BASE):
     pull_request = relation(
         'PullRequest',
         backref=backref(
-            'comments', cascade="delete, delete-orphan",
+            'comments',
+            cascade="delete, delete-orphan",
             order_by="PullRequestComment.date_created"
         ),
         foreign_keys=[pull_request_uid],
         remote_side=[PullRequest.uid])
-    editor = relation('User', foreign_keys=[editor_id],
-                         remote_side=[User.id])
+    editor = relation(
+        'User',
+        foreign_keys=[editor_id],
+        remote_side=[User.id])
 
     @property
     def mail_id(self):

From f5708bdd46546520245c60a9d11bcbd18df2cba6 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 12/22] Final style fixes to pagure.lib


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index e8d7ddd..2bd4ca6 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -16,6 +16,8 @@
 # pylint: disable=R0914
 # too-many-statements
 # pylint: disable=R0915
+# too-many-lines
+# pylint: disable=C0302
 
 
 try:
diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py
index 890f6cd..6c789ce 100644
--- a/pagure/lib/notify.py
+++ b/pagure/lib/notify.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014-2015 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -9,6 +9,12 @@
 pagure notifications.
 """
 
+# too-many-branches
+# pylint: disable=R0912
+# too-many-arguments
+# pylint: disable=R0913
+
+
 import datetime
 import hashlib
 import json
@@ -19,8 +25,6 @@ import time
 import warnings
 
 import flask
-import requests
-import six
 import pagure
 
 from email.mime.text import MIMEText
@@ -66,8 +70,8 @@ def _add_mentioned_users(emails, comment):
     ''' Check the comment to see if an user is mentioned in it and if
     so add this user to the list of people to notify.
     '''
-    MENTION_RE = r'@(\w+)'
-    for username in re.findall(MENTION_RE, comment):
+    mentio_re = r'@(\w+)'
+    for username in re.findall(mentio_re, comment):
         user = pagure.lib.search_user(pagure.SESSION, username=username)
         if user:
             emails.add(user.default_email)
diff --git a/pagure/lib/repo.py b/pagure/lib/repo.py
index 1b77330..ef3c11b 100644
--- a/pagure/lib/repo.py
+++ b/pagure/lib/repo.py
@@ -76,7 +76,7 @@ class PagureRepo(pygit2.Repository):
                 else:
                     pagure.LOG.debug(
                         'Un-expected merge result: %s' % (
-                        pygit2.GIT_MERGE_ANALYSIS_NORMAL))
+                            pygit2.GIT_MERGE_ANALYSIS_NORMAL))
                     raise AssertionError('Unknown merge analysis result')
 
     def run_hook(self, old, new, ref, username):

From 602511951c6eb287204fee160157eaf4960dc828 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 13/22] pep8 and pylint fixes to pagure.api


---

diff --git a/pagure/api/__init__.py b/pagure/api/__init__.py
index 1e1d55e..cfadddd 100644
--- a/pagure/api/__init__.py
+++ b/pagure/api/__init__.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2015 - Copyright Red Hat Inc
+ (c) 2015-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -10,6 +10,15 @@ API namespace version 0.
 
 """
 
+# invalid-name
+# pylint: disable=C0103
+# too-few-public-methods
+# pylint: disable=R0903
+# no-member
+# pylint: disable=E1101
+# too-many-locals
+# pylint: disable=R0914
+
 import codecs
 import functools
 import os
@@ -34,8 +43,8 @@ def preload_docs(endpoint):
 
     here = os.path.dirname(os.path.abspath(__file__))
     fname = os.path.join(here, '..', 'doc', endpoint + '.rst')
-    with codecs.open(fname, 'r', 'utf-8') as f:
-        rst = f.read()
+    with codecs.open(fname, 'r', 'utf-8') as stream:
+        rst = stream.read()
 
     rst = modify_rst(rst)
     api_docs = docutils.examples.html_body(rst)
@@ -123,17 +132,17 @@ def api_login_required(acls=None):
     API endpoint.
     '''
 
-    def decorator(fn):
+    def decorator(function):
         ''' The decorator of the function '''
 
-        @functools.wraps(fn)
+        @functools.wraps(function)
         def decorated_function(*args, **kwargs):
             ''' Actually does the job with the arguments provided. '''
 
             response = check_api_acls(acls)
             if response:
                 return response
-            return fn(*args, **kwargs)
+            return function(*args, **kwargs)
 
         return decorated_function
 
@@ -145,17 +154,17 @@ def api_login_optional(acls=None):
     API endpoint.
     '''
 
-    def decorator(fn):
+    def decorator(function):
         ''' The decorator of the function '''
 
-        @functools.wraps(fn)
+        @functools.wraps(function)
         def decorated_function(*args, **kwargs):
             ''' Actually does the job with the arguments provided. '''
 
             response = check_api_acls(acls, optional=True)
             if response:
                 return response
-            return fn(*args, **kwargs)
+            return function(*args, **kwargs)
 
         return decorated_function
 
@@ -167,27 +176,28 @@ def api_method(function):
 
     @functools.wraps(function)
     def wrapper(*args, **kwargs):
+        ''' Actually does the job with the arguments provided. '''
         try:
             result = function(*args, **kwargs)
-        except APIError as e:
-            if e.error_code in [APIERROR.EDBERROR]:
-                APP.logger.exception(e)
+        except APIError as err:
+            if err.error_code in [APIERROR.EDBERROR]:
+                APP.logger.exception(err)
 
-            if e.error_code in [APIERROR.ENOCODE]:
+            if err.error_code in [APIERROR.ENOCODE]:
                 response = flask.jsonify(
                     {
-                        'error': e.error,
-                        'error_code': e.error_code.name
+                        'error': err.error,
+                        'error_code': err.error_code.name
                     }
                 )
             else:
                 response = flask.jsonify(
                     {
-                        'error': e.error_code.value,
-                        'error_code': e.error_code.name,
+                        'error': err.error_code.value,
+                        'error_code': err.error_code.name,
                     }
                 )
-            response.status_code = e.status_code
+            response.status_code = err.status_code
         else:
             response = result
 
@@ -274,13 +284,13 @@ def api_users():
     return flask.jsonify(
         {
             'total_users': len(users),
-            'users': [user.username for user in users],
+            'users': [usr.username for usr in users],
             'mention': [{
-                'username': user.username,
-                'name': user.fullname,
-                'image': pagure.lib.avatar_url_from_openid(user.default_email,
+                'username': usr.username,
+                'name': usr.fullname,
+                'image': pagure.lib.avatar_url_from_openid(usr.default_email,
                                                            size=16)
-            } for user in users]
+            } for usr in users]
         }
     )
 
@@ -437,10 +447,10 @@ def api():
         issues.append(load_doc(issue.api_view_issue_comment))
         issues.append(load_doc(issue.api_comment_issue))
 
-    ci = []
+    ci_doc = []
     if pagure.APP.config.get('PAGURE_CI_SERVICES', True):
         if 'jenkins' in pagure.APP.config['PAGURE_CI_SERVICES']:
-            ci.append(load_doc(jenkins.jenkins_ci_notification))
+            ci_doc.append(load_doc(jenkins.jenkins_ci_notification))
 
     api_pull_request_views_doc = load_doc(fork.api_pull_request_views)
     api_pull_request_view_doc = load_doc(fork.api_pull_request_view)
@@ -491,7 +501,7 @@ def api():
             api_view_user_doc,
             api_groups_doc,
         ],
-        ci=ci,
+        ci=ci_doc,
         extras=extras,
     )
 
diff --git a/pagure/api/ci/jenkins.py b/pagure/api/ci/jenkins.py
index 74673a4..3b30872 100644
--- a/pagure/api/ci/jenkins.py
+++ b/pagure/api/ci/jenkins.py
@@ -12,7 +12,6 @@ import flask
 
 from cryptography.hazmat.primitives import constant_time
 from kitchen.text.converters import to_bytes
-from sqlalchemy.exc import SQLAlchemyError
 
 import pagure
 import pagure.exceptions
@@ -22,9 +21,10 @@ from pagure import APP, SESSION
 from pagure.api import API, APIERROR
 
 
-
-@API.route('/ci/jenkins///build-finished', methods=['POST'])
-@API.route('/ci/jenkins/forks////build-finished', methods=['POST'])
+@API.route('/ci/jenkins///build-finished',
+           methods=['POST'])
+@API.route('/ci/jenkins/forks///'
+           '/build-finished', methods=['POST'])
 def jenkins_ci_notification(repo, pagure_ci_token, username=None):
     """
     Jenkins Build Notification
@@ -40,20 +40,22 @@ def jenkins_ci_notification(repo, pagure_ci_token, username=None):
 
     project = pagure.lib.get_project(SESSION, repo, user=username)
     if repo is None:
-        flask.abort(404, 'Project not found')
+        raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOPROJECT)
 
     if not constant_time.bytes_eq(
-          to_bytes(pagure_ci_token),
-          to_bytes(project.ci_hook[0].pagure_ci_token)):
-        return ('Token mismatch', 401)
+            to_bytes(pagure_ci_token),
+            to_bytes(project.ci_hook[0].pagure_ci_token)):
+        raise pagure.exceptions.APIError(401, error_code=APIERROR.EINVALIDTOK)
 
     data = flask.request.get_json()
     if not data:
-        flask.abort(400, "Bad Request: No JSON retrived")
+        APP.logger.debug("Bad Request: No JSON retrived")
+        raise pagure.exceptions.APIError(400, error_code=APIERROR.EINVALIDREQ)
 
     build_id = data.get('build', {}).get('number')
     if not build_id:
-        flask.abort(400, "Bad Request: No build ID retrived")
+        APP.logger.debug("Bad Request: No build ID retrived")
+        raise pagure.exceptions.APIError(400, error_code=APIERROR.EINVALIDREQ)
 
     try:
         lib_ci.process_jenkins_build(
@@ -64,7 +66,8 @@ def jenkins_ci_notification(repo, pagure_ci_token, username=None):
         )
     except pagure.exceptions.PagureException as err:
         APP.logger.error('Error processing jenkins notification', exc_info=err)
-        flask.abort(400, "Bad Request: %s" % err)
+        raise pagure.exceptions.APIError(
+            400, error_code=APIERROR.ENOCODE, error=str(err))
 
     APP.logger.info('Successfully proccessed jenkins notification')
     return ('', 204)
diff --git a/pagure/api/issue.py b/pagure/api/issue.py
index 8738a59..706f222 100644
--- a/pagure/api/issue.py
+++ b/pagure/api/issue.py
@@ -460,7 +460,8 @@ def api_view_issue_comment(repo, issueid, commentid, username=None):
 
 
 @API.route('//issue//status', methods=['POST'])
-@API.route('/fork///issue//status', methods=['POST'])
+@API.route(
+    '/fork///issue//status', methods=['POST'])
 @api_login_required(acls=['issue_change_status'])
 @api_method
 def api_change_status_issue(repo, issueid, username=None):
@@ -555,7 +556,8 @@ def api_change_status_issue(repo, issueid, username=None):
 
 
 @API.route('//issue//comment', methods=['POST'])
-@API.route('/fork///issue//comment', methods=['POST'])
+@API.route(
+    '/fork///issue//comment', methods=['POST'])
 @api_login_required(acls=['issue_comment'])
 @api_method
 def api_comment_issue(repo, issueid, username=None):
@@ -645,7 +647,8 @@ def api_comment_issue(repo, issueid, username=None):
 
 
 @API.route('//issue//assign', methods=['POST'])
-@API.route('/fork///issue//assign', methods=['POST'])
+@API.route(
+    '/fork///issue//assign', methods=['POST'])
 @api_login_required(acls=['issue_assign'])
 @api_method
 def api_assign_issue(repo, issueid, username=None):
diff --git a/pagure/api/user.py b/pagure/api/user.py
index 65c8664..9280052 100644
--- a/pagure/api/user.py
+++ b/pagure/api/user.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2015 - Copyright Red Hat Inc
+ (c) 2015-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
@@ -13,7 +13,7 @@ import flask
 import pagure
 import pagure.exceptions
 import pagure.lib
-from pagure import APP, SESSION
+from pagure import SESSION
 from pagure.api import API, api_method, APIERROR
 
 
@@ -87,10 +87,6 @@ def api_view_user(username):
     except ValueError:
         forkpage = 1
 
-    limit = APP.config['ITEM_PER_PAGE']
-    repo_start = limit * (repopage - 1)
-    fork_start = limit * (forkpage - 1)
-
     repos = pagure.lib.search_projects(
         SESSION,
         username=username,

From fa85ee2605dfdd58dc3467bc0340c3b3dbf2355c Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 14/22] pep8 and pylint fixes to the pagure top module


---

diff --git a/pagure/__init__.py b/pagure/__init__.py
index ceb0a06..f9873b5 100644
--- a/pagure/__init__.py
+++ b/pagure/__init__.py
@@ -56,7 +56,7 @@ if APP.config.get('THEME_TEMPLATE_FOLDER', False):
     # That's what we do here
     template_folder = APP.config['THEME_TEMPLATE_FOLDER']
     if template_folder[0] != '/':
-        template_folder= os.path.join(
+        template_folder = os.path.join(
             APP.root_path, APP.template_folder, template_folder)
     import jinja2
     # Jinja looks for the template in the order of the folders specified
@@ -70,7 +70,7 @@ if APP.config.get('THEME_TEMPLATE_FOLDER', False):
 if APP.config.get('THEME_STATIC_FOLDER', False):
     static_folder = APP.config['THEME_STATIC_FOLDER']
     if static_folder[0] != '/':
-        static_folder= os.path.join(
+        static_folder = os.path.join(
             APP.root_path, 'static', static_folder)
     # Unlike templates, to serve static files from multiples folders we
     # need flask-multistatic
@@ -87,7 +87,7 @@ class RepoConverter(BaseConverter):
     :param map: the :class:`Map`.
     """
     regex = r'[^/]*(/[^/]+)?'
-    #weight = 200
+    # weight = 200
 
 
 APP.url_map.converters['repo'] = RepoConverter
@@ -418,7 +418,8 @@ def auth_login():  # pragma: no cover
         if not APP.config.get('ENABLE_GROUP_MNGT', False):
             groups = [
                 group.group_name
-                for group in pagure.lib.search_groups(SESSION, group_type='user')
+                for group in pagure.lib.search_groups(
+                    SESSION, group_type='user')
             ]
         groups = set(groups).union(admins)
         return FAS.login(return_url=return_point, groups=groups)
diff --git a/pagure/default_config.py b/pagure/default_config.py
index d9a497c..246d8df 100644
--- a/pagure/default_config.py
+++ b/pagure/default_config.py
@@ -221,8 +221,10 @@ ACLS = {
 }
 
 # Bootstrap URLS
-BOOTSTRAP_URLS_CSS = 'https://apps.fedoraproject.org/global/fedora-bootstrap-1.0.1/fedora-bootstrap.css'
-BOOTSTRAP_URLS_JS = 'https://apps.fedoraproject.org/global/fedora-bootstrap-1.0.1/fedora-bootstrap.js'
+BOOTSTRAP_URLS_CSS = 'https://apps.fedoraproject.org/global/' \
+    'fedora-bootstrap-1.0.1/fedora-bootstrap.css'
+BOOTSTRAP_URLS_JS = 'https://apps.fedoraproject.org/global/' \
+    'fedora-bootstrap-1.0.1/fedora-bootstrap.js'
 
 # List of the type of CI service supported by this pagure instance
 PAGURE_CI_SERVICES = []
diff --git a/pagure/docs_server.py b/pagure/docs_server.py
index dad385e..d2b5263 100644
--- a/pagure/docs_server.py
+++ b/pagure/docs_server.py
@@ -135,7 +135,6 @@ def view_docs(repo, username=None, filename=None):
 
     repo_obj = pygit2.Repository(reponame)
 
-
     if not repo_obj.is_empty:
         commit = repo_obj[repo_obj.head.target]
     else:
diff --git a/pagure/forms.py b/pagure/forms.py
index e23598b..cff4e58 100644
--- a/pagure/forms.py
+++ b/pagure/forms.py
@@ -30,14 +30,15 @@ def file_virus_validator(form, field):
         return
     from pyclamd import ClamdUnixSocket
 
-    if not field.name in flask.request.files or \
+    if field.name not in flask.request.files or \
             flask.request.files[field.name].filename == '':
         # If no file was uploaded, this field is correct
         return
     uploaded = flask.request.files[field.name]
     clam = ClamdUnixSocket()
     if not clam.ping():
-        raise wtforms.ValidationError('Unable to communicate with virus scanner')
+        raise wtforms.ValidationError(
+            'Unable to communicate with virus scanner')
     results = clam.scan_stream(uploaded.stream.read())
     if results is None:
         uploaded.stream.seek(0)
@@ -457,6 +458,7 @@ class DefaultBranchForm(wtf.Form):
                 (branch, branch) for branch in kwargs['branches']
             ]
 
+
 class EditCommentForm(wtf.Form):
     """ Form to verify that comment is not empty
     """

From 0653e692061c1b6d64c470b61d42eb6236b0c720 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 15/22] pep8 fixes to pagure.login_forms


---

diff --git a/pagure/login_forms.py b/pagure/login_forms.py
index dd0d631..c5e5a38 100644
--- a/pagure/login_forms.py
+++ b/pagure/login_forms.py
@@ -29,7 +29,8 @@ def same_password(form, field):
     ''' Check if the data in the field is the same as in the password field.
     '''
     if field.data != form.password.data:
-        raise wtforms.validators.ValidationError('Both password fields should be equal')
+        raise wtforms.validators.ValidationError(
+            'Both password fields should be equal')
 
 
 class LostPasswordForm(wtf.Form):
@@ -87,6 +88,7 @@ class NewUserForm(wtf.Form):
         [wtforms.validators.Required(), same_password]
     )
 
+
 class ChangePasswordForm(wtf.Form):
     """ Form to reset one's password in the local database. """
     old_password = wtforms.PasswordField(

From 2b091df9f78b8fd80873e290d4c90d0ab0a90c77 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 16/22] pep8 fixes to pagure.internal


---

diff --git a/pagure/internal/__init__.py b/pagure/internal/__init__.py
index 6185d77..46e8506 100644
--- a/pagure/internal/__init__.py
+++ b/pagure/internal/__init__.py
@@ -332,8 +332,7 @@ def get_pull_request_ready_branch():
 
 
 @PV.route('//issue/template', methods=['POST'])
-@PV.route('/fork///issue/template',
-           methods=['POST'])
+@PV.route('/fork///issue/template', methods=['POST'])
 def get_ticket_template(repo, username=None):
     """ Return the template asked for the specified project
     """
@@ -387,7 +386,7 @@ def get_ticket_template(repo, username=None):
                 bail_on_tree=True)
             if content_file:
                 content, _ = pagure.doc_utils.convert_readme(
-                        content_file.data, 'md')
+                    content_file.data, 'md')
     if content:
         response = flask.jsonify({
             'code': 'OK',

From b13b92d17d57666ec6f8d6e9cfcc4ae74d533002 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 17/22] Start pep8 fixes to pagure.lib


---

diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py
index 2bd4ca6..522281d 100644
--- a/pagure/lib/__init__.py
+++ b/pagure/lib/__init__.py
@@ -60,12 +60,14 @@ from pagure.lib import model
 REDIS = None
 PAGURE_CI = None
 
+
 def set_redis(host, port, dbname):
     """ Set the redis connection with the specified information. """
     global REDIS
     pool = redis.ConnectionPool(host=host, port=port, db=dbname)
     REDIS = redis.StrictRedis(connection_pool=pool)
 
+
 def set_pagure_ci(services):
     """ Set the list of CI services supported by this pagure instance. """
     global PAGURE_CI
@@ -872,7 +874,8 @@ def add_pull_request_comment(session, request, commit, tree_id, filename,
             'comment_id': pr_comment.id,
             'avatar_url': avatar_url_from_openid(
                 pr_comment.user.default_email, size=16),
-            'comment_date': pr_comment.date_created.strftime('%Y-%m-%d %H:%M:%S'),
+            'comment_date': pr_comment.date_created.strftime(
+                '%Y-%m-%d %H:%M:%S'),
             'commit_id': commit,
             'filename': filename,
             'line': row,
@@ -955,7 +958,8 @@ def edit_comment(session, parent, comment, user,
                 'comment_editor': user_obj.user,
                 'avatar_url': avatar_url_from_openid(
                     comment.user.default_email, size=16),
-                'comment_date': comment.edited_on.strftime('%Y-%m-%d %H:%M:%S'),
+                'comment_date': comment.edited_on.strftime(
+                    '%Y-%m-%d %H:%M:%S'),
             }))
 
     return "Comment updated"
@@ -1065,8 +1069,10 @@ def new_project(session, user, name, blacklist, allowed_prefix,
         temp_gitrepo_path = tempfile.mkdtemp(prefix='pagure-')
         temp_gitrepo = pygit2.init_repository(temp_gitrepo_path, bare=False)
         author = pygit2.Signature(
-            userobj.fullname.encode('utf-8') if six.PY2 else userobj.fullname,
-            userobj.default_email.encode('utf-8') if six.PY2 else userobj.fullname
+            userobj.fullname.encode('utf-8')
+            if six.PY2 else userobj.fullname,
+            userobj.default_email.encode('utf-8')
+            if six.PY2 else userobj.fullname
         )
         content = u"# %s\n\n%s" % (name, description)
         readme_file = os.path.join(temp_gitrepo.workdir, "README.md")
@@ -1414,7 +1420,7 @@ def fork_project(session, user, repo, gitfolder,
         hook_token=pagure.lib.login.id_generator(40)
     )
 
-    #disable issues, PRs in the fork by default
+    # disable issues, PRs in the fork by default
     default_repo_settings = project.settings
     default_repo_settings['issue_tracker'] = False
     default_repo_settings['pull_requests'] = False
@@ -2875,6 +2881,7 @@ def get_pull_request_of_user(session, username):
 
     return query.all()
 
+
 def update_watch_status(session, project, user, watch):
     ''' Update the user status for watching a project.
     '''
diff --git a/pagure/lib/git.py b/pagure/lib/git.py
index 1b720d4..90ef234 100644
--- a/pagure/lib/git.py
+++ b/pagure/lib/git.py
@@ -1127,7 +1127,6 @@ def merge_pull_request(
             shutil.rmtree(newpath)
             return 'MERGE'
 
-
     # Update status
     pagure.lib.close_pull_request(
         session, request, username,
diff --git a/pagure/lib/lib_ci.py b/pagure/lib/lib_ci.py
index 5d77e70..f976737 100644
--- a/pagure/lib/lib_ci.py
+++ b/pagure/lib/lib_ci.py
@@ -45,7 +45,8 @@ def process_jenkins_build(session, project, build_id, requestfolder):
     import jenkins
     # Jenkins Base URL
     jenk = jenkins.Jenkins(project.ci_hook[0].ci_url.split('/job/')[0])
-    jenkins_name = project.ci_hook[0].ci_url.split('/job/', 1)[1].split('/', 1)[0]
+    jenkins_name = project.ci_hook[0].ci_url.split(
+        '/job/', 1)[1].split('/', 1)[0]
     build_info = jenk.get_build_info(jenkins_name, build_id)
     result = build_info['result']
     url = build_info['url']

From f610bfc5e374319ac37ebc4b783f6730d696d1c0 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 18/22] Finish pep8 and pylint fixes to pagure.lib


---

diff --git a/pagure/lib/link.py b/pagure/lib/link.py
index 8749439..5236478 100644
--- a/pagure/lib/link.py
+++ b/pagure/lib/link.py
@@ -19,19 +19,25 @@ import pagure.exceptions
 
 FIXES = [
     re.compile(r'(?:.*\s+)?fixe?[sd]?:?\s*?#(\d+)', re.I),
-    re.compile(r'(?:.*\s+)?fixe?[sd]?:?\s*?https?://.*/(\w+)/(?:issue|pull-request)/(\d+)', re.I),
+    re.compile(
+        r'(?:.*\s+)?fixe?[sd]?:?\s*?https?://.*/(\w+)'
+        '/(?:issue|pull-request)/(\d+)', re.I),
     re.compile(r'(?:.*\s+)?merge?[sd]?:?\s*?#(\d+)', re.I),
-    re.compile(r'(?:.*\s+)?merge?[sd]?:?\s*?https?://.*/(\w+)/(?:issue|pull-request)/(\d+)', re.I),
+    re.compile(
+        r'(?:.*\s+)?merge?[sd]?:?\s*?https?://.*/(\w+)'
+        '/(?:issue|pull-request)/(\d+)', re.I),
     re.compile(r'(?:.*\s+)?close?[sd]?:?\s*?#(\d+)', re.I),
-    re.compile(r'(?:.*\s+)?close?[sd]?:?\s*?https?://.*/(\w+)/(?:issue|pull-request)/(\d+)', re.I),
+    re.compile(
+        r'(?:.*\s+)?close?[sd]?:?\s*?https?://.*/(\w+)'
+        '/(?:issue|pull-request)/(\d+)', re.I),
 ]
 
 RELATES = [
     re.compile(r'(?:.*\s+)?relate[sd]?:?\s*?(?:to)?\s*?#(\d+)', re.I),
     re.compile(r'(?:.*\s+)?relate[sd]?:?\s?#(\d+)', re.I),
     re.compile(
-        r'(?:.*\s+)?relate[sd]?:?\s*?(?:to)?\s*?https?://.*/(\w+)/issue/(\d+)',
-        re.I),
+        r'(?:.*\s+)?relate[sd]?:?\s*?(?:to)?\s*?'
+        'https?://.*/(\w+)/issue/(\d+)', re.I),
 ]
 
 
diff --git a/pagure/lib/model.py b/pagure/lib/model.py
index 25d7752..ba2b0da 100644
--- a/pagure/lib/model.py
+++ b/pagure/lib/model.py
@@ -106,7 +106,8 @@ def create_default_status(session, acls=None):
     """ Insert the defaults status in the status tables.
     """
 
-    for status in ['Open', 'Invalid', 'Insufficient data', 'Fixed', 'Duplicate']:
+    statuses = ['Open', 'Invalid', 'Insufficient data', 'Fixed', 'Duplicate']
+    for status in statuses:
         ticket_stat = StatusIssue(status=status)
         session.add(ticket_stat)
         try:
@@ -478,7 +479,6 @@ class Project(BASE):
             Issue.private == False
         ).count()
 
-
     def to_json(self, public=False, api=False):
         ''' Return a representation of the project as JSON.
         '''
@@ -633,7 +633,10 @@ class Issue(BASE):
     def user_comments(self):
         ''' Return user comments only, filter it from notifications
         '''
-        return [comment for comment in self.comments if not comment.notification]
+        return [
+            comment
+            for comment in self.comments
+            if not comment.notification]
 
     def to_json(self, public=False, with_comments=True):
         ''' Returns a dictionary representation of the issue.
@@ -773,8 +776,10 @@ class IssueComment(BASE):
             'parent': self.parent_id,
             'date_created': self.date_created.strftime('%s'),
             'user': self.user.to_json(public=public),
-            'edited_on': self.edited_on.strftime('%s') if self.edited_on else None,
-            'editor': self.editor.to_json(public=public) if self.editor_id else None,
+            'edited_on': self.edited_on.strftime('%s')
+            if self.edited_on else None,
+            'editor': self.editor.to_json(public=public)
+            if self.editor_id else None,
             'notification': self.notification,
         }
         return output
@@ -1033,7 +1038,10 @@ class PullRequest(BASE):
     def user_comments(self):
         ''' Return user comments only, filter it from notifications
         '''
-        return [comment for comment in self.comments if not comment.notification]
+        return [
+            comment
+            for comment in self.comments
+            if not comment.notification]
 
     def to_json(self, public=False, api=False, with_comments=True):
         ''' Returns a dictionnary representation of the pull-request.
@@ -1173,8 +1181,10 @@ class PullRequestComment(BASE):
             'parent': self.parent_id,
             'date_created': self.date_created.strftime('%s'),
             'user': self.user.to_json(public=public),
-            'edited_on': self.edited_on.strftime('%s') if self.edited_on else None,
-            'editor': self.editor.to_json(public=public) if self.editor_id else None,
+            'edited_on': self.edited_on.strftime('%s')
+            if self.edited_on else None,
+            'editor': self.editor.to_json(public=public)
+            if self.editor_id else None,
             'notification': self.notification,
         }
 
@@ -1349,10 +1359,8 @@ class ProjectGroup(BASE):
         primary_key=True)
 
     # Constraints
-    __table_args__ = (
-        sa.UniqueConstraint(
-            'project_id', 'group_id'),
-    )
+    __table_args__ = (sa.UniqueConstraint('project_id', 'group_id'),)
+
 
 class Watcher(BASE):
     """ Stores the user of a projects.
diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py
index 6c789ce..3b85667 100644
--- a/pagure/lib/notify.py
+++ b/pagure/lib/notify.py
@@ -194,14 +194,17 @@ def send_email(text, subject, to_mail,
         subject_tag = 'Pagure'
 
     if pagure.APP.config['SMTP_SSL']:
-        smtp = smtplib.SMTP_SSL(pagure.APP.config['SMTP_SERVER'], pagure.APP.config['SMTP_PORT'])
+        smtp = smtplib.SMTP_SSL(
+            pagure.APP.config['SMTP_SERVER'], pagure.APP.config['SMTP_PORT'])
     else:
-        smtp = smtplib.SMTP(pagure.APP.config['SMTP_SERVER'], pagure.APP.config['SMTP_PORT'])
+        smtp = smtplib.SMTP(
+            pagure.APP.config['SMTP_SERVER'], pagure.APP.config['SMTP_PORT'])
 
     for mailto in to_mail.split(','):
         msg = MIMEText(text.encode('utf-8'), 'plain', 'utf-8')
         msg['Subject'] = '[%s] %s' % (subject_tag, subject)
-        from_email = pagure.APP.config.get('FROM_EMAIL', 'pagure@fedoraproject.org')
+        from_email = pagure.APP.config.get(
+            'FROM_EMAIL', 'pagure@fedoraproject.org')
         msg['From'] = from_email
 
         if mail_id:
@@ -224,8 +227,12 @@ def send_email(text, subject, to_mail,
             mhash.hexdigest(),
             pagure.APP.config['DOMAIN_EMAIL_NOTIFICATIONS'])
         try:
-            if pagure.APP.config['SMTP_USERNAME'] and pagure.APP.config['SMTP_PASSWORD']:
-                smtp.login(pagure.APP.config['SMTP_USERNAME'], pagure.APP.config['SMTP_PASSWORD'])
+            if pagure.APP.config['SMTP_USERNAME'] \
+                    and pagure.APP.config['SMTP_PASSWORD']:
+                smtp.login(
+                    pagure.APP.config['SMTP_USERNAME'],
+                    pagure.APP.config['SMTP_PASSWORD']
+                )
 
             smtp.sendmail(
                 from_email,

From 11d3da763df240121b6605e3292e085b3c0a95aa Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon 
Date: Aug 29 2016 09:25:52 +0000
Subject: [PATCH 19/22] Start pep8 and pylint fixes to pagure.ui


---

diff --git a/pagure/ui/admin.py b/pagure/ui/admin.py
index 776f299..e458051 100644
--- a/pagure/ui/admin.py
+++ b/pagure/ui/admin.py
@@ -1,17 +1,20 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014-2015 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
 
 """
 
+# no-member
+# pylint: disable=E1101
+
+
 from functools import wraps
 
 import flask
-from sqlalchemy.exc import SQLAlchemyError
 
 import pagure.exceptions
 import pagure.forms
@@ -20,8 +23,6 @@ import pagure.lib.git
 from pagure import (APP, SESSION, generate_user_key_files,
                     is_admin, admin_session_timedout)
 
-# pylint: disable=E1101
-
 
 def admin_required(function):
     """ Flask decorator to retrict access to admins of pagure.
diff --git a/pagure/ui/app.py b/pagure/ui/app.py
index 17475fb..58133fa 100644
--- a/pagure/ui/app.py
+++ b/pagure/ui/app.py
@@ -84,7 +84,7 @@ def index_auth():
     try:
         repopage = int(repopage)
         if repopage < 1:
-            page = 1
+            repopage = 1
     except ValueError:
         repopage = 1
 
@@ -92,7 +92,7 @@ def index_auth():
     try:
         forkpage = int(forkpage)
         if forkpage < 1:
-            page = 1
+            forkpage = 1
     except ValueError:
         forkpage = 1
 
@@ -381,7 +381,7 @@ def new_project():
         create_readme = form.create_readme.data
 
         try:
-            message = pagure.lib.new_project(
+            pagure.lib.new_project(
                 SESSION,
                 name=name,
                 description=description,
diff --git a/pagure/ui/filters.py b/pagure/ui/filters.py
index 825c87f..a32c774 100644
--- a/pagure/ui/filters.py
+++ b/pagure/ui/filters.py
@@ -1,13 +1,21 @@
 # -*- coding: utf-8 -*-
 
 """
- (c) 2014 - Copyright Red Hat Inc
+ (c) 2014-2016 - Copyright Red Hat Inc
 
  Authors:
    Pierre-Yves Chibon 
 
 """
 
+# too-many-branches
+# pylint: disable=R0912
+# too-many-arguments
+# pylint: disable=R0913
+# too-many-locals
+# pylint: disable=R0914
+
+
 import datetime
 import textwrap
 
@@ -94,18 +102,19 @@ def format_loc(loc, commit=None, filename=None, tree_id=None, prequest=None,
         if filename and commit:
             output.append(
                 ''
-                ''
+                ''
                 ''
                 '

' - '' + '' '

' '' % ( { 'cnt': '%s_%s' % (index, cnt), 'cnt_lbl': cnt, - 'img': flask.url_for('static', filename='users.png'), 'filename': filename.decode('UTF-8'), 'commit': commit, 'tree_id': tree_id, @@ -115,7 +124,8 @@ def format_loc(loc, commit=None, filename=None, tree_id=None, prequest=None, else: output.append( '' - '' + '' % ( { 'cnt': '%s_%s' % (index, cnt), @@ -154,27 +164,30 @@ def format_loc(loc, commit=None, filename=None, tree_id=None, prequest=None, templ_delete = '' templ_edit = '' templ_edited = '' + status = str(comment.parent.status).lower() if authenticated() and ( - (str(comment.parent.status).lower() in ['true', 'open'] - and comment.user.user == flask.g.fas_user.username) - or is_repo_admin(comment.parent.project)): + ( + status in ['true', 'open'] + and comment.user.user == flask.g.fas_user.username + ) + or is_repo_admin(comment.parent.project)): templ_delete = tpl_delete % ({'commentid': comment.id}) - templ_edit = tpl_edit %({ + templ_edit = tpl_edit % ({ 'edit_url': flask.url_for( 'pull_request_edit_comment', repo=comment.parent.project.name, requestid=comment.parent.id, commentid=comment.id, - username=comment.parent.user.user \ - if comment.parent.project.is_fork else None + username=comment.parent.user.user + if comment.parent.project.is_fork else None ), 'requestid': comment.parent.id, 'commentid': comment.id, }) if comment.edited_on: - templ_edited = tpl_edited %({ - 'edit_date':comment.edited_on.strftime( + templ_edited = tpl_edited % ({ + 'edit_date': comment.edited_on.strftime( '%b %d %Y %H:%M:%S'), 'human_edit_date': humanize_date(comment.edited_on), 'user': comment.editor.user, @@ -199,7 +212,8 @@ def format_loc(loc, commit=None, filename=None, tree_id=None, prequest=None, '' '
' '%(templ_edited)s' - '