Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a JSON Reporter #469

Merged
merged 3 commits into from
Feb 28, 2023

Conversation

mark-davenport-fountain
Copy link
Contributor

I'm proposing adding a JSON route and reporter. This can be used by systems to pull a structured view of the data and then can be easily processed.

I based this off of what was in the html file view.

In my use case I'd like to be able to hit this end point periodically and then store the results to process locally and give feedback during dev about usage of a file that's in production, but having this structured set available for systems to use could be valuable for other use cases as well.

Example output (truncated):

{
  "total_files": 17,
  "lines_of_code": 242,
  "lines_covered": 38,
  "lines_missed": 204,
  "covered_strength": 1.4223140495867765,
  "covered_percent": 15.702479338842975,
  "files": {
    "app/controllers/application_controller.rb": {
      "file_name": "app/controllers/application_controller.rb",
      "never_loaded": false,
      "runtime_percentage": 33.33,
      "lines_of_code": 11,
      "lines_covered": 2,
      "lines_missed": 1,
      "covered_percent": 66.66666666666667,
      "covered_strength": 3.0
    },
    "app/controllers/home_controller.rb": {
      "file_name": "app/controllers/home_controller.rb",
      "never_loaded": false,
      "runtime_percentage": 28.57,
      "lines_of_code": 35,
      "lines_covered": 10,
      "lines_missed": 10,
      "covered_percent": 50.0,
      "covered_strength": 1.6
    }
    .....
  }
}

@danmayer
Copy link
Owner

hmm, so @mark-davenport-fountain this isn't well documented as it is mostly for the developers of coverband, but I have also used it for tool integration in the past... There are two JSON endpoints

I think these would cover your use cases... to enable and display links to that data add this to your coverband config:

config.web_debug = true

If these don't have the specific data you are after we could modify or add another endpoint... I am more likely to support an API than some of the recent requests to dump static reports... All of these 'extra' options that folks do a bit more of one off processing has in the past added a lot of maintenance burden and isn't frequently used. Take a look at the current endpoints and let me know if they meet your needs...

Otherwise the code and pattern looks good, so I could cleanup and move all the JSON api endpoints more towards this style, if there is enough interest in using the JSON.

@mark-davenport-fountain
Copy link
Contributor Author

I saw those to endpoints but they didn't meed my needs since they didn't have the data clearly laid out to consume. The enriched_debug_data has it a little closer, but I wanted to have an endpoint that made it clear and simple for how to use the data that is presented in JSON.

For example:
I assume the data array has all the information in it, but I'm not sure how to consume it. The web UI has it pretty clearly spelled out so I was looking for something similar to relate to.

    "./config/routes.rb": {
      "first_updated_at": 1676067851,
      "last_updated_at": 1676300488,
      "file_hash": "c6975f2631903dd08b43afec8de92306",
      "data": [
        null,
        17,
        0,
        null,
        null,
        null,
        null,
      ]
    }
  },

Runtime relevant lines is easier to understand, and coverage also is her but still not clear how to tell what they mean.

  {
   "filename": "/Users/mark/fountain/coverband_demo/app/controllers/application_controller.rb",
   "runtime_relavant_lines": null,
   "coverage": [4, 4, 0, null, null, null, 4, 0, null, null, null],
   "last_updated_at": "2023-02-13T09:01:28.000-06:00",
   "first_updated_at": "2023-02-10T16:24:36.000-06:00",
   "never_loaded": false
 },

I could probably use these endpoints if they add some good docs on how to make sense of the responses.

@danmayer
Copy link
Owner

OK, I think we can take your approach, could you resolve the conflict and ensure that it has all the data for your use cases... If so I am good with pulling this in, after it is merged, I will likely move over all the other json endpoints to follow some of these patterns.

@mark-davenport-fountain let me know if you run into any issues.

@mark-davenport-fountain
Copy link
Contributor Author

Sounds good. I 'll get this fixed up shortly. I as out on vacation last week. I'll let you know!

@danmayer danmayer self-requested a review February 22, 2023 04:55
@mark-davenport-fountain
Copy link
Contributor Author

I've got this ready now. @danmayer please take a look, and may want to approve the workflow to run.

@danmayer
Copy link
Owner

@mark-davenport-fountain approved workflow run

@mark-davenport-fountain
Copy link
Contributor Author

mark-davenport-fountain commented Feb 23, 2023

Looks like I missed running standardrb on one of my files. I've got that done now. Should be green on the next run.
@danmayer

@mark-davenport-fountain
Copy link
Contributor Author

Just a small bump on this @danmayer.

@danmayer
Copy link
Owner

hmm still another standard error

@mark-davenport-fountain
Copy link
Contributor Author

Alright - got that one too. I was running into some trouble with standardrb locally. I'm seeing this same scanning error locally as I'm seeing in CI, but I guess it's not causing any actual problems. Looks like to fix it you'd need to unlock and update standardrb.
Should be good to go now anyhow.

@danmayer danmayer merged commit 93290cf into danmayer:main Feb 28, 2023
@danmayer
Copy link
Owner

merged, thanks I will update the changes and get this in a RC release sometime soon

@mark-davenport-fountain
Copy link
Contributor Author

Than you @danmayer

@danmayer
Copy link
Owner

danmayer commented Mar 5, 2023

ok so you can install coverband RC release 5.2.6.rc.4 to test out this functionality let me know if you have any issues @mark-davenport-fountain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants