-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: Add path and query params to test-results endpoint #93264
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
Changes from all commits
d3455e2
43aa85a
8b2d932
bdb31a2
7409dc4
d247ad8
02be70a
69ba699
d0c658b
1bce36a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from enum import Enum | ||
|
||
from drf_spectacular.utils import extend_schema | ||
from rest_framework import status | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
|
||
|
@@ -58,6 +59,12 @@ def has_pagination(self, response): | |
parameters=[ | ||
PreventParams.OWNER, | ||
PreventParams.REPOSITORY, | ||
PreventParams.TEST_RESULTS_SORT_BY, | ||
PreventParams.TEST_RESULTS_FILTER_BY, | ||
PreventParams.INTERVAL, | ||
PreventParams.BRANCH, | ||
PreventParams.FIRST, | ||
PreventParams.LAST, | ||
], | ||
request=None, | ||
responses={ | ||
|
@@ -70,29 +77,51 @@ def has_pagination(self, response): | |
def get(self, request: Request, owner: str, repository: str, **kwargs) -> Response: | ||
"""Retrieves the list of test results for a given repository and owner. Also accepts a number of query parameters to filter the results.""" | ||
|
||
owner = "codecov" | ||
repository = "gazebo" | ||
branch = "main" | ||
sort_by = request.query_params.get("sortBy", OrderingParameter.COMMITS_WHERE_FAIL.value) | ||
|
||
if sort_by and sort_by.startswith("-"): | ||
sort_by = sort_by[1:] | ||
direction = OrderingDirection.DESC.value | ||
else: | ||
direction = OrderingDirection.ASC.value | ||
|
||
first_param = request.query_params.get("first") | ||
last_param = request.query_params.get("last") | ||
|
||
first = int(first_param) if first_param else None | ||
last = int(last_param) if last_param else None | ||
|
||
if first and last: | ||
return Response( | ||
status=status.HTTP_400_BAD_REQUEST, | ||
data={"details": "Cannot specify both `first` and `last`"}, | ||
) | ||
|
||
if not first and not last: | ||
first = 20 | ||
|
||
variables = { | ||
"owner": owner, | ||
"repo": repository, | ||
"filters": { | ||
"branch": branch, | ||
"branch": request.query_params.get("branch", "main"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, i would think that there's no fallback for branch unless we're just keeping this here for the time that this will be under development There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's right, just keeping it for development. We can remove as soon as query params are hooked up |
||
"parameter": request.query_params.get("filterBy"), | ||
"interval": ( | ||
request.query_params.get("interval", MeasurementInterval.INTERVAL_30_DAY.value) | ||
), | ||
"flags": None, | ||
"interval": MeasurementInterval.INTERVAL_30_DAY.value, | ||
"parameter": None, | ||
"term": None, | ||
"test_suites": None, | ||
}, | ||
"ordering": { | ||
"direction": OrderingDirection.DESC.value, | ||
"parameter": OrderingParameter.COMMITS_WHERE_FAIL.value, | ||
"direction": direction, | ||
"parameter": sort_by, | ||
}, | ||
"first": 10, | ||
"first": first, | ||
"last": last, | ||
} | ||
|
||
client = CodecovApiClient(git_provider_org="codecov") | ||
client = CodecovApiClient(git_provider_org=owner) | ||
graphql_response = client.query(query=query, variables=variables) | ||
|
||
test_results = TestResultSerializer().to_representation(graphql_response.json()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would this work w/
master
? I supposemain
captures more thanmaster
these daysThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just pass in a branch name for master, eventually the frontend will be the SOT, we're just defaulting main here so the user doesn't need to pass a branch for most cases