-
Notifications
You must be signed in to change notification settings - Fork 1k
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
NuGet efficiency #8679
Merged
Merged
NuGet efficiency #8679
Changes from 20 commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
a0276bf
Resilience
ryanbrandenburg 1302377
PR cleanup
ryanbrandenburg 8b9a614
Lint rules
ryanbrandenburg 00ccb43
Lint rules
ryanbrandenburg b470486
Lint rules
ryanbrandenburg fe651b8
Lint cleanup
ryanbrandenburg ed8a1f9
Lint cleanup
ryanbrandenburg b7fd729
Fix nil assignment
ryanbrandenburg e3576b3
Lint fix
ryanbrandenburg 946df05
Merge branch 'main' of https://github.com/dependabot/dependabot-core …
ryanbrandenburg df81998
adjust spec
ryanbrandenburg c130032
Repo details
ryanbrandenburg c10bc75
Lint
ryanbrandenburg 3c54a4b
Cleanup
ryanbrandenburg 7e6bf5e
Cleanup
ryanbrandenburg bac5898
Cleanup
ryanbrandenburg 8db360b
Cleanup extra cache items
ryanbrandenburg 665119f
Fix tests
ryanbrandenburg d4440eb
Merge branch 'main' of https://github.com/dependabot/dependabot-core …
ryanbrandenburg 87c7bc9
Lint
ryanbrandenburg bd37d3f
Lint fixes
ryanbrandenburg 44e95fc
Fix tests
ryanbrandenburg bb8b2d1
registration test
ryanbrandenburg 4b00f86
PR feedback
ryanbrandenburg cb4e47d
registration test
ryanbrandenburg 5ef3f21
Testing
ryanbrandenburg afaf2d2
Reigstrations
ryanbrandenburg e6061cc
Expand registration url
ryanbrandenburg 8c6915d
Lint fix
ryanbrandenburg f3ac081
Fix registration
ryanbrandenburg 228133a
Fix registration
ryanbrandenburg b13c192
Lint
ryanbrandenburg d0c8878
Registration fix
ryanbrandenburg 966fc03
fix paged version
ryanbrandenburg c976527
Fix test
ryanbrandenburg af5f684
Fix expectations
ryanbrandenburg 24f366d
Fix expectations
ryanbrandenburg 8f9f61c
Fix versions
ryanbrandenburg 0188de5
Fix tests
ryanbrandenburg 78c6635
Fix tests
ryanbrandenburg 540ea34
temp versions
ryanbrandenburg bc3d689
Fixture cleanup
ryanbrandenburg f94ada4
Cleanup
ryanbrandenburg 8ec5f33
Tweek results
ryanbrandenburg c462cb3
Tweet results
ryanbrandenburg e06a931
Tweet results
ryanbrandenburg e0e96ce
Update zero-width
ryanbrandenburg a907cb6
Merge branch 'main' of https://github.com/dependabot/dependabot-core …
ryanbrandenburg 00031d7
Add caching back for file_fetcher
ryanbrandenburg 68c1655
Lint
ryanbrandenburg b2f2b48
Lint
ryanbrandenburg 7eb8262
Lint
ryanbrandenburg 1ff67a9
Lint
ryanbrandenburg fe4bc98
Lint
ryanbrandenburg caae36c
use CacheManager
ryanbrandenburg 06758b5
Merge branch 'main' of https://github.com/dependabot/dependabot-core …
ryanbrandenburg 59ac615
Don't use CacheManager
ryanbrandenburg c26f674
Merge branch 'main' into dev/rybrande/NugetJsonParse
jakecoffman f6424ba
Refactor Nuget APIs
ryanbrandenburg bd970af
Fix requires and lint
ryanbrandenburg 0ae58b5
Fix Sorbet complaints
ryanbrandenburg 243f8cc
Fix Sorbet complaints
ryanbrandenburg 5bc51da
Fix file load issues
ryanbrandenburg 322e490
Merge branch 'main' of https://github.com/dependabot/dependabot-core …
ryanbrandenburg 9c0fe42
Cleanup specs
ryanbrandenburg 18e6e17
Handle 404 requests gracefully
ryanbrandenburg eff9637
Nil handling
ryanbrandenburg 8be7546
PR feedback
ryanbrandenburg 28319fc
Lint cleanup
ryanbrandenburg a7608ee
Lint cleanup
ryanbrandenburg f19e73c
Fix tests
ryanbrandenburg cb456f2
Guard clause
ryanbrandenburg 4e35f4a
Fix tests
ryanbrandenburg b63e8ce
Lint length
ryanbrandenburg 10f251b
Non-standard API
ryanbrandenburg e65660e
No results
ryanbrandenburg 2c4351c
Adjust with-results index.json
ryanbrandenburg ccb3dcb
Stub next request
ryanbrandenburg b50a764
Merge branch 'main' of https://github.com/dependabot/dependabot-core …
ryanbrandenburg 80e9898
PR feedback
ryanbrandenburg d48cf85
Lint cleanup
ryanbrandenburg f2dc11a
Merge branch 'main' of https://github.com/dependabot/dependabot-core …
ryanbrandenburg 379eedf
Merge branch 'main' into dev/rybrande/NugetJsonParse
bdragon d28427b
Merge branch 'main' into dev/rybrande/NugetJsonParse
bdragon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ def find_dependency_urls | |
end.compact.uniq | ||
end | ||
|
||
# rubocop:disable Metrics/AbcSize | ||
def build_url_for_details(repo_details) | ||
response = get_repo_metadata(repo_details) | ||
check_repo_response(response, repo_details) | ||
|
@@ -62,7 +63,9 @@ def build_url_for_details(repo_details) | |
body = remove_wrapping_zero_width_chars(response.body) | ||
base_url = base_url_from_v3_metadata(JSON.parse(body)) | ||
resolved_base_url = base_url || repo_details.fetch(:url).gsub("/index.json", "-flatcontainer") | ||
search_url = search_url_from_v3_metadata(JSON.parse(body)) | ||
parsed_json = JSON.parse(body) | ||
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. We should move this up so we can use it when getting the base_url from the response body. |
||
search_url = search_url_from_v3_metadata(parsed_json) | ||
registration_url = registration_url_from_v3_metadata(parsed_json) | ||
|
||
details = { | ||
base_url: resolved_base_url, | ||
|
@@ -78,18 +81,30 @@ def build_url_for_details(repo_details) | |
details[:search_url] = | ||
search_url + "?q=#{dependency.name.downcase}&prerelease=true&semVerLevel=2.0.0" | ||
end | ||
|
||
details[:registration_url] = registration_url + dependency.name.downcase if registration_url | ||
|
||
details | ||
rescue JSON::ParserError | ||
build_v2_url(response, repo_details) | ||
rescue Excon::Error::Timeout, Excon::Error::Socket | ||
handle_timeout(repo_metadata_url: repo_details.fetch(:url)) | ||
end | ||
# rubocop:enable Metrics/AbcSize | ||
|
||
def get_repo_metadata(repo_details) | ||
Dependabot::RegistryClient.get( | ||
url: repo_details.fetch(:url), | ||
headers: auth_header_for_token(repo_details.fetch(:token)) | ||
) | ||
url = repo_details.fetch(:url) | ||
cache = CacheManager.cache("repo_finder_metadatacache") | ||
if !CacheManager.caching_disabled? && cache[url] | ||
cache[url] | ||
else | ||
result = Dependabot::RegistryClient.get( | ||
url: url, | ||
headers: auth_header_for_token(repo_details.fetch(:token)) | ||
) | ||
cache[url] = result | ||
result | ||
end | ||
end | ||
|
||
def base_url_from_v3_metadata(metadata) | ||
|
@@ -99,6 +114,17 @@ def base_url_from_v3_metadata(metadata) | |
&.fetch("@id") | ||
end | ||
|
||
def registration_url_from_v3_metadata(metadata) | ||
allowed_registration_types = %w( | ||
RegistrationsBaseUrl/3.0.0-beta | ||
RegistrationsBaseUrl | ||
) | ||
ryanbrandenburg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
metadata | ||
.fetch("resources", []) | ||
.find { |r| allowed_registration_types.find { |s| r.fetch("@type") == s } } | ||
&.fetch("@id") | ||
end | ||
|
||
def search_url_from_v3_metadata(metadata) | ||
# allowable values from here: https://learn.microsoft.com/en-us/nuget/api/search-query-service-resource#versioning | ||
allowed_search_types = %w( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not for this PR, but I think this method would is a good candidate for some cleanup. Doing a bit more than building a url. Would we want to encapsulate parsing the repo metadata response somewhere else?