diff --git a/jupyterlab_pullrequests/base.py b/jupyterlab_pullrequests/base.py index 80703c1..d9fe7c9 100644 --- a/jupyterlab_pullrequests/base.py +++ b/jupyterlab_pullrequests/base.py @@ -8,12 +8,13 @@ class CommentReply(NamedTuple): """Comment reply - + Attributes: text: Comment body filename: Targeted filename; None if the comment is for the pull request inReplyTo: ID of the comment of the discussion or the comment to which this one reply """ + text: str filename: Optional[str] inReplyTo: str @@ -21,13 +22,14 @@ class CommentReply(NamedTuple): class NewComment(NamedTuple): """New comment - + Attributes: text: Comment body filename: Targeted filename; None if the comment is for the pull request line: Commented line number (in the new version) originalLine: Commented line number (in the original version) """ + text: str filename: Optional[str] line: Optional[int] @@ -50,7 +52,7 @@ class PRConfig(Configurable): help="Base URL of the versioning service REST API.", ) - @default('api_base_url') + @default("api_base_url") def set_default_api_base_url(self): if self.provider == "gitlab": return "https://gitlab.com/api/v4/" diff --git a/jupyterlab_pullrequests/handlers.py b/jupyterlab_pullrequests/handlers.py index f37ffa7..721e959 100644 --- a/jupyterlab_pullrequests/handlers.py +++ b/jupyterlab_pullrequests/handlers.py @@ -32,7 +32,7 @@ class PullRequestsAPIHandler(APIHandler): def initialize(self, manager: PullRequestsManager, logger: logging.Logger): self._jp_log = logger - self._manager = manager + self._manager = manager def write_error(self, status_code, **kwargs): """ @@ -243,7 +243,11 @@ def setup_handlers(web_app: "NotebookWebApplication", config: PRConfig): web_app.add_handlers( host_pattern, [ - (url_path_join(base_url, pat), handler, {"logger": logger, "manager": manager}) + ( + url_path_join(base_url, pat), + handler, + {"logger": logger, "manager": manager}, + ) for pat, handler in default_handlers ], ) diff --git a/jupyterlab_pullrequests/managers/github.py b/jupyterlab_pullrequests/managers/github.py index 351f62e..c1645d5 100644 --- a/jupyterlab_pullrequests/managers/github.py +++ b/jupyterlab_pullrequests/managers/github.py @@ -131,9 +131,9 @@ async def get_threads( "id": thread[-1]["id"], # Set discussion id as the last comment id "comments": [GitHubManager._response_to_comment(c) for c in thread], "filename": filename, - "line": thread[0]["position"], - "originalLine": thread[0]["original_position"] - if thread[0]["position"] is None + "line": thread[0]["line"], + "originalLine": thread[0]["original_line"] + if thread[0]["line"] is None else None, "pullRequestId": pr_id, } @@ -212,9 +212,9 @@ async def post_comment( filename = body.filename if filename is None: # Concept of reply does not exist at pull request level in GitHub - data = {"body": body.text} + data = {"body": body.text} git_url = git_url.replace("pulls", "issues") - + else: if isinstance(body, CommentReply): data = {"body": body.text, "in_reply_to": body.inReplyTo} @@ -228,7 +228,7 @@ async def post_comment( } response = await self._call_github(git_url, method="POST", body=data) - + return GitHubManager._response_to_comment(response) async def _call_github( diff --git a/jupyterlab_pullrequests/managers/manager.py b/jupyterlab_pullrequests/managers/manager.py index 3d81110..e2a5d6f 100644 --- a/jupyterlab_pullrequests/managers/manager.py +++ b/jupyterlab_pullrequests/managers/manager.py @@ -199,7 +199,7 @@ async def _call_provider( else "{}" ) self.log.debug(error_body) - try: + try: message = json.loads(error_body).get("message", str(e)) except json.JSONDecodeError: message = str(e) diff --git a/jupyterlab_pullrequests/tests/sample_responses/github/github_comments_get.json b/jupyterlab_pullrequests/tests/sample_responses/github/github_comments_get.json index e9b8fd9..855b2bd 100644 --- a/jupyterlab_pullrequests/tests/sample_responses/github/github_comments_get.json +++ b/jupyterlab_pullrequests/tests/sample_responses/github/github_comments_get.json @@ -46,7 +46,9 @@ "pull_request": { "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } - } + }, + "line": 4, + "original_line": 4 }, { "url": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/comments/296364299", @@ -95,7 +97,9 @@ "pull_request": { "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } - } + }, + "line": 9, + "original_line": 9 }, { "url": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/comments/296364357", @@ -144,7 +148,9 @@ "pull_request": { "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } - } + }, + "line": 2, + "original_line": 2 }, { "url": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/comments/296375528", @@ -194,6 +200,8 @@ "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } }, + "line": 2, + "original_line": 2, "in_reply_to_id": 296364357 }, { @@ -244,6 +252,8 @@ "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } }, + "line": 4, + "original_line": 4, "in_reply_to_id": 296362189 }, { @@ -294,6 +304,8 @@ "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } }, + "line": 2, + "original_line": 2, "in_reply_to_id": 296364357 }, { @@ -344,6 +356,8 @@ "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } }, + "line": 4, + "original_line": 4, "in_reply_to_id": 296362189 }, { @@ -394,6 +408,8 @@ "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } }, + "line": 4, + "original_line": 4, "in_reply_to_id": 296362189 }, { @@ -444,6 +460,8 @@ "href": "https://api.github.com/repos/timnlupo/juypterlabpr-test/pulls/1" } }, + "line": 2, + "original_line": 2, "in_reply_to_id": 296364357 } ] \ No newline at end of file