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

REST API: add flag coverage to flag list endpoint #765

Merged
merged 5 commits into from
Aug 27, 2024

Conversation

JerrySentry
Copy link
Contributor

closes codecov/feedback#362

Updates /api/v2/{service}/{owner_username}/repos/{repo_name}/flags/ endpoint to include the coverage value for each flag in the response object.

Old: "results": [{"flag_name": string}]
New: "results": [{"flag_name": string, "coverage": float}]

This coverage value comes from the computed report of the head commit of the repo's default branch. If failure to retrieve such value a default value of 0 will be returned.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Copy link

codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.15%. Comparing base (c4496c9) to head (9fe14b4).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@               Coverage Diff                @@
##               main       #765        +/-   ##
================================================
+ Coverage   96.14000   96.15000   +0.01000     
================================================
  Files           812        812                
  Lines         18400      18416        +16     
================================================
+ Hits          17691      17707        +16     
  Misses          709        709                
Flag Coverage Δ
unit 91.97% <100.00%> (+<0.01%) ⬆️
unit-latest-uploader 91.97% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

]
try:
report = self.get_commit().full_report
if not report:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, when would we throw a NotFound vs. return None?

Copy link
Contributor Author

@JerrySentry JerrySentry Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line would return the list of flags without the coverage information for each flag if the coverage report of the head commit is not yet processed.

in general imo we should throw 404 if the requested data is not found (eg in the param you have a repo/owner that doesn't exist) so there's nothing to return. And return null, I don't think we would return that as a response to the entire request, rather the response object has some partial data is not available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! Makes sense to me, thanks for the context


for i, val in enumerate(results):
flag_report = report.filter(flags=[val["flag_name"]])
results[i]["coverage"] = flag_report.totals.coverage or 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totals will always exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I can tell yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sggg

"next": None,
"previous": None,
"results": [
{"flag_name": "foo", "coverage": 0},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jw on returning 0 for coverage here vs. None 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I feel none is better

Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good 👌

@JerrySentry JerrySentry added this pull request to the merge queue Aug 27, 2024
Merged via the queue into main with commit ae3f4d8 Aug 27, 2024
18 checks passed
@JerrySentry JerrySentry deleted the aug_22_api_v2_flag_coverage branch August 27, 2024 18:44
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.

Add coverage percentage to public API's Flag list endpoint
2 participants