danielpalme / ReportGenerator

ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.

Home Page:https://reportgenerator.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for Gitlab (Code Climate) Reports

thompson-tomo opened this issue · comments

What

I want to use the tool to generate Code Climate, code quality reports which can then be exposed as an artifacat in GitLab and visible within the Gitlab UI.

Additional Context

Gitlab info is available from: https://docs.gitlab.com/ee/ci/testing/code_quality.html
Spec is described at: https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md

According to the spec of the Code Climate report, it seems it's about issues in a code base.
It's not related to code coverage.

Since ReportGenerator is all about code coverage I don't think it's a good fit.
Am I missing somthing?

For me the content of this report would be very similiar to what I am already producing for SonarQube. Only difference being the tool which consumes the report.

The report for SonarQube has the following format:
https://reportgenerator.io/resources/reports/SonarQube/SonarQube.xml

But still, it's a report about code coverage, which you can use within SonarQube.

The Code Climate report is about issues in a code base.
I guess ReportGenerator is the wrong tool to generate such a report. ReportGenerator "knows" about code coverage, but it does not analyze a code base for potential issues.

So have done some investigation and what I have found is: https://docs.codeclimate.com/docs/configuring-test-coverage that website leads me to believe that it is possible to convert a Cobertura report to the code climate quality report. Hence based on that information I don't see it being an issue to generate that report using this library.

Sorry for the delay.

I just had a look at your link and generated a sample file.
The format is easy to understand:

