Bug 561656 - CommitComment has default line 0 which now causes request failure
Summary: CommitComment has default line 0 which now causes request failure
Status: NEW
Alias: None
Product: EGit
Classification: Technology
Component: GitHub (show other bugs)
Version: 5.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2020-04-01 13:36 EDT by Carmen Alvarez CLA
Modified: 2020-04-04 10:28 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carmen Alvarez CLA 2020-04-01 13:36:23 EDT
This issue started occurring today.


If you try to post a comment to a PR and don't specify the line, CommitComment uses a line of 0, and github now returns an error.

Groovy code snippet:

    CommitComment commitComment = new CommitComment()
    commitComment.setCommitId(commitId)
    commitComment.setPath("path/to/file.kt")
    commitComment.setPosition(36)
    commitComment.setBody("Hello there")

    def gitHubClient = new GitHubClient()
    gitHubClient.setOAuth2Token(token)
    def repositoryId = new RepositoryId(orgName, repoName)
    def pullRequestService = new PullRequestService(gitHubClient)
    def pullRequestId = 123
    pullRequestService.createComment(repositoryId, pullRequestId, commitComment)

This fails with:

Caused by: org.eclipse.egit.github.core.client.RequestException: Validation Failed (422): line required and an integer greater than zero
        at org.eclipse.egit.github.core.client.GitHubClient.createException(GitHubClient.java:606)
        at org.eclipse.egit.github.core.client.GitHubClient.sendJson(GitHubClient.java:697)
        at org.eclipse.egit.github.core.client.GitHubClient.post(GitHubClient.java:816)
        at org.eclipse.egit.github.core.service.PullRequestService.createComment(PullRequestService.java:494)
        at org.eclipse.egit.github.core.service.PullRequestService$createComment$2.call(Unknown Source)
        at MyScript.postPrComment(/path/to/MyScript.gradle:65)

If you add commitComment.setLine(someLine), it works.

Note that if you use the curl apis, you can either leave the line out altogether, or specify a non-zero line. But, in curl, if you specify a line of 0, it also fails.


Works (no line):
curl --request POST -H "Content-Type: application/json" -H "Authorization: token "sometoken" https://api.github.com/repos/orgName/repoName/pulls/123/comments --data '{"body":"hello world","path":"path/to/file.kt","position":3, commit_id":"1234567"}'


Doesn't work anymore (line is 0):
curl --request POST -H "Content-Type: application/json" -H "Authorization: token "sometoken" https://api.github.com/repos/orgName/repoName/pulls/123/comments --data '{"body":"hello world","path":"path/to/file.kt","position":3, "commit_id":"1234567", "line":0}'


Error:
{
  "message": "Validation Failed",
  "errors": [
    {
      "resource": "PullRequestReviewComment",
      "code": "custom",
      "field": "line",
      "message": "line required and an integer greater than zero"
    }
  ],
  "documentation_url": "https://developer.github.com/v3/pulls/comments/#create-a-comment"
}
Comment 1 Thomas Wolf CLA 2020-04-04 10:28:07 EDT
Looks like that CommitComment class lacks more, for instance "side". Line numbers seem to start at 1, so not serializing zeroes could be done by using Integer instead of primitive int and setting to null if zero, or using a special @JsonAdapter for the field.

Contributions are welcome!