Skip to content

Cannot fetch PR comments using danger.api.github #591

Open
@ipodishima

Description

using 3.17.1 version

Hi

I need the comments from the PR to detect some stuff required for my rules processing.

I think the way to do it should be to update GithubDSL to include the required structs.

What I'm doing

ActionFlow

name: Run Unit Tests

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  checkout_and_prepare:
    [...]
  test:
    [...]
  run-danger:
    name: "Run Danger"
    needs: test
    runs-on: self-hosted
    steps:
      - name: Generate Github Token
        id: generate_token
        uses: tibdex/github-app-token@v1
        with:
          app_id: ${{ secrets.TOKEN_APP_ID }}
          private_key: ${{ secrets.TOKEN_APP_PRIVATE_KEY }}
      - name: Danger
        run: |
          sh FirstPartyFrameworks/My-CI/BuildTools/danger_lint.sh
        env:
          GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
          DANGER_GITHUB_API_TOKEN: ${{ steps.generate_token.outputs.token }}

Note
If I had this step before danger

- name: Test API Call
  run: |
    curl -H "Authorization: token ${{ steps.generate_token.outputs.token }}" \
         https://api.github.com/repos/<OrgName>/<RepoName>/issues/<PRNumber>/comments

The curl succeeds.

Now, in my code, if I'm doing

danger.github.api.issueComments(owner: owner,
                                        repository: repo,
                                        number: danger.github.pullRequest.number)

Then I get

Error fetching comments: Error Domain=com.nerdishbynature.octokit Code=404

After digging, I honestly think that's an issue with Authorization. But I don't know how to setup it properly or if the library needs an update.
As I said, it might also be only a matter of mapping some properties in the Github struct.

Also, as a FYI, I have those warnings at then end:

Request failed [403]: https://api.github.com/user
Response: {
  "message": "Resource not accessible by integration",
  "documentation_url": "https://docs.github.com/rest/users/users#get-the-authenticated-user"
}
Request failed [403]: https://api.github.com/user
Response: {
  "message": "Resource not accessible by integration",
  "documentation_url": "https://docs.github.com/rest/users/users#get-the-authenticated-user"
}
Feedback: https://github.com/BeatPitch/BeatPitch-iOS/pull/443#issuecomment-1693072516

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions