@@ -50,24 +50,27 @@ namespace vcpkg
5050 Optional<Json::Object> create_dependency_graph_snapshot (const VcpkgCmdArguments& args,
5151 const ActionPlan& action_plan)
5252 {
53- if (args.github_ref .has_value () && args.github_sha .has_value () && args.github_job .has_value () &&
54- args.github_workflow .has_value () && args.github_run_id .has_value ())
53+ const auto github_ref = args.github_ref .get ();
54+ const auto github_sha = args.github_sha .get ();
55+ const auto github_job = args.github_job .get ();
56+ const auto github_workflow = args.github_workflow .get ();
57+ const auto github_run_id = args.github_run_id .get ();
58+ if (github_ref && github_sha && github_job && github_workflow && github_run_id)
5559 {
5660 Json::Object detector;
5761 detector.insert (JsonIdName, Json::Value::string (" vcpkg" ));
5862 detector.insert (JsonIdUrl, Json::Value::string (" https://github.com/microsoft/vcpkg" ));
5963 detector.insert (JsonIdVersion, Json::Value::string (" 1.0.0" ));
6064
6165 Json::Object job;
62- job.insert (JsonIdId, Json::Value::string (*args.github_run_id .get ()));
63- job.insert (JsonIdCorrelator,
64- Json::Value::string (*args.github_workflow .get () + " -" + *args.github_job .get ()));
66+ job.insert (JsonIdId, Json::Value::string (*github_run_id));
67+ job.insert (JsonIdCorrelator, Json::Value::string (fmt::format (" {}-{}" , *github_workflow, *github_run_id)));
6568
6669 Json::Object snapshot;
6770 snapshot.insert (JsonIdJob, job);
6871 snapshot.insert (JsonIdVersion, Json::Value::integer (0 ));
69- snapshot.insert (JsonIdSha, Json::Value::string (*args. github_sha . get () ));
70- snapshot.insert (JsonIdRef, Json::Value::string (*args. github_ref . get () ));
72+ snapshot.insert (JsonIdSha, Json::Value::string (*github_sha));
73+ snapshot.insert (JsonIdRef, Json::Value::string (*github_ref));
7174 snapshot.insert (JsonIdScanned, Json::Value::string (CTime::now_string ()));
7275 snapshot.insert (JsonIdDetector, detector);
7376
@@ -77,44 +80,45 @@ namespace vcpkg
7780 std::unordered_map<std::string, std::string> map;
7881 for (auto && action : action_plan.install_actions )
7982 {
80- if (!action.source_control_file_and_location .has_value ())
83+ const auto scfl = action.source_control_file_and_location .get ();
84+ if (!scfl)
8185 {
8286 return nullopt ;
8387 }
84- const auto & scf = *action.source_control_file_and_location .get ();
85- auto version = scf.to_version ().to_string ();
86- auto s = action.spec .to_string ();
87- auto pkg_url = Strings::concat (" pkg:github/vcpkg/" , s, " @" , version);
88- map.insert ({s, pkg_url});
88+ auto spec = action.spec .to_string ();
89+ map.insert (
90+ {spec, fmt::format (" pkg:github/vcpkg/{}@{}" , spec, scfl->source_control_file ->to_version ())});
8991 }
9092
9193 Json::Object resolved;
9294 for (auto && action : action_plan.install_actions )
9395 {
9496 Json::Object resolved_item;
95- if (map.find (action.spec .to_string ()) != map.end ())
97+ auto spec = action.spec .to_string ();
98+ const auto found = map.find (spec);
99+ if (found != map.end ())
96100 {
97- auto pkg_url = map. at (action. spec . to_string ()) ;
101+ const auto & pkg_url = found-> second ;
98102 resolved_item.insert (JsonIdPackageUnderscoreUrl, pkg_url);
99103 resolved_item.insert (JsonIdRelationship, Json::Value::string (JsonIdDirect));
100104 Json::Array deps_list;
101105 for (auto && dep : action.package_dependencies )
102106 {
103- if (map.find (dep.to_string ()) != map.end ())
107+ const auto found_dep = map.find (dep.to_string ());
108+ if (found_dep != map.end ())
104109 {
105- auto dep_pkg_url = map.at (dep.to_string ());
106- deps_list.push_back (dep_pkg_url);
110+ deps_list.push_back (found_dep->second );
107111 }
108112 }
109113 resolved_item.insert (JsonIdDependencies, deps_list);
110114 resolved.insert (pkg_url, resolved_item);
111115 }
112116 }
117+
113118 manifest.insert (JsonIdResolved, resolved);
114119 Json::Object manifests;
115120 manifests.insert (JsonIdVcpkgDotJson, manifest);
116121 snapshot.insert (JsonIdManifests, manifests);
117-
118122 Debug::print (Json::stringify (snapshot));
119123 return snapshot;
120124 }
0 commit comments