Code Quality MR widget: Status of report comparison is not taken into account

Summary

The backend code quality comparison returns JSON data that includes a status property, but we are not taking it into account in three cases:

1️⃣ The code quality MR widget reports "No changes to code quality" when the arrays of changed issues are empty, but the message is not accurate when the status is failed. The widget should instead use the "Failed to load code quality report" status/message in this case.

(on further investigation, failed refers to the status of the scan and not to the status of the report comparison, so we don't need to change the behavior in this case)

2️⃣ The code quality MR widget correctly reports "Base pipeline code quality artifact not found" when that is the case, but it is determined from the data source that we used before moving the comparison to the backend. We should instead show this message when the status is not_found so that we can remove the redundant code from the frontend. This could be combined with moving the message into the body of the widget to make it more discoverable

image

3️⃣ The code quality MR widget incorrectly reports "No changes to code quality" when the backend is still parsing and comparing the base and head reports (indicated by the HTTP status 204 No Content). In this case we should display a loading icon and continue to poll until we get a response with a different HTTP status so we can display the results in the widget once they have been generated.

Steps to reproduce

For 1️⃣

  1. Run code quality on the base commit of an MR
  2. Somehow cause an error when running code quality on the head commit of the MR
  3. The JSON response should show a status of failed but the widget will say "No changes to code quality"

For 2️⃣

  1. Run code quality on the head commit of an MR, but not the base commit
  2. The JSON response should show a status of not_found and the widget will say "Failed to load codeclimate report"
  3. The widget should have a question mark icon with a popover that says "Base pipeline code quality artifact not found" and links to the docs

For 3️⃣

  1. Run code quality on the base commit and head commit of an MR with code quality changes
  2. Once the job is done for the head commit, refresh the MR page until you can see the code quality widget
  3. On the first load that you can see the widget, it should display "No changes to code quality" even though there are changes, and the network panel in your browser's dev tools should show a request for codequality_reports.json with a 204 No Content response
  4. Refresh the page again until the widget displays the real result

Example Project

What is the current bug behavior?

The code quality MR widget reports "No changes to code quality" when the report comparison has failed/errored

The code quality MR widget reports "No changes to code quality" when the reports are still being parsed/compared

What is the expected correct behavior?

The code quality MR widget should show "Failed to load code quality" (or some other more specific/helpful error message) when the report comparison has failed/errored

The code quality MR widget should show a loading indicator while the reports are being parsed/compared, continue to poll for results until the endpoint returns a different result, then display the corresponding message for that result.

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by Miranda Fluharty