Code Quality Widget Doesn't Load

I’m using GitLab Enterprise Edition v16.0.5-ee and I’m having an issue in a MR, where the widget states there are no changes but If I download the report I can see a number of violations. Also, despite the fact it succeed, if I tap on the Code Quality tab Im getting Failed to load Code Quality report.

Here is my config

code-quality:
  variables:
    CODE_CLIMATE_REPORT_PATH: "reports/lint/lint_report.json"
  stage: quality
  rules:
    - !reference [.master_rules, rules]
  artifacts:
    paths:
      - "$CODE_CLIMATE_REPORT_PATH"
    reports:
      codequality: "$CODE_CLIMATE_REPORT_PATH"
  script:
    - bundle exec fastlane run_lint
  tags:
    - macos
  interruptible: true
swiftlint(
      mode: :lint,
      output_file: "reports/lint/lint_report.json",
      reporter: "codeclimate", 
      config_file: ".swiftlint.yml",
      raise_if_swiftlint_error: true,
    )

This is the lint violation lint_report.json

[
  {
    "check_name" : "Operator Usage Whitespace",
    "description" : "Operators should be surrounded by a single whitespace when they are being used",
    "engine_name" : "SwiftLint",
    "fingerprint" : "0d7083317d8d39a0f2ff1ac2803a1b151bb005e9ea68028da1810be5e8adaa4f",
    "location" : {
      "lines" : {
        "begin" : 27,
        "end" : 27
      },
      "path" : "File.swift"
    },
    "severity" : "MINOR",
    "type" : "issue"
  }
]

I tried to inspect the issue and it seems the report fails to load on api/graphql with the following error.

{
  "errors": [
    {
      "message": "Unexpected end of document",
      "locations": []
    }
  ]
}

This issue seems to only takes place when the code quality report fails(probably something on the parser) because when it succeeds, it reports correctly.

It turns out that GitLab have case sensitive problem when parsing severity from SwiftLint reports.

SwiftLint provides severities “MINOR” or “MAJOR” and gitlab code quality expects “info” , “minor” , “major” , “critical” , or “blocker”.

Use sed or gsed (if you are using macOS) to replace severity to lower case in your code quality JSON report.

gsed -i 's/MINOR/minor/g' lint_report.json
gsed -i 's/MAJOR/major/g' lint_report.json
2 Likes