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

Is Danger always making a new comment? #856

Closed
orta opened this issue Apr 9, 2019 · 26 comments · Fixed by #1013
Closed

Is Danger always making a new comment? #856

orta opened this issue Apr 9, 2019 · 26 comments · Fixed by #1013

Comments

@orta
Copy link
Member

orta commented Apr 9, 2019

I keep seeing notifications in Slack about new comments by Danger, when they should be being edited.

@jmenestr
Copy link
Contributor

I am also seeing this. I'm using 9.2.2 and currently see a new comment.

I can inspect each comment's markdown and see the same dangerid for each comment.

I was also under the impression that it should search all the comments for ones with the same dangerid and update them, rather than create a new one.

@tamlenguyen
Copy link

Same for me, adding a new comment every time

@nick28
Copy link

nick28 commented Dec 1, 2019

Same for me in Bitbucket Cloud, any updates or any leads how can we solve this?

@orta
Copy link
Member Author

orta commented Dec 1, 2019

Each platform has a updateOrCreateComment which must not be doing what we expect

@HelloCore
Copy link
Member

Same for me in Bitbucket Cloud, any updates or any leads how can we solve this?

For Bitbucket Cloud, we need DANGER_BITBUCKETCLOUD_UUID to detect the owner of the comment.
Could you check your UUID?
It has to be this format {zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz}. (38 characters including brackets).

@orta
Copy link
Member Author

orta commented Dec 6, 2019

That doesn't feel right to me - the bot should be able to ask for it's own user ID via the API and it likely does

@HelloCore
Copy link
Member

Yes, that's right, I've never thought about that before.
I'm going to work on this.

@nick28
Copy link

nick28 commented Dec 6, 2019

Same for me in Bitbucket Cloud, any updates or any leads how can we solve this?

For Bitbucket Cloud, we need DANGER_BITBUCKETCLOUD_UUID to detect the owner of the comment.
Could you check your UUID?
It has to be this format {zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz}. (38 characters including brackets).

I had set it as mentioned in the documentation. And yes it is in the format as mentioned by you

@HelloCore
Copy link
Member

Same for me in Bitbucket Cloud, any updates or any leads how can we solve this?

For Bitbucket Cloud, we need DANGER_BITBUCKETCLOUD_UUID to detect the owner of the comment.
Could you check your UUID?
It has to be this format {zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz}. (38 characters including brackets).

I had set it as mentioned in the documentation. And yes it is in the format as mentioned by you

We've just released version 9.2.9, could you remove DANGER_BITBUCKETCLOUD_UUID and try this version?
You might need to create the new credentials with Read Pull requests and Read Account.

I suspect that this issue would have something to do with brackets, some CI might encode it. At 9.2.9, we fetch UUID from Bitbucket Cloud Instead, and it works fine for me.

@nick28
Copy link

nick28 commented Dec 8, 2019

Same for me in Bitbucket Cloud, any updates or any leads how can we solve this?

For Bitbucket Cloud, we need DANGER_BITBUCKETCLOUD_UUID to detect the owner of the comment.
Could you check your UUID?
It has to be this format {zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz}. (38 characters including brackets).

I had set it as mentioned in the documentation. And yes it is in the format as mentioned by you

We've just released version 9.2.9, could you remove DANGER_BITBUCKETCLOUD_UUID and try this version?
You might need to create the new credentials with Read Pull requests and Read Account.

I suspect that this issue would have something to do with brackets, some CI might encode it. At 9.2.9, we fetch UUID from Bitbucket Cloud Instead, and it works fine for me.

Seems to be fixed and danger is now updating the comments in bitbucket cloud. Tested with DANGER_FAKE_CI="YEP"

@ghost
Copy link

ghost commented Dec 16, 2019

It still creates new comments on Github

mokagio added a commit to mokagio/WordPress-iOS that referenced this issue Feb 7, 2020
Assumption: the version hosted in the GitHub action might have a bug
when it comes to sticky messages. See
danger/danger-js#856.

Trying this to see if the latest version of the package itself has the
same behavior or not.
@mokagio
Copy link
Contributor

mokagio commented Feb 7, 2020

Same as @zhongliangwang, I'm seeing new comments on GitHub as well.

Screen Shot 2020-02-07 at 21 34 57

I made a dedicated repo to reproduce 👉 mokagio/danger-new-comments-example#3.

I tried to fetch Danger JS from master but I couldn't get it to work.

@mokagio
Copy link
Contributor

mokagio commented Feb 7, 2020

I made a new test, mokagio/danger-new-comments-example#5, with a Dangerfile looking like this, to remove any kind of custom logic that could have resulted in the issue.

import {warn} from "danger";

warn("This demo warning was generated on " + new Date());

Same result.

screencapture-github-mokagio-danger-new-comments-example-pull-5-2020-02-08-10_24_27

@mokagio
Copy link
Contributor

mokagio commented Feb 7, 2020

FWIW, the Ruby version doesn't have this issue. See mokagio/danger-new-comments-example#6.

Screen Shot 2020-02-08 at 10 47 08

@mokagio
Copy link
Contributor

mokagio commented Feb 10, 2020

I did a bit more investigation, and saw that Danger JS also makes multiple comments when given file and line.

Screen Shot 2020-02-10 at 12 39 17

@orta
Copy link
Member Author

orta commented Feb 10, 2020

