summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-02-26 22:36:51 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-03-04 22:55:18 +0000
commit14bcb584cf2df8a7f519bbc635b2b459aacdcb10 (patch)
tree8bea0ce71e50f817cfbae20cc356302ede7e6cb0
parentCreate git utils (diff)
downloadgentoobrowse-api-14bcb584cf2df8a7f519bbc635b2b459aacdcb10.tar.bz2
gentoobrowse-api-14bcb584cf2df8a7f519bbc635b2b459aacdcb10.tar.xz
gentoobrowse-api-14bcb584cf2df8a7f519bbc635b2b459aacdcb10.zip
Add service methods to update repositories
-rw-r--r--gentoobrowse-api/api/maintenance.ice1
-rw-r--r--gentoobrowse-api/db/schema.sql4
-rw-r--r--gentoobrowse-api/service/maintenanceGitOperations.cpp12
-rw-r--r--gentoobrowse-api/service/maintenanceimpl.h1
-rw-r--r--gentoobrowse-api/service/sql/maintenance/reposToUpdate.sql4
-rw-r--r--gentoobrowse-api/unittests/Jamfile.jam2
-rw-r--r--gentoobrowse-api/unittests/testMaintenance.cpp57
7 files changed, 80 insertions, 1 deletions
diff --git a/gentoobrowse-api/api/maintenance.ice b/gentoobrowse-api/api/maintenance.ice
index 335cd7e..3a4c038 100644
--- a/gentoobrowse-api/api/maintenance.ice
+++ b/gentoobrowse-api/api/maintenance.ice
@@ -13,6 +13,7 @@ module Gentoo {
idempotent void refreshPackageTree();
idempotent void refreshBugs();
idempotent void refreshChangeLogs() throws GitError;
+ idempotent void updateRepositories() throws GitError;
UserNews getUserNews();
void sendNotifications();
};
diff --git a/gentoobrowse-api/db/schema.sql b/gentoobrowse-api/db/schema.sql
index cb74add..f1bee54 100644
--- a/gentoobrowse-api/db/schema.sql
+++ b/gentoobrowse-api/db/schema.sql
@@ -473,7 +473,9 @@ COMMENT ON TABLE package_urls IS 'URLs associated with a given package';
CREATE TABLE repos (
repoid integer NOT NULL,
name text NOT NULL,
- path text NOT NULL
+ path text NOT NULL,
+ upstream text,
+ branch text
);
ALTER TABLE repos OWNER TO gentoo;
-- Name: repos_repoid_seq; Type: SEQUENCE; Schema: gentoobrowse; Owner: gentoo
diff --git a/gentoobrowse-api/service/maintenanceGitOperations.cpp b/gentoobrowse-api/service/maintenanceGitOperations.cpp
index 84fe352..5aa3ae4 100644
--- a/gentoobrowse-api/service/maintenanceGitOperations.cpp
+++ b/gentoobrowse-api/service/maintenanceGitOperations.cpp
@@ -9,6 +9,7 @@
#include <sql/maintenance/changeLogRoots.sql.h>
#include <sql/maintenance/changeLogInsert.sql.h>
#include <sql/maintenance/changeLogRepoCommits.sql.h>
+#include <sql/maintenance/reposToUpdate.sql.h>
#include <portage-models.h>
#include "utils/git.h"
#include "converters.h"
@@ -114,6 +115,17 @@ namespace Gentoo {
}
});
}
+
+ void
+ Maintenance::updateRepositories(const Ice::Current &)
+ {
+ git_libgit2_init();
+ AdHoc::ScopeExit shutdownlibgit2(&git_libgit2_shutdown);
+
+ auto dbc = db->get();
+ sql::maintenance::reposToUpdate.select(dbc.get())->forEachRow<std::string, std::string, std::string>(&updateRepository);
+ }
+
}
}
diff --git a/gentoobrowse-api/service/maintenanceimpl.h b/gentoobrowse-api/service/maintenanceimpl.h
index 57ea94a..c55d74b 100644
--- a/gentoobrowse-api/service/maintenanceimpl.h
+++ b/gentoobrowse-api/service/maintenanceimpl.h
@@ -42,6 +42,7 @@ namespace Gentoo {
void refreshPackageTree(const Ice::Current &) override;
void refreshBugs(const Ice::Current &) override;
void refreshChangeLogs(const Ice::Current &) override;
+ void updateRepositories(const Ice::Current &) override;
Gentoo::UserNews getUserNews(const Ice::Current &) override;
void sendNotifications(const Ice::Current &) override;
diff --git a/gentoobrowse-api/service/sql/maintenance/reposToUpdate.sql b/gentoobrowse-api/service/sql/maintenance/reposToUpdate.sql
new file mode 100644
index 0000000..d373418
--- /dev/null
+++ b/gentoobrowse-api/service/sql/maintenance/reposToUpdate.sql
@@ -0,0 +1,4 @@
+SELECT path, upstream, branch
+FROM gentoobrowse.repos
+WHERE upstream IS NOT NULL
+AND branch IS NOT NULL
diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam
index 7ee7ab1..558d7d9 100644
--- a/gentoobrowse-api/unittests/Jamfile.jam
+++ b/gentoobrowse-api/unittests/Jamfile.jam
@@ -3,6 +3,7 @@ import testing ;
lib boost_utf : : <name>boost_unit_test_framework ;
lib dbpp-postgresql : : : : <include>/usr/include/dbpp-postgresql ;
lib dl ;
+lib git2 ;
lib tidy ;
lib dryice : : : : <include>/usr/include/icetray ;
@@ -83,6 +84,7 @@ run
<dependency>../db/schema.sql
<define>BOOST_TEST_DYN_LINK
<library>testCommon
+ <library>git2
<implicit-dependency>testCommon
: testMaintenance ;
diff --git a/gentoobrowse-api/unittests/testMaintenance.cpp b/gentoobrowse-api/unittests/testMaintenance.cpp
index 015a596..1ee94bc 100644
--- a/gentoobrowse-api/unittests/testMaintenance.cpp
+++ b/gentoobrowse-api/unittests/testMaintenance.cpp
@@ -5,6 +5,7 @@
#include <definedDirs.h>
#include <buffer.h>
#include <modifycommand.h>
+#include <git2.h>
class MaintenanceClientCombined : public Maintenance, public TestClient { };
@@ -114,5 +115,61 @@ BOOST_AUTO_TEST_CASE( refreshPackageTree )
m, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
+static
+git_oid
+create_initial_commit(git_repository *repo)
+{
+ git_signature * sig;
+ git_index * index;
+ git_oid tree_id, commit_id;
+ git_tree * tree;
+
+ BOOST_REQUIRE_EQUAL(0, git_signature_default(&sig, repo));
+ BOOST_REQUIRE_EQUAL(0, git_repository_index(&index, repo));
+ BOOST_REQUIRE_EQUAL(0, git_index_write_tree(&tree_id, index));
+ BOOST_REQUIRE_EQUAL(0, git_tree_lookup(&tree, repo, &tree_id));
+ BOOST_REQUIRE_EQUAL(0, git_commit_create_v( &commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0));
+
+ git_index_free(index);
+ git_tree_free(tree);
+ git_signature_free(sig);
+ return commit_id;
+}
+
+BOOST_AUTO_TEST_CASE( testUpdateGitRepository )
+{
+ auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("GentooBrowseAPI"));
+ auto testRepo = binDir / "testrepo";
+ boost::filesystem::remove_all(testRepo);
+ boost::filesystem::create_directories(testRepo);
+ // Create a stub repo to update
+ git_libgit2_init();
+ git_repository * repo;
+ BOOST_REQUIRE_EQUAL(0, git_repository_init(&repo, testRepo.c_str(), false));
+ git_remote * origin;
+ BOOST_REQUIRE_EQUAL(0, git_remote_create(&origin, repo, "origin", "http://git.randomdan.homeip.net/git/portage"));
+ git_remote_free(origin);
+ create_initial_commit(repo);
+ git_repository_free(repo);
+ git_libgit2_shutdown();
+ // Reference it
+ auto insRepo = db->modify("INSERT INTO gentoobrowse.repos(name, path, upstream, branch) VALUES(?, ?, ?, ?)");
+ insRepo->bindParamS(0, "testrepo");
+ insRepo->bindParamS(1, testRepo.string());
+ insRepo->bindParamS(2, "origin");
+ insRepo->bindParamS(3, "master");
+ insRepo->execute();
+
+ // Update
+ m->updateRepositories();
+
+ // Verify checkout
+ BOOST_REQUIRE(boost::filesystem::is_directory(testRepo));
+ BOOST_REQUIRE(boost::filesystem::is_directory(testRepo / "virtual"));
+ BOOST_REQUIRE(boost::filesystem::is_directory(testRepo / "net-misc"));
+ BOOST_REQUIRE(boost::filesystem::is_directory(testRepo / "net-misc" / "gentoobrowse-api"));
+ BOOST_REQUIRE(boost::filesystem::is_regular_file(testRepo / "net-misc" / "gentoobrowse-api" / "Manifest"));
+}
+
BOOST_AUTO_TEST_SUITE_END();