Skip to content

feat(prevent): create endpoint that fetches repositories list #95181

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

adrianviquez
Copy link
Contributor

This PR creates and endpoint that fetches a list of repositories belonging to a specific owner

Notes

  • Added path to access endpoint
  • Added query file with GQL query
  • Added endpoint logic + its serializer
  • Added test file for said logic

@adrianviquez adrianviquez requested review from a team as code owners July 9, 2025 22:28
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 9, 2025
request=None,
responses={
200: RepositoriesSerializer,
400: RESPONSE_BAD_REQUEST,
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're up for it, one thing I didn't do with my initial implementation of the serializers with the test results one is to actually throw the exceptions in the serializer if we error out on the owner part of the request.

https://github.com/codecov/umbrella/blob/02de63009831bee26cb65113b35f6ef53ed32a3b/apps/codecov-api/graphql_api/types/repository/repository.graphql#L95 All of this stuff basically would be in the GQL request IIRC.

But for repositories also maybe not, because it returns a set of RepositoryConnections, in which case idk when we'd return 404 or 403 🤔 Something we can maybe talk about later

Copy link

codecov bot commented Jul 10, 2025

Codecov Report

Attention: Patch coverage is 97.35099% with 4 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ntry/codecov/endpoints/Repositories/serializers.py 91.17% 3 Missing ⚠️
...try/codecov/endpoints/Repositories/repositories.py 97.61% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #95181      +/-   ##
==========================================
+ Coverage   87.83%   87.84%   +0.01%     
==========================================
  Files       10478    10487       +9     
  Lines      605897   605479     -418     
  Branches    23668    23586      -82     
==========================================
- Hits       532177   531880     -297     
+ Misses      73356    73239     -117     
+ Partials      364      360       -4     

@GabeVillalobos
Copy link
Member

Is there a tech spec detailing which new API endpoints we're implementing within Sentry? We probably need security to review these and the data we're ferrying to Codecov in the process.

@GabeVillalobos GabeVillalobos requested a review from a team July 10, 2025 18:13
@@ -3307,6 +3308,11 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
TestResultsAggregatesEndpoint.as_view(),
name="sentry-api-0-test-results-aggregates",
),
re_path(
Copy link
Member

Choose a reason for hiding this comment

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

i realize this is beyond the scope of this - but these URLs are not maintainable - they should all be prefixed if we're allowing repo access outside of org-scoped queries

e.g. /gh-repos/ or something similar

Copy link
Contributor

@ajay-sentry ajay-sentry Jul 10, 2025

Choose a reason for hiding this comment

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

@dcramer We actually just moved these over to be org scoped hehe. This one will be rebased and further created endpoints will follow suit

Related slack thread: https://sentry.slack.com/archives/C08HLC09Z8A/p1752079936486329

@ajay-sentry
Copy link
Contributor

@GabeVillalobos We're pulling data from Codecov rather than ferrying to Codecov, unless you mean the request parameters for these endpoints?

@GabeVillalobos
Copy link
Member

@GabeVillalobos We're pulling data from Codecov rather than ferrying to Codecov, unless you mean the request parameters for these endpoints?

@ajay-sentry Yep, I'm mainly interested in request parameters, or request bodies for future PUT/POST requests.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@@ -1065,6 +1066,11 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
TestResultsAggregatesEndpoint.as_view(),
name="sentry-api-0-test-results-aggregates",
),
re_path(
r"^owner/(?P<owner>[^/]+)/repositories/$",
Copy link
Contributor

Choose a reason for hiding this comment

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

man, this made me realize I probably should've named the other routes repositories rather than repository, maybe I can do a follow up on this

}
}
pageInfo {
endCursor
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add hasPreviousPage and startCursor?

), f"Response keys {response_keys} don't match serializer fields {serializer_fields}"

@patch("sentry.codecov.endpoints.Repositories.repositories.CodecovApiClient")
def test_get_with_query_parameters(self, mock_codecov_client_class):
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is just testing for the "term" query parameter right? Not all of them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will add test w/ all the query params

assert response.status_code == 200

@patch("sentry.codecov.endpoints.Repositories.repositories.CodecovApiClient")
def test_get_with_last_parameter(self, mock_codecov_client_class):
Copy link
Contributor

Choose a reason for hiding this comment

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

wonder if we should do a similar thing like we did in test_results where we just had the "no response mock" be a const at the top of the file so we can keep the rest of the test pretty lean

try:
first = int(first_param) if first_param is not None else None
last = int(last_param) if last_param is not None else None
except ValueError:
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add some simple tests for these error responses?

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.

mostly small stuff, looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants