This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

initial import

  • Loading branch information...
1 parent 0b8a4e3 commit 585ce5b679406ffe8644b23e3a267d7af8e3a5de @fcuny committed Sep 23, 2010
View
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'jitterbug',
+ AUTHOR => q{YOUR NAME <youremail@example.com>},
+ VERSION_FROM => 'lib/jitterbug.pm',
+ ABSTRACT => 'YOUR APPLICATION ABSTRACT',
+ ($ExtUtils::MakeMaker::VERSION >= 6.3002
+ ? ('LICENSE'=> 'perl')
+ : ()),
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'YAML' => 0,
+ 'Dancer' => 1.1810,
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'jitterbug-*' },
+);
View
@@ -0,0 +1,17 @@
+layout: "main"
+logger: "file"
+appname: "jitterbug"
+serializer: "JSON"
+redis: "127.0.0.1:6379"
+template: "xslate"
+engines:
+ xslate:
+ path: /
+ type: text
+ cache: 0
+
+jitterbug:
+ reports:
+ dir: /tmp/jitterbug
+ build:
+ dir: /tmp/build
View
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use 5.010;
+use LWP::UserAgent;
+use HTTP::Request::Common;
+use YAML::Syck;
+use JSON;
+
+my $content = LoadFile('t/data/test.yaml');
+my $payload = JSON::encode_json($content);
+
+my $url = "http://localhost:5000/hook/";
+
+my $req = POST $url, [payload => $payload];
+
+my $ua = LWP::UserAgent->new();
+my $res = $ua->request($req);
+$res->is_success ? say "ok" : say "not ok";
@@ -0,0 +1,4 @@
+log: "debug"
+warnings: 1
+show_errors: 1
+auto_reload: 0
@@ -0,0 +1,6 @@
+log: "warning"
+warnings: 0
+show_errors: 0
+route_cache: 1
+auto_reload: 0
+
View
@@ -0,0 +1,5 @@
+#!/usr/bin/env perl
+use Dancer;
+use lib ('lib');
+load_app 'jitterbug';
+dance;
View
@@ -0,0 +1,24 @@
+package jitterbug;
+
+BEGIN {
+ use Dancer ':syntax';
+ load_plugin 'jitterbug::Plugin::Redis';
+};
+
+our $VERSION = '0.1';
+
+load_app 'jitterbug::Hook', prefix => '/hook';
+load_app 'jitterbug::Project', prefix => '/project';
+load_app 'jitterbug::WebService', prefix => '/api';
+
+before_template sub {
+ my $tokens = shift;
+ $tokens->{uri_base} = request->base;
+};
+
+get '/' => sub {
+ my @projects = redis->smembers(key_projects);
+ template 'index', {projects => \@projects};
+};
+
+true;
View
@@ -0,0 +1,42 @@
+package jitterbug::Hook;
+
+BEGIN {
+ use Dancer ':syntax';
+ load_plugin 'jitterbug::Plugin::Redis';
+};
+
+setting serializer => 'JSON';
+
+post '/' => sub {
+ my $hook = from_json(params->{payload});
+
+ my $repo = $hook->{repository}->{name};
+
+ my $repo_key = key_project($repo);
+
+ if ( !redis->exists($repo_key) ) {
+ my $project = {
+ name => $repo,
+ url => $hook->{repository}->{url},
+ description => $hook->{repository}->{description},
+ owner => $hook->{repository}->{owner},
+ };
+ redis->set( $repo_key, to_json($project) );
+ redis->sadd(key_projects, $repo);
+ }
+
+ my $last_commit = pop @{ $hook->{commits} };
+
+ $last_commit->{repo} = $hook->{repository}->{url};
+ $last_commit->{project} = $repo;
+ $last_commit->{compare} = $hook->{compare};
+
+ my $task_key = key_task_repo($repo);
+ redis->set($task_key, to_json($last_commit));
+
+ redis->sadd(key_tasks, $task_key);
+
+ { updated => $repo };
+};
+
+1;
@@ -0,0 +1,21 @@
+package jitterbug::Plugin::Redis;
+
+use Dancer::Config qw/setting/;
+use Dancer::Plugin;
+use Redis;
+
+register redis => sub {
+ Redis->new( server => setting('redis') );
+};
+
+sub _key { join( ':', 'jitterbug', @_ ); }
+
+register key_projects => sub { _key('projects'); };
+register key_project => sub { _key('project', @_); };
+register key_builds_project => sub { _key('builds', @_); };
+register key_task_repo => sub { _key('tasks', @_); };
+register key_tasks => sub { _key('tasks'); };
+
+register_plugin;
+
+1;
View
@@ -0,0 +1,57 @@
+package jitterbug::Project;
+
+BEGIN {
+ use Dancer ':syntax';
+ load_plugin 'jitterbug::Plugin::Redis';
+};
+
+use DateTime;
+use XML::Feed;
+
+get '/:project' => sub {
+ my $project = params->{project};
+
+ my $res = redis->get( key_project($project) );
+
+ send_error( "Project $project not found", 404 ) if !$res;
+
+ my $desc = from_json($res);
+
+ my @ids = redis->smembers( key_builds_project($project) );
+
+ my @builds;
+ foreach my $id (@ids) {
+ my $res = redis->get($id);
+ push @builds, from_json($res) if $res;
+ }
+
+ template 'project/index',
+ { project => $project, builds => \@builds, %$desc };
+};
+
+get '/:project/feed' => sub {
+ my $project = params->{project};
+
+ my @builds = reverse( redis->smembers( key_builds_project($project) ) );
+
+ my $feed = XML::Feed->new('Atom');
+ $feed->title('builds for '.$project);
+
+ foreach (splice(@builds, 0, 5)) {
+ my $res = redis->get($_);
+ next unless $res;
+ my $desc = from_json($res);
+
+ foreach my $version (keys %{$desc->{version}}) {
+ my $entry = XML::Feed::Entry->new();
+ $entry->title("build for ".$desc->{commit}.' on '.$version);
+ $entry->summary("Result: ".$desc->{version}->{$version});
+ $feed->add_entry($entry);
+ }
+ }
+
+ content_type('application/atom+xml');
+ $feed->as_xml;
+};
+
+1;
@@ -0,0 +1,34 @@
+package jitterbug::WebService;
+
+BEGIN {
+ use Dancer ':syntax';
+ load_plugin 'jitterbug::Plugin::Redis';
+}
+
+use File::Spec;
+
+set serializer => 'JSON';
+
+get '/build/:project/:commit/:version' => sub {
+ my $project = params->{project};
+ my $commit = params->{commit};
+ my $version = params->{version};
+
+ my $conf = setting 'jitterbug';
+
+ my $file = File::Spec->catfile( $conf->{reports}->{dir},
+ $project, $commit, $version . '.txt' );
+
+ if ( -f $file ) {
+ open my $fh, '<', $file;
+ my @content = <$fh>;
+ close $fh;
+ {
+ commit => $commit,
+ version => $version,
+ content => join( '', @content ),
+ };
+ }
+};
+
+1;
View
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en-US">
+<head>
+<title>Error 404</title>
+<link rel="stylesheet" href="/css/error.css" />
+<meta charset=UTF-8" />
+</head>
+<body>
+<h1>Error 404</h1>
+<div id="content">
+<h2>Page Not Found</h2><p>Sorry, this is the void.</p>
+</div>
+<footer>
+Powered by <a href="http://perldancer.org/">Dancer</a> 1.1810
+</footer>
+</body>
+</html>
View
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en-US">
+<head>
+<title>Error 500</title>
+<link rel="stylesheet" href="/css/error.css" />
+<meta charset=UTF-8" />
+</head>
+<body>
+<h1>Error 500</h1>
+<div id="content">
+<h2>Internal Server Error</h2><p>Wooops, something went wrong</p>
+</div>
+<footer>
+Powered by <a href="http://perldancer.org/">Dancer</a> 1.1810
+</footer>
+</body>
+</html>
View
@@ -0,0 +1,70 @@
+body {
+ font-family: Lucida,sans-serif;
+}
+
+h1 {
+ color: #AA0000;
+ border-bottom: 1px solid #444;
+}
+
+h2 { color: #444; }
+
+pre {
+ font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace;
+ font-size: 12px;
+ border-left: 2px solid #777;
+ padding-left: 1em;
+}
+
+footer {
+ font-size: 10px;
+}
+
+span.key {
+ color: #449;
+ font-weight: bold;
+ width: 120px;
+ display: inline;
+}
+
+span.value {
+ color: #494;
+}
+
+/* these are for the message boxes */
+
+pre.content {
+ background-color: #eee;
+ color: #000;
+ padding: 1em;
+ margin: 0;
+ border: 1px solid #aaa;
+ border-top: 0;
+ margin-bottom: 1em;
+}
+
+div.title {
+ font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace;
+ font-size: 12px;
+ background-color: #aaa;
+ color: #444;
+ font-weight: bold;
+ padding: 3px;
+ padding-left: 10px;
+}
+
+pre.content span.nu {
+ color: #889;
+ margin-right: 10px;
+}
+
+pre.error {
+ background: #334;
+ color: #ccd;
+ padding: 1em;
+ border-top: 1px solid #000;
+ border-left: 1px solid #000;
+ border-right: 1px solid #eee;
+ border-bottom: 1px solid #eee;
+}
+
Oops, something went wrong.

0 comments on commit 585ce5b

Please sign in to comment.