Skip to content

Commit

Permalink
fix github text position (#26)
Browse files Browse the repository at this point in the history
* Fix comment position for GitHub plain text

* blacken
  • Loading branch information
fcollonval committed Mar 8, 2021
1 parent f4a423e commit dd824a5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
8 changes: 5 additions & 3 deletions jupyterlab_pullrequests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@

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


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]
Expand All @@ -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/"
Expand Down
8 changes: 6 additions & 2 deletions jupyterlab_pullrequests/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
],
)
12 changes: 6 additions & 6 deletions jupyterlab_pullrequests/managers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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}
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion jupyterlab_pullrequests/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
},
{
Expand Down Expand Up @@ -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
},
{
Expand Down Expand Up @@ -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
},
{
Expand Down Expand Up @@ -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
},
{
Expand Down Expand Up @@ -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
},
{
Expand Down Expand Up @@ -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
}
]

0 comments on commit dd824a5

Please sign in to comment.