about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-10-03 11:39:43 +0200
committerfranck cuny <franck@lumberjaph.net>2010-10-03 11:39:43 +0200
commitf82c83ffb32be0ef286cd31401e6d6f7b494591c (patch)
tree5acd7f778d69475b48e424927d5e83f1a930b543 /lib
parentuse dbic (diff)
downloadjitterbug-f82c83ffb32be0ef286cd31401e6d6f7b494591c.tar.gz
update project listing
Diffstat (limited to 'lib')
-rw-r--r--lib/jitterbug.pm49
1 files changed, 25 insertions, 24 deletions
diff --git a/lib/jitterbug.pm b/lib/jitterbug.pm
index 08a9e76..d1de03f 100644
--- a/lib/jitterbug.pm
+++ b/lib/jitterbug.pm
@@ -1,46 +1,47 @@
 package jitterbug;
 
 use Dancer ':syntax';
-use jitterbug::Plugin::Redis;
+use Dancer::Plugin::DBIC;
 use jitterbug::Plugin::Template;
 
 our $VERSION = '0.1';
 
 load_app 'jitterbug::Hook',       prefix => '/hook';
 load_app 'jitterbug::Project',    prefix => '/project';
-load_app 'jitterbug::WebService', prefix => '/api';
-load_app 'jitterbug::Task',       prefix => '/task';
+#load_app 'jitterbug::WebService', prefix => '/api';
+#load_app 'jitterbug::Task',       prefix => '/task';
 
 get '/' => sub {
 
-    my @proj_name = redis->smembers(key_projects);
-    my @projects  = ();
-
-    foreach (@proj_name) {
-        my $proj = redis->get( key_project($_) );
-        next unless $proj;
-        my $desc = from_json($proj);
-        my @ids  = redis->smembers( key_builds_project($_) );
-        my $last_build;
-        if (@ids) {
-            my $res = redis->get( pop @ids );
-            if ($res) {
-                $last_build = from_json($res);
-            }
+    my @projects = ();
+
+    my $projects = schema->resultset('Project')->search();
+    while ( my $project = $projects->next ) {
+        my $owner     = from_json( $project->owner );
+        my $proj_desc = {
+            description => $project->description,
+            name        => $project->name,
+            url         => $project->url,
+            owner_name  => $owner->{name},
+        };
+
+        my $last_commit =
+          schema->resultset('Commit')
+          ->search( { projectid => $project->projectid }, {} )->single();
+
+        if ($last_commit) {
+            # XXX see what data to store here
+            $proj_desc->{last_build} = from_json($last_commit->content);
         }
-        else {
-            $last_build = { timestamp => '' };
-        }
-        $desc->{last_build} = $last_build;
-        push @projects, $desc;
+
+        push @projects, $proj_desc;
     }
 
     @projects =
       sort { $b->{last_build}->{timestamp} cmp $a->{last_build}->{timestamp} }
       @projects;
 
-    my @tasks = redis->smembers(key_tasks);
-    template 'index', {projects => \@projects, tasks => \@tasks};
+    template 'index', {projects => \@projects};
 };
 
 true;