Open yigitcanyurtsever opened 5 years ago
Were those comments in the diff? GitHub's API doesn't let you make comments on any random files in the repo - they have to live on the diff in the PR.
Thanks for looking into it @orta 🙌
Yes, all three files were created/added on the same commit and were part of the diff.
When I was debugging the issue, I also tried adding comments that were not part of the diff. When they are not part of the diff, Github returns a "invalid position" validation error. The response looks like this:
Response: {
"message": "Validation Failed",
"errors": [
{
"resource": "PullRequestReviewComment",
"code": "invalid",
"field": "position"
}
],
"documentation_url": "https://developer.github.com/v3/pulls/comments/#create-a-comment"
}
These ones on the other hand, returns a "pull_request_review_id must be pending". Here's how it looks:
Response: {
"message": "Validation Failed",
"errors": [
{
"resource": "PullRequestReviewComment",
"code": "custom",
"field": "pull_request_review_id",
"message": "pull_request_review_id must be pending"
}
],
"documentation_url": "https://developer.github.com/v3/pulls/comments/#create-a-comment"
}
I couldn't find any documentation for these errors on Github. My only guess is that, when danger is trying to make inline comments, it sends out the review immediately after making the first comment. The rest of the comments receive a validation error because the review was already sent and it's not in "pending" state anymore. Although, If this was the case, it would be a really common issue that other people also run into. So, I'm thinking we are doing some other things that trigger this early review sending for us.
I'm also running into a similar issue, with danger-js. I get these warnings:
Found only warnings, not failing the build.
Request failed [422]: https://api.github.com/repos/next-insurance/skyscraper/pulls/17831/comments
Response: {
"message": "Validation Failed",
"errors": [
{
"resource": "PullRequestReviewComment",
"code": "custom",
"field": "pull_request_review_id",
"message": "pull_request_review_id must be pending"
}
],
"documentation_url": "https://developer.github.com/v3/pulls/comments/#create-a-comment"
}
Feedback: https://github.com/next-insurance/skyscraper/pull/17831#issuecomment-664449196
My setup -
I have a jenkins job that polls my private repository (it's a commercial company),
and runs Danger, with a github-bot.
I pass the token via DANGER_GITHUB_API_TOKEN
.
I've tried setting the bot's id via PERIL_BOT_USER_ID
(tried to follow these instructions by @orta ) - it didn't make a difference.
@yigitcanyurtsever 's theory sounds logical to me. I was hoping maybe this issue was solved by now... I'm still investigating mine.
I've turned DEBUG
on (set the environment variable DEBUG
to *
), to get more information, and it seems like:
PERIL_BOT_USER_ID
to the bot's id did nothing - see danger:GitHubAPI User ID: NaN
So I'm suspecting this has to do with getUserID
returning NaN, and that it does because I'm using a bot instead of a regular user.Here's the log from my Jenkins run of Danger-JS:
18:29:47 2020-07-27T15:29:47.591Z danger:GitHub::Issue Position found for inline comment: blah blah blah...
18:29:47 2020-07-27T15:29:47.592Z danger:GitHubAPI Sending: https://api.github.com/repos/next-insurance/skyscraper/pulls/17831/comments {
18:29:47 'Content-Type': 'application/json',
18:29:47 Authorization: 'token ****'
18:29:47 }
18:29:47 2020-07-27T15:29:47.593Z danger:GitHubAPI Sending: https://api.github.com/repos/next-insurance/skyscraper/pulls/17831/comments {
18:29:47 'Content-Type': 'application/json',
18:29:47 Authorization: 'token ****'
18:29:47 }
18:29:48 Request failed [422]: https://api.github.com/repos/next-insurance/skyscraper/pulls/17831/comments
18:29:48 Response: {
18:29:48 "message": "Validation Failed",
18:29:48 "errors": [
18:29:48 {
18:29:48 "resource": "PullRequestReviewComment",
18:29:48 "code": "custom",
18:29:48 "field": "pull_request_review_id",
18:29:48 "message": "pull_request_review_id must be pending"
18:29:48 }
18:29:48 ],
18:29:48 "documentation_url": "https://developer.github.com/v3/pulls/comments/#create-a-comment"
18:29:48 }
18:29:48 2020-07-27T15:29:48.474Z danger:GitHubAPI getPullRequestCommits:: Sending pull request commit request for first page
18:29:48 2020-07-27T15:29:48.474Z danger:GitHubAPI getPullRequestCommits:: Request url generated "repos/next-insurance/skyscraper/issues/17831/comments"
18:29:48 2020-07-27T15:29:48.474Z danger:GitHubAPI Sending: https://api.github.com/repos/next-insurance/skyscraper/issues/17831/comments {
18:29:48 'Content-Type': 'application/json',
18:29:48 Authorization: 'token ****'
18:29:48 }
18:29:48 2020-07-27T15:29:48.719Z danger:GitHubAPI getNextPageFromLinkHeader:: Given response does not contain link header for pagination
18:29:48 2020-07-27T15:29:48.719Z danger:GitHubAPI User ID: NaN
18:29:48 2020-07-27T15:29:48.719Z danger:GitHubAPI Looking at 1 comments for DangerID: danger-id-Danger;
18:29:48 2020-07-27T15:29:48.719Z danger:GitHub::Issue Creating new comment
18:29:48 2020-07-27T15:29:48.719Z danger:GitHubAPI Sending: https://api.github.com/repos/next-insurance/skyscraper/issues/17831/comments {
18:29:48 'Content-Type': 'application/json',
18:29:48 Authorization: 'token ****'
18:29:48 }
18:29:49 Feedback: https://github.com/next-insurance/skyscraper/pull/17831#issuecomment-664466380
18:29:49 2020-07-27T15:29:49.551Z danger:GitHubAPI Sending: https://api.github.com/repos/next-insurance/skyscraper/statuses/1e08eb352b498dee932c00fce380c74470626a1b {
18:29:49 'Content-Type': 'application/json',
18:29:49 Authorization: 'token ****'
18:29:49 }
P.S: Hope it's OK I'm posting here, even though I'm using danger-js and not swift. I came here when searching for the error message. Plus, I think if we solve this, the solution may apply to swift as well.
I've fixed the PERIL_BOT_USER_ID
, but it didn't solve the issue.
I'm still getting these errors from the second inline-comment and on.
At least fixing PERIL_BOT_USER_ID
fixed another issue - now Danger updates its summary comment, instead of creating a new one every run.
How I've fixed my PERIL_BOT_USER_ID
(for anyone who comes across this)
When I was looking for user.id
to put in PERIL_BOT_USER_ID
, I was using GitHub GraphQL API, which uses a different API than Danger-JS.
So I didn't know what field to look for.
It's not user.id
- first, there's no user
in this API version, there's author
. second - author.id
is not numeric - it's a GUID.
Eventually I realized the field I was looking for was databaseId
, which is numeric.
Hi, how about this issue?
I'm still having this issue
It opens a review for the first review comment you add. You have to await that call before adding more comments. Otherwise, you end up with a race condition where it tries to add more comments while the review is still getting set up.
Hello,
I was testing out the SwiftLint plugin with Danger Swift for our PRs. I created a sample PR with 3 new files with some violations in each of them. Danger was able to add only 1 inline comment and the rest was displayed in general results comment. Here's how it looks:
Some details:
I'm attaching the full debug output from our CI as well. I'm not sure if this is a danger-js issue or a danger-swift one. Let me know if I can provide more details.