Sonarcloud not identifying Pull Requests on Github

My organisation uses Sonarcloud across several projects in github, and has the sonarcloud app installed. Most are projects have sonarcloud functioning correctly, but one project is broken.

In this project, Sonarcloud is not identifying Pull requests, instead marking everything as branches, even though develop is correctly identified as the main branch (and PRs are made to develop).

image

Therefore the Sonarcloud bot is not commenting on PRs (ie. no pull request decoration).

Unfortunately the documentation offers no clue as to a solution, as it presumes pull request analysis works automatically for Github.

Any help is much appreciated.

EDIT: relevant yml

name: CI Workflow
on: push

jobs:
  pytest:
    {snip out pytest with coverage.xml output}

  SonarCloud-scan:
    name: SonarCloud scan
    needs: pytest
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/download-artifact@v2
        with:
          name: coverage.xml
      - name: SonarCloud scan
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

What CI tool are you using (GitHub Actions?). How is your build which triggers the SonarCloud analysis configured (such as a GitHub Actions YML file)?

Thanks Colin: Yes, github actions managed with yml

name: CI Workflow
on: push

jobs:
  pytest:
    name: pytest
    runs-on: ubuntu-latest

    steps:
      - name: checkout
        uses: actions/checkout@v2

      - name: Run Pytest
        run: make test-ci

      - name: Archive unit test reports
        uses: actions/upload-artifact@v1
        with:
          name: coverage.xml
          path: ./coverage.xml

  SonarCloud-scan:
    name: SonarCloud scan
    needs: pytest
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/download-artifact@v2
        with:
          name: coverage.xml
      - name: SonarCloud scan
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

You would need a trigger so that the action runs on pull requests. Like this:

name: Build
on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened]

Thanks. I will try that, however all our projects use identical pytest.ini, github actions .yml and sonar-project.properties files, and yet only one project is having sonarcloud problems

Therefore the suggested trigger is not present in projects that do run sonarcloud correctly so I don’t understand why it would be the root cause of the issue preventing bot comments and PRs?

One unique sonarcloud warning that impacts the project without proper functionality is

The following error(s) occurred while trying to import coverage report:
Invalid directory path in 'source' element: {repo_name}

where {repo_name} is the name of the project and the top-level folder

Problem is not resolved.

We will need to escalate. Further projects in our repo are developing sonarcloud errors despite our making no changes in github actions or sonarcloud.properties in those projects.

These errors are slightly different by project and look like github and sonarcloud failing to integrate correctly. Can we discuss this live with Sonarcloud support?

This community is your only avenue for support for SonarCloud, so it’s best that you describe the issues you’re facing here.

What issues have the other repositories started facing (and if there are explicit error messages, what are they?)