code-coverage-api-plugin icon indicating copy to clipboard operation
code-coverage-api-plugin copied to clipboard

Add remote API for new model

Open uhafner opened this issue 3 years ago • 13 comments

The previous coverage model supports a remote API to obtain the coverage results. This needs to be added for the new model as well.

Old implementation: https://github.com/jenkinsci/code-coverage-api-plugin/blob/master/plugin/src/main/java/io/jenkins/plugins/coverage/targets/RestResultWrapper.java

New implementation should follow a similar pattern as in: https://github.com/jenkinsci/warnings-ng-plugin/tree/master/plugin/src/main/java/io/jenkins/plugins/analysis/core/restapi.

The remote API should provide the results of the coverage analysis in a similar way as the warnings plugin provides the results. So we basically need:

  • A top-level API method that returns an overview for the ResultAction that contains the model data of the overview.
  • Optionally: additional API method that returns the delta information for the ResultAction (coverage of a change set)
  • Optionally: additional API method that return the rows of the coverage table for the ResultAction that contains the model data of the overview.

uhafner avatar Oct 01 '21 12:10 uhafner

Hey Can I do this ?

chinmaym07 avatar Oct 17 '21 17:10 chinmaym07

Yes, please go ahead. If you need more details please let me know!

uhafner avatar Oct 17 '21 18:10 uhafner

Is there no REST API then for coverage in any form at the moment? (Version 2.0.4) Then I think this should be mentioned in the README and release notes.

mucst avatar Dec 06 '21 13:12 mucst

Well, it is tracked as this issue. Feel free to add it to the README as well.

uhafner avatar Dec 06 '21 14:12 uhafner

Having to back out our support for code-coverage-api plugin within our CI framework as we require the REST API for downstream analytics. Unfortunate as this plugin looks better (within Jenkins) than cobertura.

Hopefully this issue will be fixed and we can revert.

sawatts avatar Feb 17 '22 12:02 sawatts

@chinmaym07 Did you make any progress with this?

stevegolton avatar Feb 17 '22 13:02 stevegolton

I think we are now ready to start working on this issue.

What elements or results do you want to see in such an API call? Just the coverage results per metric?

uhafner avatar Feb 17 '22 19:02 uhafner

I would like to take over if that is ok

mbauerness avatar Feb 19 '22 13:02 mbauerness

We use the numerator and denominator for each type of coverage, rather than the pre-calculated percentage - e.g. number of lines covered vs total number of lines counted - as this provides a measurement of the "size" of a project when comparing results.

sawatts avatar Feb 21 '22 10:02 sawatts

Hi all, is there any progress on this?

I am relying on the API methods to generate a nice github comment for each PR to show how much tests were added and indicate a trend for the current PR if merged.

filipecosta01 avatar Oct 06 '22 08:10 filipecosta01

Unfortunately, not. Seems that nobody really did start working on this topic yet. Maybe this would be a good Hacktoberfest issue, I will mark it as such.

uhafner avatar Oct 06 '22 20:10 uhafner

Hello, Can anyone help me understand the requirement? I can pick this issue.

isanketsaha avatar Oct 17 '22 10:10 isanketsaha

I updated the title now. What else can I do to make it more clear?

uhafner avatar Oct 17 '22 11:10 uhafner

Do we have any progress on this? We were using the API(../coverage/result/api/json?depth=2) to get the coverage results. Are u aware of any alternatives to this? Any help would be appreciated.

karnwaltushti avatar Mar 01 '23 10:03 karnwaltushti

Yes, this is already part of #512. You can install a snapshot if you want to test.

to get the coverage results.

What results are you actually expecting? The test of the new API is available at https://github.com/jenkinsci/code-coverage-api-plugin/blob/coerage-model/plugin/src/test/java/io/jenkins/plugins/coverage/metrics/steps/CoverageApiITest.java

uhafner avatar Mar 01 '23 10:03 uhafner

@uhafner This was the information we are using with the endpoint ../coverage/result/api/json?depth=1 image (3)

karnwaltushti avatar Mar 02 '23 06:03 karnwaltushti

Ok, the current PR exposes the same results in a different schema, but you should find everything you need.

{
  "_class" : "io.jenkins.plugins.coverage.metrics.steps.CoverageApi",
  "modifiedFilesDelta" : {
    
  },
  "modifiedFilesStatistics" : {
    
  },
  "modifiedLinesDelta" : {
    
  },
  "modifiedLinesStatistics" : {
    
  },
  "projectDelta" : {
    
  },
  "projectStatistics" : {
    "branch" : "81.51%",
    "class" : "90.91%",
    "complexity" : "666",
    "complexity-density" : "+51.00%",
    "file" : "95.83%",
    "instruction" : "87.50%",
    "line" : "88.21%",
    "loc" : "1306",
    "method" : "84.32%",
    "module" : "100.00%",
    "package" : "66.67%"
  },
  "qualityGates" : {
    "overallResult" : "SUCCESS",
    "resultItems" : [
      {
        "qualityGate" : "Overall project - Line Coverage",
        "result" : "SUCCESS",
        "threshold" : 60.0,
        "value" : "88.21%"
      },
      {
        "qualityGate" : "Overall project - Branch Coverage",
        "result" : "SUCCESS",
        "threshold" : 60.0,
        "value" : "81.51%"
      }
    ]
  },
  "referenceBuild" : "-"
}

uhafner avatar Mar 02 '23 07:03 uhafner

Do we have the snapshot version available online? Otherwise can u guide me to the steps for creating it? Also when is the planned release for this, it would be very helpful? And could you help me understand why the format for the result was changed?

I also have a pretty basic question just so i am not missing anything, The plugin page (https://plugins.jenkins.io/code-coverage-api/) still has the entry image but these endpoints are not available anymore..

karnwaltushti avatar Mar 03 '23 08:03 karnwaltushti

No, there are no snapshots available right now. You need to wait for the beta version.

You can watch PR #512 to see when it is merged.

uhafner avatar Mar 03 '23 10:03 uhafner

The plugin page (https://plugins.jenkins.io/code-coverage-api/) still has the entry image but these endpoints are not available anymore..

Yes, the documentation needs to be updated as well. Feel free to submit a PR once the changes have been merged.

uhafner avatar Mar 03 '23 10:03 uhafner

The new step recordCoverage is now in beta testing, can you please check if this release helps to solve this issue? Please note that the syntax of the step is totally new and cannot be combined with existing results.

uhafner avatar Mar 15 '23 18:03 uhafner

@uhafner I see the minimum jenkins Version required for this version is bumped up to 2.387.1 and we have 2.361.2. Is it possible to downgarde the jenkins version, if there is any help required i would be glad to help since this is a core requirement for us.

karnwaltushti avatar Mar 15 '23 20:03 karnwaltushti

This is not possible since I am using features of Jenkins 2.385.

uhafner avatar Mar 15 '23 21:03 uhafner