From d3ffbe63a88b4bf69c12c58d23ea130f0cd0ddfa Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 06 2018 10:16:44 +0000 Subject: [PATCH 1/3] Fix the link on the new ticket button It was adding the user's username thus making the link point to a fork even if the project wasn't a fork Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/repo_master.html b/pagure/templates/repo_master.html index e0d5bea..a89c34e 100644 --- a/pagure/templates/repo_master.html +++ b/pagure/templates/repo_master.html @@ -86,9 +86,9 @@ and config.get('ENABLE_TICKETS', True) and not repo.settings.get('issue_tracker_read_only', False) %} New issue {% endif %} From a8e1a65ddf1a75a3614824a9ba3bca55510b3df6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 06 2018 10:16:44 +0000 Subject: [PATCH 2/3] Fix activating and deactivating a hook (esp the ticket-hook) Previously the ticket-hook would raise a 404 error itself, making the code in the hook controller section by-passed and thus not allowing to rollback the session, practically practically rendering pagure stuck on a DB error (especially with RDBMS such as sqlite). With this commit, the ticket-hook now raises an exception that the controller catches and process as desired (rollback the DB session, raise the corresponding http error). This fix came with a few other changes found while debugging this issue, such as the session not being rollbacked for other exceptions. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/pagure_ticket_hook.py b/pagure/hooks/pagure_ticket_hook.py index f609fe0..acd9187 100644 --- a/pagure/hooks/pagure_ticket_hook.py +++ b/pagure/hooks/pagure_ticket_hook.py @@ -12,7 +12,6 @@ from __future__ import unicode_literals import os -import flask import sqlalchemy as sa import wtforms @@ -26,6 +25,7 @@ from sqlalchemy.orm import backref import pagure.lib.git import pagure.lib.tasks_services from pagure.config import config as pagure_config +from pagure.exceptions import FileNotFoundException from pagure.hooks import BaseHook, BaseRunner from pagure.lib.model import BASE, Project @@ -133,7 +133,7 @@ class PagureTicketHook(BaseHook): """ repopath = os.path.join(pagure_config["TICKETS_FOLDER"], project.path) if not os.path.exists(repopath): - flask.abort(404, "No git repo found") + raise FileNotFoundException('No such file: %s' % repopath) hook_files = os.path.join( os.path.dirname(os.path.realpath(__file__)), "files" diff --git a/pagure/ui/plugins.py b/pagure/ui/plugins.py index fd79a06..72d92b8 100644 --- a/pagure/ui/plugins.py +++ b/pagure/ui/plugins.py @@ -21,8 +21,8 @@ from flask import Markup from sqlalchemy.exc import SQLAlchemyError import pagure.exceptions -import pagure.lib.plugins import pagure.forms +import pagure.lib.plugins from pagure.exceptions import FileNotFoundException from pagure.ui import UI_NS from pagure.utils import login_required @@ -152,23 +152,25 @@ def view_plugin(repo, plugin, username=None, namespace=None, full=True): form.active.data = True if form.active.data: - # Set up the main script if necessary - plugin.set_up(repo) - # Install the plugin itself try: + # Set up the main script if necessary + plugin.set_up(repo) + # Install the plugin itself plugin.install(repo, dbobj) flask.flash("Hook %s activated" % plugin.name) except FileNotFoundException as err: + flask.g.session.rollback() _log.exception(err) flask.abort(404, "No git repo found") else: try: plugin.remove(repo) - flask.g.session.delete(dbobj) - flask.flash("Hook %s deactivated" % plugin.name) except FileNotFoundException as err: + flask.g.session.rollback() _log.exception(err) flask.abort(404, "No git repo found") + flask.g.session.delete(dbobj) + flask.flash("Hook %s deactivated" % plugin.name) flask.g.session.commit() From ee649a904346563d8dd3e4a54c7ca594dfd5206a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 06 2018 10:17:14 +0000 Subject: [PATCH 3/3] Code style / black fixes Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/default_config.py b/pagure/default_config.py index e24f523..179787c 100644 --- a/pagure/default_config.py +++ b/pagure/default_config.py @@ -381,7 +381,7 @@ TRIGGER_CI = { "name": "Default CI", "description": "Rerun default CI", "requires_project_hook_attr": ("ci_hook", "active_pr", True), - }, + } } FLAG_STATUSES_LABELS = { diff --git a/pagure/hooks/pagure_ticket_hook.py b/pagure/hooks/pagure_ticket_hook.py index acd9187..eb48397 100644 --- a/pagure/hooks/pagure_ticket_hook.py +++ b/pagure/hooks/pagure_ticket_hook.py @@ -133,7 +133,7 @@ class PagureTicketHook(BaseHook): """ repopath = os.path.join(pagure_config["TICKETS_FOLDER"], project.path) if not os.path.exists(repopath): - raise FileNotFoundException('No such file: %s' % repopath) + raise FileNotFoundException("No such file: %s" % repopath) hook_files = os.path.join( os.path.dirname(os.path.realpath(__file__)), "files" diff --git a/pagure/lib/plugins.py b/pagure/lib/plugins.py index f04f621..1859053 100644 --- a/pagure/lib/plugins.py +++ b/pagure/lib/plugins.py @@ -34,7 +34,8 @@ def get_plugin_names(blacklist=None, without_backref=False): blacklist = [blacklist] output = [ - plugin.name for plugin in plugins + plugin.name + for plugin in plugins if plugin.name not in blacklist and (plugin.backref or without_backref) ] # The default hook is not one we show diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index c47369b..1527430 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -956,20 +956,21 @@ def reopen_request_pull(repo, requestid, username=None, namespace=None): @UI_NS.route( - "//pull-request//trigger-ci", - methods=["POST"] + "//pull-request//trigger-ci", methods=["POST"] ) @UI_NS.route( "///pull-request//trigger-ci", - methods=["POST"] + methods=["POST"], ) @UI_NS.route( "/fork///pull-request//trigger-ci", methods=["POST"], ) @UI_NS.route( - ("/fork////pull-request/" - "/trigger-ci"), + ( + "/fork////pull-request/" + "/trigger-ci" + ), methods=["POST"], ) @login_required