Add the same support for source_packaging_publishing_history::distro_series

main
Simon Quigley 1 month ago
parent b963524519
commit 9d15a0f2f7

@ -13,9 +13,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "build.h"
#include "source_package_publishing_history.h" #include "source_package_publishing_history.h"
#include "utils.h" #include "build.h"
#include "launchpad.h" #include "launchpad.h"
#include <iostream> #include <iostream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@ -46,6 +45,10 @@ void source_package_publishing_history::parse_json(const std::string& json_data)
if (data.contains("self_link") && data["self_link"].is_string()) { if (data.contains("self_link") && data["self_link"].is_string()) {
self_link = data["self_link"].get<std::string>(); self_link = data["self_link"].get<std::string>();
} }
if (data.contains("distro_series_link") && data["distro_series_link"].is_string()) {
distro_series_link = data["distro_series_link"].get<std::string>();
}
} catch (const std::exception& e) { } catch (const std::exception& e) {
std::cerr << "Error parsing source JSON: " << e.what() << std::endl; std::cerr << "Error parsing source JSON: " << e.what() << std::endl;
} }
@ -76,3 +79,15 @@ std::generator<build> source_package_publishing_history::getBuilds() const {
void source_package_publishing_history::set_lp(launchpad* lp_ptr) { void source_package_publishing_history::set_lp(launchpad* lp_ptr) {
lp = lp_ptr; lp = lp_ptr;
} }
const std::optional<class distro_series> source_package_publishing_history::getDistroSeries() {
auto response = lp->api_get(distro_series_link);
if (!response) return std::nullopt;
auto data = nlohmann::json::parse(response.value());
auto ds = distro_series::parse(data.dump());
if (ds) {
ds->set_lp(lp);
return ds;
}
return std::nullopt;
}

@ -19,6 +19,7 @@
#include <string> #include <string>
#include <optional> #include <optional>
#include <generator> #include <generator>
#include "distro_series.h"
class launchpad; class launchpad;
class build; class build;
@ -36,12 +37,13 @@ public:
source_package_publishing_history(); source_package_publishing_history();
~source_package_publishing_history(); ~source_package_publishing_history();
// Add static parse method declaration
static std::optional<source_package_publishing_history> parse(const std::string& json_data); static std::optional<source_package_publishing_history> parse(const std::string& json_data);
void parse_json(const std::string& json_data); void parse_json(const std::string& json_data);
std::generator<build> getBuilds() const; std::generator<build> getBuilds() const;
std::optional<class distro_series> distro_series = getDistroSeries();
std::string distro_series_link;
std::string self_link; std::string self_link;
std::string source_package_name; std::string source_package_name;
std::string source_package_version; std::string source_package_version;
@ -50,6 +52,7 @@ public:
private: private:
launchpad* lp; launchpad* lp;
const std::optional<class distro_series> getDistroSeries();
}; };
#endif // SOURCE_PACKAGE_PUBLISHING_HISTORY #endif // SOURCE_PACKAGE_PUBLISHING_HISTORY

Loading…
Cancel
Save