From af28992bce1383e1bd1bf3f370c2bcd708d74144 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 9 Dec 2015 03:47:01 +0000 Subject: Add bugs list support --- gentoobrowse-api/api/portage.ice | 4 +++ gentoobrowse-api/domain/extended-models.ice | 5 ++++ gentoobrowse-api/domain/portage-models.ice | 9 ++++++ gentoobrowse-api/service/portageimpl.cpp | 21 ++++++++++++++ gentoobrowse-api/service/portageimpl.h | 4 +++ gentoobrowse-api/service/sql/portage/getBug.sql | 3 ++ .../service/sql/portage/getBugsSearch.sql | 5 ++++ .../service/sql/portage/getPackageBugs.sql | 5 ++++ .../unittests/fixtures/package_bugs.dat | 2 ++ gentoobrowse-api/unittests/testPortage.cpp | 33 ++++++++++++++++++++++ 10 files changed, 91 insertions(+) create mode 100644 gentoobrowse-api/service/sql/portage/getBug.sql create mode 100644 gentoobrowse-api/service/sql/portage/getBugsSearch.sql create mode 100644 gentoobrowse-api/service/sql/portage/getPackageBugs.sql diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index 9ac9899..00f4730 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -12,6 +12,10 @@ module Gentoo { idempotent optional(0) Package findPackage(string category, string package); idempotent Packages getPackagesInCategory(int id); idempotent SearchResultPackages getPackagesSearch(string query); + + idempotent Bug getBug(int id); + idempotent Bugs getPackageBugs(int packageId); + idempotent SearchResultBugs getBugsSearch(string query); }; }; diff --git a/gentoobrowse-api/domain/extended-models.ice b/gentoobrowse-api/domain/extended-models.ice index 956692f..cccd45a 100644 --- a/gentoobrowse-api/domain/extended-models.ice +++ b/gentoobrowse-api/domain/extended-models.ice @@ -12,7 +12,12 @@ module Gentoo { double rank; }; + class SearchResultBug extends Bug { + double rank; + }; + sequence SearchResultPackages; + sequence SearchResultBugs; sequence OverviewCategories; }; diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index 9593315..2efe985 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -34,9 +34,18 @@ module Gentoo { optional(1) string license; }; + class Bug { + ["slicer:db:pkey"] + int bugid; + string severity; + string status; + string summary; + }; + sequence Categories; sequence Packages; sequence Ebuilds; + sequence Bugs; }; #endif diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index f7881fa..9e495e2 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include Portage::Portage(AdHoc::ResourcePool & d) : AbstractDatabaseClient(d) @@ -61,3 +64,21 @@ Portage::getPackagesSearch(const std::string & query, const Ice::Current &) return fetch(query, query); } +Gentoo::BugPtr +Portage::getBug(Ice::Int id, const Ice::Current &) +{ + return fetch(id); +} + +Gentoo::Bugs +Portage::getPackageBugs(Ice::Int packageId, const Ice::Current &) +{ + return fetch(packageId); +} + +Gentoo::SearchResultBugs +Portage::getBugsSearch(const std::string & query, const Ice::Current &) +{ + return fetch(query, query); +} + diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index f72fee2..5adae46 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -18,6 +18,10 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, AbstractDatabaseClient { IceUtil::Optional findPackage(const std::string &, const std::string &, const Ice::Current &) override; Gentoo::Packages getPackagesInCategory(Ice::Int id, const Ice::Current &) override; Gentoo::SearchResultPackages getPackagesSearch(const std::string & query, const Ice::Current &) override; + + Gentoo::BugPtr getBug(Ice::Int id, const Ice::Current &) override; + Gentoo::Bugs getPackageBugs(Ice::Int packageId, const Ice::Current &) override; + Gentoo::SearchResultBugs getBugsSearch(const std::string & query, const Ice::Current &) override; }; #endif diff --git a/gentoobrowse-api/service/sql/portage/getBug.sql b/gentoobrowse-api/service/sql/portage/getBug.sql new file mode 100644 index 0000000..b91b1a6 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getBug.sql @@ -0,0 +1,3 @@ +SELECT b.bugid, b.severity, b.status, b.summary +FROM gentoobrowse.bugs b +WHERE b.bugid = ? diff --git a/gentoobrowse-api/service/sql/portage/getBugsSearch.sql b/gentoobrowse-api/service/sql/portage/getBugsSearch.sql new file mode 100644 index 0000000..856dc7b --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getBugsSearch.sql @@ -0,0 +1,5 @@ +SELECT b.bugid, b.severity, b.status, b.summary, + ts_rank(gentoobrowse.bugfts(b), plainto_tsquery('english', ?)) rank +FROM gentoobrowse.bugs b +WHERE gentoobrowse.bugfts(b) @@ plainto_tsquery('english', ?) +ORDER BY rank DESC, bugid diff --git a/gentoobrowse-api/service/sql/portage/getPackageBugs.sql b/gentoobrowse-api/service/sql/portage/getPackageBugs.sql new file mode 100644 index 0000000..ed9cee8 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getPackageBugs.sql @@ -0,0 +1,5 @@ +SELECT b.bugid, b.severity, b.status, b.summary +FROM gentoobrowse.bugs b, gentoobrowse.package_bugs pb +WHERE b.bugid = pb.bugid +AND pb.packageid = ? +ORDER BY b.bugid diff --git a/gentoobrowse-api/unittests/fixtures/package_bugs.dat b/gentoobrowse-api/unittests/fixtures/package_bugs.dat index e69de29..3ef448f 100644 --- a/gentoobrowse-api/unittests/fixtures/package_bugs.dat +++ b/gentoobrowse-api/unittests/fixtures/package_bugs.dat @@ -0,0 +1,2 @@ +55923 567108 2010-06-19 14:36:57.532747 +55925 567166 2010-06-19 14:36:57.532747 diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index a0b62a8..b6fa56a 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -150,6 +150,39 @@ BOOST_AUTO_TEST_CASE( searchNotFound ) BOOST_REQUIRE(matches.empty()); } +BOOST_AUTO_TEST_CASE( getBug ) +{ + MockPool mp; + auto p = Portage::PointerType(new Portage(mp)); + auto b = p->getBug(567064); + BOOST_REQUIRE(b); + BOOST_REQUIRE_EQUAL(567064, b->bugid); + BOOST_REQUIRE_EQUAL("normal", b->severity); + BOOST_REQUIRE_EQUAL("UNCONFIRMED", b->status); + BOOST_REQUIRE_EQUAL("Request for new package: dev-python/twine", b->summary); +} + +BOOST_AUTO_TEST_CASE( getPackageBugs ) +{ + MockPool mp; + auto p = Portage::PointerType(new Portage(mp)); + auto bs = p->getPackageBugs(55925); + BOOST_REQUIRE_EQUAL(1, bs.size()); + BOOST_REQUIRE_EQUAL(567166, bs.front()->bugid); +} + +BOOST_AUTO_TEST_CASE( getBugsSearch ) +{ + MockPool mp; + auto p = Portage::PointerType(new Portage(mp)); + auto bs = p->getBugsSearch("cpu"); + BOOST_REQUIRE_EQUAL(3, bs.size()); + BOOST_REQUIRE_EQUAL(567154, bs[0]->bugid); + BOOST_REQUIRE_CLOSE(0.06, bs[0]->rank, 2.0); + BOOST_REQUIRE_EQUAL(567250, bs[1]->bugid); + BOOST_REQUIRE_EQUAL(567682, bs[2]->bugid); +} + BOOST_AUTO_TEST_CASE( cache ) { MockPool mp; -- cgit v1.2.3