Interesting! Yeah, that check and update code was done before inline comments were added, and it makes sense why I rarely see it (I don't use multiline anywhere)

My bet? the check to find the existing main comment might be hitting these and thinking there isn't an issue to update

@f-meloni
Copy link
Member

I think the reason why is doing multiple comments is that you are using

 GITHUB_TOKEN: ${{ secrets.MOKAGIO_BOT_GITHUB_TOKEN }}

Try

 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Actions doesn't allow you to call https://api.github.com/user, that is what danger-js uses to get the current user.

(this is the response you get)

Request failed [403]: https://api.github.com/user
Response: {
 "message": "Resource not accessible by integration",
 "documentation_url": "https://developer.github.com/v3/users/#get-the-authenticated-user"
}

This is why the user id is hardcoded, then if you don't use the actions user danger can not understand which comment is the danger comment and edit it.
I wonder how danger ruby does this.

mokagio added a commit to mokagio/danger-new-comments-example that referenced this issue Feb 11, 2020
It's possible that my understanding of how GitHub Actions secrets work
and of which token to use if flawed. Maybe you need to use the same
exact syntax as the Danger docs suggest?

See danger/danger-js#856 (comment)
@mokagio
Copy link
Contributor

mokagio commented Feb 11, 2020

Hey @f-meloni, you're spot on! Once I changed the action GITHUB_TOKEN value to secrets.GITHUB_TOKEN it worked as expected. 🎉 🎉 Thanks a lot! 🙏

Screen Shot 2020-02-11 at 13 01 31

Screen Shot 2020-02-11 at 13 11 09

Clearly, my understanding of what that token should have been was wrong. Or rather, I didn't spend enough time reading the docs. I though that the GITHUB_TOKEN we talk about in the Danger + GitHub Action guide was just the arbitrary name used to pass the token one has to generate if they want to use Danger. But actually, GITHUB_TOKEN refers to the token GitHub provides a token that you can use to authenticate on behalf of GitHub Actions. 🤦‍♂️

What I might do is open a PR to add the link to the GITHUB_TOKEN documentation in the Danger + GitHub Actions section. This way future me won't make the same mistake again. 🤞

Thanks again folks! ❤️

@mokagio
Copy link
Contributor

mokagio commented Feb 14, 2020

Hey @f-meloni, in your comment you mention

This is why the user id is hardcoded

When you have time, could you point me to where in the code this happens? I don't understand how it ends up that even if I pass an --id, the default Danger value is used. Thanks ❤️ .

@f-meloni
Copy link
Member

What is hardcoded is the user id, not the danger id.
I use --id often, then I think that works well, how are you setting it?

@f-meloni
Copy link
Member

@mokagio
Copy link
Contributor

mokagio commented Feb 14, 2020

What is hardcoded is the user id, not the danger id.
Oh gotcha. That's why I couldn't find it. Makes sense.

I use --id often, then I think that works well, how are you setting it?

I use the --id parameter too.

It works well if I have Danger locally, but I'm having troubles with the GitHub Action.

I've been experimenting with this yesterday. I'm probably doing something wrong, but it seems to me the Danger GitHub Action doesn't read the id.

See this PR here for example. I'm calling danger ci in the workflow like this:

- name: Run Consistency Checks
  uses: danger/danger-js@9.1.8
  with:
    args: |
      --dangerfile Automattic/peril-settings/org/pr/ios-macos.ts \
      --id danger_id_same
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

But the resulting Danger comment has id danger-id-Danger.

@orta
Copy link
Member Author

orta commented Feb 16, 2020

Looks to me like the docker image for an action isn't respecting the args?

Step 9/10 : RUN cd /usr/src/danger &&   yarn &&   yarn run build:fast &&   chmod +x distribution/commands/danger.js &&   ln -s $(pwd)/distribution/commands/danger.js /usr/bin/danger

Was it definitely calling your dangerfile?

@mokagio
Copy link
Contributor

mokagio commented Feb 17, 2020

Was it definitely calling your dangerfile?

Yes, it was. I made a commit to trigger a failure comment from Danger, and Danger posted it.

mokagio added a commit to mokagio/danger-js that referenced this issue Feb 19, 2020
Not understanding the GITHUB_TOKEN cost me a fair bit of time recently.
Hopefully adding this link to the docs will save time to other people.

See
danger#856 (comment).
@rohit-gohri
Copy link
Member

There are 2 ways one can provide Github Token to danger when using it on Github Actions:

  1. GITHUB_TOKEN: Temporary bot token generated by Github (https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token)
  2. DANGER_GITHUB_API_TOKEN: Personal access token for a user, manually added to secrets

When updating/deleting comments only the 1st case is being considered in the Github Actions env and the userId is never considered, instead a hardcoded ID is returned.

const useGitHubActionsID = process.env["GITHUB_WORKFLOW"]
if (useGitHubActionsID) {
return 41898282
}

I think we should do that only if both the conditions are true, i.e.:

  • CI is Github Actions (env.GITHUB_WORKFLOW is set)
  • Token is in GITHUB_TOKEN and not in DANGER_GITHUB_API_TOKEN

This would allow people to use method 2. (for whatever reasons) and it would still work properly.

There would still be one case where it will fail and we probably can't detect it, just probably mention in docs not to use it this way

 GITHUB_TOKEN: ${{ secrets.MOKAGIO_BOT_GITHUB_TOKEN }}

@f-meloni @orta

@orta
Copy link
Member Author

orta commented Mar 5, 2020

Yep, seems reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants