Compact git logs and provide changeset links to github.
[buildfarm-server.git] / cgi-bin / show_history.pl
1 #!/usr/bin/perl
2
3 =comment
4
5 Copyright (c) 2003-2010, Andrew Dunstan
6
7 See accompanying License file for license details
8
9 =cut 
10
11 use strict;
12 use DBI;
13 use Template;
14 use CGI;
15
16 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir);
17
18
19 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
20 #require "BuildFarmWeb.pl";
21
22 die "no dbname" unless $dbname;
23 die "no dbuser" unless $dbuser;
24
25 my $dsn="dbi:Pg:dbname=$dbname";
26 $dsn .= ";host=$dbhost" if $dbhost;
27 $dsn .= ";port=$dbport" if $dbport;
28
29 my $db = DBI->connect($dsn,$dbuser,$dbpass);
30
31 die $DBI::errstr unless $db;
32
33 my $query = new CGI;
34 my $member = $query->param('nm'); $member =~ s/[^a-zA-Z0-9_ -]//g;
35 my $branch = $query->param('br'); $branch =~ s/[^a-zA-Z0-9_ -]//g;
36 my $hm = $query->param('hm');  $hm =~ s/[^a-zA-Z0-9_ -]//g;
37 $hm = '240' unless $hm =~ /^\d+$/;
38
39 my $latest_personality = $db->selectrow_arrayref(q{
40             select os_version, compiler_version
41             from personality
42             where name = ?
43             order by effective_date desc limit 1
44         }, undef, $member);
45
46 # we don't really need to do this join, since we only want
47 # one row from buildsystems. but it means we only have to run one
48 # query. If it gets heavy we'll split it up and run two
49
50 my $statement = <<EOS;
51
52   select (now() at time zone 'GMT')::timestamp(0) - snapshot as when_ago,
53       sysname, snapshot, b.status, stage,
54       operating_system, os_version, compiler, compiler_version, architecture,
55       owner_email,
56       sys_notes_ts::date AS sys_notes_date, sys_notes
57   from buildsystems s, 
58        build_status b 
59   where name = ?
60         and branch = ?
61         and s.status = 'approved'
62         and name = sysname
63   order by snapshot desc
64   limit $hm
65
66 EOS
67 ;
68
69 my $statrows=[];
70 my $sth=$db->prepare($statement);
71 $sth->execute($member,$branch);
72 while (my $row = $sth->fetchrow_hashref)
73 {
74     $row->{owner_email} =~ s/\@/ [ a t ] /;
75     if ($latest_personality)
76     {
77         $row->{os_version} = $latest_personality->[0];
78         $row->{compiler_version} = $latest_personality->[1];
79     }
80     push(@$statrows,$row);
81 }
82
83 $sth->finish;
84
85 $db->disconnect;
86
87 my $template_opts = { INCLUDE_PATH => $template_dir, EVAL_PERL => 1 };
88 my $template = new Template($template_opts);
89
90 print "Content-Type: text/html\n\n";
91
92 $template->process('history.tt',
93                    {statrows=>$statrows, 
94                     branch=>$branch, 
95                     member => $member,
96                     hm => $hm
97                     });
98
99 exit;