{
  "ci_service": {
    "branch": "main",
    "build_identifier": "",
    "build_url": "",
    "commit_sha": "48d550158a3b19dfe303c0ecb86695d0754cb47d",
    "committed_at": 1706815230,
    "name": ""
  },
  "environment": {
    "gem_version": "",
    "package_version": "",
    "pwd": "C:\\temp",
    "prefix": "C:\\temp",
    "rails_root": "",
    "reporter_version": "0.11.1",
    "simplecov_root": ""
  },
  "git": {
    "branch": "main",
    "head": "48d550158a3b19dfe303c0ecb86695d0754cb47d",
    "committed_at": 1706815230
  },
  "covered_percent": 70.69767441860465,
  "covered_strength": 0,
  "line_counts": {
    "missed": 63,
    "covered": 152,
    "total": 215
  },
  "source_files": [
    {
      "blob_id": "ec77391762bb9081cb95ea77b62dfe8a5de2f758",
      "coverage": "[null,null,null,null,null,null,null,null,null,null,null,0,0,0,null,null,null,null,null,null,null,2,2,2,2,null,null,2,2,2,2]",
      "covered_percent": 72.72727272727273,
      "covered_strength": 1.4545454545454546,
      "line_counts": {
        "missed": 3,
        "covered": 8,
        "total": 11
      },
      "name": "C:\\temp\\GenericClass.cs"
    },
    {
      "blob_id": "63ebe7b1c4c489f94eaac965781784a22d1ec94b",
      "coverage": "[null,null,null,null,null,null,4,4,2,2,null,null,2,2,null,4]",
      "covered_percent": 100,
      "covered_strength": 2.857142857142857,
      "line_counts": {
        "missed": 0,
        "covered": 7,
        "total": 7
      },
      "name": "C:\\temp\\CodeContract_Target.cs"
    },
    {
      "blob_id": "f39c0228f81d0e40ae52c53cea85d0c8b93adb4a",
      "coverage": "[null,null,null,null,null,null,null,null,null,null,4,null,6,null,0,null,0,0,0,0,0,null,4,4,4,4,4,null,null,2,2,2,2,null,null,0,0,0,0,null,null,2,2,null,10,null,22,8,8,8,null,2,null,8,2,2,2,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0,0,0]",
      "covered_percent": 63.1578947368421,
      "covered_strength": 3.0526315789473686,
      "line_counts": {
        "missed": 14,
        "covered": 24,
        "total": 38
      },
      "name": "C:\\temp\\TestClass2.cs"
    },
    {
      "blob_id": "a6d84d76022be2182fb3ab3b2121c1c0af20fd35",
      "coverage": "[null,null,null,null,null,null,4,4,4,4,null,null,null,null,null,null,null,null,null,2,2,2,2,null,null,0,0,null,null,null,0,0,null,null,null,null,null,null,2,2,2,2,null,null,0,0,null,null,null,0,0]",
      "covered_percent": 60,
      "covered_strength": 1.6,
      "line_counts": {
        "missed": 8,
        "covered": 12,
        "total": 20
      },
      "name": "C:\\temp\\AbstractClass.cs"
    },
    {
      "blob_id": "9f41b5ba9acf7c39411a7ead65c07dd3b59e692e",
      "coverage": "[null,null,null,null,null,2]",
      "covered_percent": 100,
      "covered_strength": 2,
      "line_counts": {
        "missed": 0,
        "covered": 1,
        "total": 1
      },
      "name": "C:\\temp\\PartialClassWithAutoProperties.cs"
    },
    {
      "blob_id": "d641c2e65a648d7abe337eda6ddd55768eef660f",
      "coverage": "[null,null,null,null,null,2]",
      "covered_percent": 100,
      "covered_strength": 2,
      "line_counts": {
        "missed": 0,
        "covered": 1,
        "total": 1
      },
      "name": "C:\\temp\\NotMatchingFileName.cs"
    },
    {
      "blob_id": "622a582d1fce20af86b8bc0b843cac35f4866f05",
      "coverage": "[null,null,null,null,null,null,null,null,2,2,2,2,2,null,2,2,null,2,2,2,2,null,0,0,0,2,null,null,2,2,null,2,null,null,2,2,2,2,null,null,2,8,null,8,null,2,2,null,null,null,null,0,0,0,0,0,0]",
      "covered_percent": 72.72727272727273,
      "covered_strength": 1.8181818181818181,
      "line_counts": {
        "missed": 9,
        "covered": 24,
        "total": 33
      },
      "name": "C:\\temp\\TestClass.cs"
    },
    {
      "blob_id": "5ff6ea8502a9fc5674e585404b7f0e51fc5a99ce",
      "coverage": "[null,null,null,null,null,2,null,null,2,null,null,2,2,2,null,null,null,2,2,2]",
      "covered_percent": 100,
      "covered_strength": 2,
      "line_counts": {
        "missed": 0,
        "covered": 8,
        "total": 8
      },
      "name": "C:\\temp\\ClassWithExcludes.cs"
    },
    {
      "blob_id": "57f8a5cb4a137a3d5591896666a773c53bfed2dd",
      "coverage": "[null,null,null,null,null,null,null,0,0,0,0,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0,0,0,null,null,0,0,null,0]",
      "covered_percent": 0,
      "covered_strength": 0,
      "line_counts": {
        "missed": 11,
        "covered": 0,
        "total": 11
      },
      "name": "C:\\temp\\AnalyzerTestClass.cs"
    },
    {
      "blob_id": "be6daacb80451a7157bf945760606b70517ec7cd",
      "coverage": "[null,null,null,null,null,null,null,null,null,0,0,null,0,0]",
      "covered_percent": 0,
      "covered_strength": 0,
      "line_counts": {
        "missed": 4,
        "covered": 0,
        "total": 4
      },
      "name": "C:\\temp\\CodeContract_Contract.cs"
    },
    {
      "blob_id": "9e3c667f8ff37902d437a2de9f8b7e4bcd9b41a9",
      "coverage": "[null,null,null,null,null,null,null,null,null,2,null,null,2,2,null,null,2,2,2,null,2,2,2]",
      "covered_percent": 100,
      "covered_strength": 2,
      "line_counts": {
        "missed": 0,
        "covered": 9,
        "total": 9
      },
      "name": "C:\\temp\\ClassWithLocalFunctions.cs"
    },
    {
      "blob_id": "8c179013f3e6831379ff6da9c7334501386e87b0",
      "coverage": "[null,null,null,null,null,2,null,0]",
      "covered_percent": 50,
      "covered_strength": 1,
      "line_counts": {
        "missed": 1,
        "covered": 1,
        "total": 2
      },
      "name": "C:\\temp\\PartialClassWithAutoProperties2.cs"
    },
    {
      "blob_id": "047c42c253aaed7328be26398efe2d086635c86a",
      "coverage": "[null,null,null,null,null,null,null,2,2,2,null,null,0,0,0,null,null,null,null,null,0,null,null,2,2,2,2,2,null,0,0,0,2]",
      "covered_percent": 56.25,
      "covered_strength": 1.125,
      "line_counts": {
        "missed": 7,
        "covered": 9,
        "total": 16
      },
      "name": "C:\\temp\\PartialClass.cs"
    },
    {
      "blob_id": "17451a3495165fdcdb99991646e3ea0d01661431",
      "coverage": "[null,null,null,null,null,null,null,null,null,2,2,2,2,null,2,2,null,2,2,2,null,2,2,null,2,null,2,2,null,2,2,null,2,null,2,2,null,2,null,null,2,2,2,0,0,0,null,2,2,2,null,null,2,2,2,2,2,2,null,null,null,null,null,2,2,2,2,null,null,2,2,2]",
      "covered_percent": 92.85714285714286,
      "covered_strength": 1.8571428571428572,
      "line_counts": {
        "missed": 3,
        "covered": 39,
        "total": 42
      },
      "name": "C:\\temp\\Program.cs"
    },
    {
      "blob_id": "9f2ee8ea75f727132fad30cdd5265051126aecd5",
      "coverage": "[null,null,null,null,null,null,null,null,null,2,2]",
      "covered_percent": 100,
      "covered_strength": 2,
      "line_counts": {
        "missed": 0,
        "covered": 2,
        "total": 2
      },
      "name": "C:\\temp\\GenericAsyncClass.cs"
    },
    {
      "blob_id": "dd2529bd867bae07395c8ad3d83d8aa678389569",
      "coverage": "[null,null,null,null,null,null,null,null,null,2,2,2,2]",
      "covered_percent": 100,
      "covered_strength": 2,
      "line_counts": {
        "missed": 0,
        "covered": 4,
        "total": 4
      },
      "name": "C:\\temp\\AsyncClass.cs"
    },
    {
      "blob_id": "a92ae48dda4bccc92715b75b99a7c28d4cccfbea",
      "coverage": "[null,null,null,null,null,null,null,2,2,2,null,null,0,0,0]",
      "covered_percent": 50,
      "covered_strength": 1,
      "line_counts": {
        "missed": 3,
        "covered": 3,
        "total": 6
      },
      "name": "C:\\temp\\PartialClass2.cs"
    }
  ],
  "repo_token": ""
}

I will create a implementation as soon as possible.

No worries at all @danielpalme and thank you for agreeing to implement this, I appreciate it.

Release 5.2.1 is now available.

You can now use or add the new reporttype "CodeClimate": -reporttypes:CodeClimate
This will generate a "codeclimate.json" file.

It would be great if you could test it and let me know, if it works for you.

Wow that was nice & quick, thanks alot. :) I will aim to test it within the next week.

Just some quick feedback, new feature is looking good on first test as was able to generate report and attach to gitlab just have 1 more aspect to check and when it passes will close issue. Thanks again.

Did you have a chance to have a look at the new feature yet?