Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiline comments in PullRequest #2540

Merged
merged 27 commits into from Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e3efd64
fix(PullRequest.create_comment): add multiline comment
heitorpolidoro May 31, 2023
b4f6dae
fix(PullRequest.create_comment): fix and create tests
heitorpolidoro May 31, 2023
71ce75e
fix(PullRequest.create_comment): lint
heitorpolidoro May 31, 2023
84bd203
fix(PullRequest.create_comment): lint
heitorpolidoro May 31, 2023
d559f6d
Update github/PullRequest.py
heitorpolidoro Jun 14, 2023
bd00108
Update github/PullRequest.py
heitorpolidoro Jun 14, 2023
28eb82b
Fix broken urls in docstrings (#2393)
Muscaw Jun 1, 2023
1bc6179
Add `name`, `display_title` and `path` attributes to `WorkflowRun` (#…
nuang-ee Jun 1, 2023
2d5933f
Add `name` filter to `Repository.get_artifacts()` (#2459)
trim21 Jun 1, 2023
f00b0be
Merging 1.58.x patch release notes into master (#2525)
EnricoMi Jun 1, 2023
fe2525a
Add sort order and direction for getting comments (#2544)
EnricoMi Jun 7, 2023
8b27cc5
Add authentication classes, move auth logic there (#2528)
EnricoMi Jun 8, 2023
14e902e
Make `MainClass.get_app` return completed `GithubApp` when slug is gi…
EnricoMi Jun 8, 2023
cb13705
Add support for new RepositoryAdvisories API :tada: (#2483)
JLLeitschuh Jun 9, 2023
1e16ae0
Fix auth issues with `Installation.get_repos` (#2547)
EnricoMi Jun 13, 2023
6a41b40
Make Requester.__createException robust against missing message and b…
EnricoMi Jun 13, 2023
cc6a627
Add support for environments (#2223)
alson Jun 13, 2023
c504fb8
Implement `AppUserAuth` for Github App user tokens (#2546)
EnricoMi Jun 14, 2023
41c79dd
feat(PullRequest.create_review_comment): new parameters and better te…
heitorpolidoro Jun 14, 2023
7543301
Merge branch 'master' into fix_create_comment_issues
heitorpolidoro Jun 14, 2023
18a9e57
style(PullRequest.create_review_comment): fixing lint errors
heitorpolidoro Jun 14, 2023
69f85a3
Merge branch 'master' into fix_create_comment_issues
heitorpolidoro Jun 14, 2023
7feb50c
Update github/PullRequest.py
heitorpolidoro Jun 15, 2023
10254c2
fix(PullRequest.create_review_comment): Change default from None to N…
heitorpolidoro Jun 15, 2023
f9196de
fix(PullRequest.create_review_comment): Change default from None to N…
heitorpolidoro Jun 15, 2023
6453e32
style(PullRequest.create_review_comment): minor changes
heitorpolidoro Jun 15, 2023
50f5398
style(PullRequest.create_review_comment): lint
heitorpolidoro Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions github/PullRequest.py
Expand Up @@ -409,25 +409,36 @@ def create_comment(self, body, commit_id, path, position):
"""
return self.create_review_comment(body, commit_id, path, position)
heitorpolidoro marked this conversation as resolved.
Show resolved Hide resolved

def create_review_comment(self, body, commit_id, path, position):
def create_review_comment(
self, body, commit, path, line, start_line=None, as_suggestion=False
):
heitorpolidoro marked this conversation as resolved.
Show resolved Hide resolved
"""
:calls: `POST /repos/{owner}/{repo}/pulls/{number}/comments <https://docs.github.com/en/rest/reference/pulls#review-comments>`_
:param body: string
:param commit_id: :class:`github.Commit.Commit`
:param commit: :class:`github.Commit.Commit`
heitorpolidoro marked this conversation as resolved.
Show resolved Hide resolved
:param path: string
:param position: integer
:param line: integer
:param start_line: integer
:param as_suggestion: bool
heitorpolidoro marked this conversation as resolved.
Show resolved Hide resolved
:rtype: :class:`github.PullRequestComment.PullRequestComment`
"""
assert isinstance(body, str), body
assert isinstance(commit_id, github.Commit.Commit), commit_id
assert isinstance(commit, github.Commit.Commit), commit
assert isinstance(path, str), path
assert isinstance(position, int), position
assert isinstance(line, int), line
assert start_line is None or isinstance(start_line, int), start_line
assert isinstance(as_suggestion, bool), as_suggestion

if as_suggestion:
body = f"```suggestion\n{body}\n```"
post_parameters = {
"body": body,
"commit_id": commit_id._identity,
"commit_id": commit._identity,
"path": path,
"position": position,
"line": line,
}
if start_line is not None:
post_parameters["start_line"] = start_line
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/comments", input=post_parameters
)
Expand Down
14 changes: 14 additions & 0 deletions tests/PullRequest.py
Expand Up @@ -154,6 +154,20 @@ def testCreateComment(self):
)
self.assertEqual(comment.id, 886298)

def testCreateMultilineReviewComment(self):
commit = self.repo.get_commit("8a4f306d4b223682dd19410d4a9150636ebe4206")
comment = self.pull.create_review_comment(
"Comment created by PyGithub", commit, "src/github/Issue.py", 10, 5
)
self.assertEqual(comment.id, 886298)

def testCreateMultilineReviewCommentAsSuggestion(self):
commit = self.repo.get_commit("8a4f306d4b223682dd19410d4a9150636ebe4206")
comment = self.pull.create_review_comment(
"Comment created by PyGithub", commit, "src/github/Issue.py", 10, 5, True
)
self.assertEqual(comment.id, 886298)

heitorpolidoro marked this conversation as resolved.
Show resolved Hide resolved
def testGetComments(self):
self.assertListKeyEqual(self.pull.get_comments(), lambda c: c.id, [886298])

Expand Down
4 changes: 2 additions & 2 deletions tests/ReplayData/PullRequest.testCreateComment.txt
Expand Up @@ -15,8 +15,8 @@ api.github.com
None
/repos/jacquev6/PyGithub/pulls/31/comments
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"body": "Comment created by PyGithub", "commit_id": "8a4f306d4b223682dd19410d4a9150636ebe4206", "position": 5, "path": "src/github/Issue.py"}
{"body": "Comment created by PyGithub", "commit_id": "8a4f306d4b223682dd19410d4a9150636ebe4206", "line": 5, "path": "src/github/Issue.py"}
201
[('status', '201 Created'), ('x-ratelimit-remaining', '4953'), ('content-length', '937'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"7ca841d45253326d61bee20c809872dc"'), ('date', 'Sun, 27 May 2012 09:40:12 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/pulls/comments/886298')]
{"updated_at":"2012-05-27T09:40:12Z","position":5,"original_position":5,"body":"Comment created by PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub/pulls/comments/886298","commit_id":"8a4f306d4b223682dd19410d4a9150636ebe4206","created_at":"2012-05-27T09:40:12Z","user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"original_commit_id":"8a4f306d4b223682dd19410d4a9150636ebe4206","path":"src/github/Issue.py","id":886298,"_links":{"self":{"href":"https://api.github.com/repos/jacquev6/PyGithub/pulls/comments/886298"},"html":{"href":"https://github.com/jacquev6/PyGithub/pull/31#r886298"},"pull_request":{"href":"https://api.github.com/repos/jacquev6/PyGithub/pulls/31"}}}
{"updated_at":"2012-05-27T09:40:12Z","line":5,"original_position":5,"body":"Comment created by PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub/pulls/comments/886298","commit_id":"8a4f306d4b223682dd19410d4a9150636ebe4206","created_at":"2012-05-27T09:40:12Z","user":{"url":"https://api.github.com/users/jacquev6","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146},"original_commit_id":"8a4f306d4b223682dd19410d4a9150636ebe4206","path":"src/github/Issue.py","id":886298,"_links":{"self":{"href":"https://api.github.com/repos/jacquev6/PyGithub/pulls/comments/886298"},"html":{"href":"https://github.com/jacquev6/PyGithub/pull/31#r886298"},"pull_request":{"href":"https://api.github.com/repos/jacquev6/PyGithub/pulls/31"}}}