Skip to content

Commit

Permalink
Pull more redesign from jupyterlab#44
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Apr 19, 2021
1 parent 890ad3c commit 67a0657
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions jupyterlab_pullrequests/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import traceback
from typing import Optional
from http import HTTPStatus

import tornado
Expand Down Expand Up @@ -198,26 +199,33 @@ def get_body_value(handler):
]


def setup_handlers(web_app: "NotebookWebApplication", config: PRConfig):
def setup_handlers(web_app: tornado.web.Application, config: PRConfig, log: Optional[logging.Logger]=None):
host_pattern = ".*$"
base_url = url_path_join(web_app.settings["base_url"], NAMESPACE)

logger = get_logger()
log = log or logging.getLogger(__name__)

manager_class = MANAGERS.get(config.provider)
if manager_class is None:
logger.error(f"No manager defined for provider '{config.provider}'.")
log.error(f"PR Manager: No manager defined for provider '{config.provider}'.")
raise NotImplementedError()
manager = manager_class(config)

web_app.add_handlers(
host_pattern,
[
(
url_path_join(base_url, pat),
handler,
{"logger": logger, "manager": manager},
)
for pat, handler in default_handlers
],
)
log.info(f"PR Manager Class {manager_class}")
try:
manager = manager_class(config)
except Exception as err:
import traceback
logging.error("PR Manager Exception", exc_info=1)
raise err

handlers = [
(
url_path_join(base_url, pat),
handler,
{"logger": log, "manager": manager},
)
for pat, handler in default_handlers
]

log.debug(f"PR Handlers: {handlers}")

web_app.add_handlers(host_pattern, handlers)

0 comments on commit 67a0657

Please sign in to comment.