-
Notifications
You must be signed in to change notification settings - Fork 351
Fix GitHub API endpoint selection based on host parsing #1850
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
d7fd183
96e4029
da9910c
6adec92
ff21a82
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 |
|---|---|---|
|
|
@@ -53,6 +53,29 @@ TEST_CASE ("url_encode_spaces", "[downloads]") | |
| "https://example.com/a%20%20space/b?query=value&query2=value2"); | ||
| } | ||
|
|
||
| TEST_CASE ("github_dependency_graph_snapshots_uri", "[downloads]") | ||
| { | ||
| REQUIRE(github_dependency_graph_snapshots_uri(nullopt, "owner/repo") == | ||
| "https://api.github.com/repos/owner/repo/dependency-graph/snapshots"); | ||
|
|
||
| REQUIRE(github_dependency_graph_snapshots_uri(Optional<std::string>{"https://github.com"}, "owner/repo") == | ||
| "https://api.github.com/repos/owner/repo/dependency-graph/snapshots"); | ||
|
|
||
| REQUIRE(github_dependency_graph_snapshots_uri(Optional<std::string>{"https://github.com/"}, "owner/repo") == | ||
| "https://github.com//api/v3/repos/owner/repo/dependency-graph/snapshots"); | ||
|
|
||
| REQUIRE(github_dependency_graph_snapshots_uri(Optional<std::string>{"https://github.example.com"}, "owner/repo") == | ||
| "https://github.example.com/api/v3/repos/owner/repo/dependency-graph/snapshots"); | ||
|
|
||
| REQUIRE(github_dependency_graph_snapshots_uri(Optional<std::string>{"https://user:[email protected]:443"}, | ||
| "owner/repo") == | ||
| "https://user:[email protected]:443/api/v3/repos/owner/repo/dependency-graph/snapshots"); | ||
|
|
||
| REQUIRE( | ||
| github_dependency_graph_snapshots_uri(Optional<std::string>{"https://github.com"}, "owner/repo with space") == | ||
| "https://api.github.com/repos/owner/repo%20with%20space/dependency-graph/snapshots"); | ||
| } | ||
|
|
||
| /* | ||
| * To run this test: | ||
| * - Set environment variables VCPKG_TEST_AZBLOB_URL and VCPKG_TEST_AZBLOB_SAS. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -287,19 +287,7 @@ namespace vcpkg | |||||
| const std::string& github_repository, | ||||||
| const Json::Object& snapshot) | ||||||
| { | ||||||
| std::string uri; | ||||||
| if (auto github_server_url = maybe_github_server_url.get()) | ||||||
| { | ||||||
| uri = *github_server_url; | ||||||
| uri.append("/api/v3"); | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| uri = "https://api.github.com"; | ||||||
| } | ||||||
|
|
||||||
| fmt::format_to( | ||||||
| std::back_inserter(uri), "/repos/{}/dependency-graph/snapshots", url_encode_spaces(github_repository)); | ||||||
| const auto uri = github_dependency_graph_snapshots_uri(maybe_github_server_url, github_repository); | ||||||
|
|
||||||
| CurlEasyHandle handle; | ||||||
| CURL* curl = handle.get(); | ||||||
|
|
@@ -334,6 +322,34 @@ namespace vcpkg | |||||
| return response_code >= 200 && response_code < 300; | ||||||
| } | ||||||
|
|
||||||
| std::string github_dependency_graph_snapshots_uri(const Optional<std::string>& maybe_github_server_url, | ||||||
| StringView github_repository) | ||||||
| { | ||||||
| std::string uri; | ||||||
| constexpr StringLiteral github_com_url = "https://github.com"; | ||||||
| constexpr StringLiteral api_github_com_url = "https://api.github.com"; | ||||||
| if (auto github_server_url = maybe_github_server_url.get()) | ||||||
| { | ||||||
| if (*github_server_url == github_com_url) | ||||||
| { | ||||||
| uri = api_github_com_url.data(); | ||||||
|
Member
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.
Suggested change
Author
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. Done. |
||||||
| } | ||||||
| else | ||||||
| { | ||||||
| uri = *github_server_url; | ||||||
| uri.append("/api/v3"); | ||||||
|
Member
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. Should this defend against
Author
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. Yes, I applied. |
||||||
| } | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| uri = api_github_com_url.data(); | ||||||
|
Member
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.
Suggested change
Author
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. Done. |
||||||
| } | ||||||
|
|
||||||
| fmt::format_to( | ||||||
| std::back_inserter(uri), "/repos/{}/dependency-graph/snapshots", url_encode_spaces(github_repository)); | ||||||
| return uri; | ||||||
| } | ||||||
|
|
||||||
| static size_t read_file_callback(char* buffer, size_t size, size_t nitems, void* param) | ||||||
| { | ||||||
| auto* file = static_cast<ReadFilePointer*>(param); | ||||||
|
|
||||||
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.
Why doesn't this one become api.? (Should it use starts with rather than ==?)