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

Use GITHUB_SERVER_URL to change GitHub API host for dependency graph submission #1547

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/vcpkg/base/downloads.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ namespace vcpkg
View<std::string> headers,
View<std::string> secrets);

bool send_snapshot_to_api(const std::string& github_token,
const std::string& github_repository,
const Json::Object& snapshot);
bool submit_github_dependency_graph_snapshot(const Optional<std::string>& maybe_github_server_url,
const std::string& github_token,
const std::string& github_repository,
const Json::Object& snapshot);
ExpectedL<int> put_file(const ReadOnlyFilesystem&,
StringView url,
const std::vector<std::string>& secrets,
Expand Down
24 changes: 19 additions & 5 deletions src/vcpkg/base/downloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,27 @@ namespace vcpkg
secrets);
}

bool send_snapshot_to_api(const std::string& github_token,
const std::string& github_repository,
const Json::Object& snapshot)
bool submit_github_dependency_graph_snapshot(const Optional<std::string>& maybe_github_server_url,
const std::string& github_token,
const std::string& github_repository,
const Json::Object& snapshot)
{
static constexpr StringLiteral guid_marker = "fcfad8a3-bb68-4a54-ad00-dab1ff671ed2";

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));

auto cmd = Command{"curl"};
cmd.string_arg("-w").string_arg("\\n" + guid_marker.to_string() + "%{http_code}");
cmd.string_arg("-X").string_arg("POST");
Expand All @@ -497,8 +512,7 @@ namespace vcpkg
std::string res = "Authorization: Bearer " + github_token;
cmd.string_arg("-H").string_arg(res);
cmd.string_arg("-H").string_arg("X-GitHub-Api-Version: 2022-11-28");
cmd.string_arg(Strings::concat(
"https://api.github.com/repos/", url_encode_spaces(github_repository), "/dependency-graph/snapshots"));
cmd.string_arg(uri);
cmd.string_arg("-d").string_arg("@-");

RedirectedProcessLaunchSettings settings;
Expand Down
16 changes: 10 additions & 6 deletions src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,16 @@ namespace vcpkg
if (paths.manifest_mode_enabled() && paths.get_feature_flags().dependency_graph)
{
msg::println(msgDependencyGraphCalculation);
auto snapshot = create_dependency_graph_snapshot(args, action_plan);
bool s = false;
if (snapshot.has_value() && args.github_token.has_value() && args.github_repository.has_value())
auto maybe_snapshot = create_dependency_graph_snapshot(args, action_plan);
auto snapshot = maybe_snapshot.get();
auto github_token = args.github_token.get();
auto github_repository = args.github_repository.get();
bool dependency_graph_success = false;
if (snapshot && github_token && github_repository)
{
s = send_snapshot_to_api(*args.github_token.get(), *args.github_repository.get(), *snapshot.get());
if (s)
dependency_graph_success = submit_github_dependency_graph_snapshot(
args.github_server_url, *github_token, *github_repository, *snapshot);
if (dependency_graph_success)
{
msg::println(msgDependencyGraphSuccess);
}
Expand All @@ -208,7 +212,7 @@ namespace vcpkg
msg::println(msgDependencyGraphFailure);
}
}
get_global_metrics_collector().track_bool(BoolMetric::DependencyGraphSuccess, s);
get_global_metrics_collector().track_bool(BoolMetric::DependencyGraphSuccess, dependency_graph_success);
}

// currently (or once) installed specifications
Expand Down