|
1 | 1 | #! /usr/bin/perl
|
2 | 2 | # vim:ts=4:sw=4:ai:et:si:sts=4
|
| 3 | + |
3 | 4 | use strict;
|
4 | 5 | use warnings;
|
5 | 6 | use Apache2::Const -compile => qw(M_POST HTTP_METHOD_NOT_ALLOWED);
|
6 | 7 | use CGI;
|
7 | 8 | use JSON;
|
8 | 9 | use Mail::Send;
|
9 |
| - |
10 |
| -my $debug = 1; |
| 10 | +use Config::General; |
| 11 | +use DBI; |
| 12 | +use File::Basename; |
| 13 | +use English; |
| 14 | +use Cwd 'abs_path'; |
11 | 15 |
|
12 | 16 | my $r = shift;
|
13 | 17 |
|
|
17 | 21 | return;
|
18 | 22 | }
|
19 | 23 |
|
| 24 | +my $conffile = dirname(abs_path($0 or $PROGRAM_NAME)) . "email_hook.cfg" |
| 25 | +my $conf = new Config::General($conffile); |
| 26 | +my %config = $conf->getall; |
| 27 | +
|
| 28 | +my $debug = $config{'debug'} or 0; |
| 29 | +
|
20 | 30 | $r->content_type('text/html');
|
21 | 31 | $r->print();
|
22 | 32 |
|
|
35 | 45 | my $branch = $payload->{"ref"};
|
36 | 46 | $branch =~ s/^refs\/.*?\///;
|
37 | 47 |
|
38 |
| -if ($branch !~ /^(?:master|fixes\/)/) { |
| 48 | +$regexp = qr($config{'ignoreregexp'}); |
| 49 | +if ($branch !~ $regexp) { |
39 | 50 | exit 0;
|
40 | 51 | }
|
41 | 52 |
|
| 53 | +my $dbh = DBI->connect("dbi:mysql:database=".$config{'db'}{'database'}. |
| 54 | + ":host=".$config{'db'}{'host'}, |
| 55 | + $config{'db'}{'user'}, $config{'db'}{'password'}) |
| 56 | + or die "Cannot connect to database: " . DBI::errstr . "\n"; |
| 57 | +
|
| 58 | +my $q = "SELECT sha1 FROM seen WHERE sha1 = ?"; |
| 59 | +my $select_h = $dbh->prepare($q); |
| 60 | +
|
| 61 | +$q = "INSERT INTO seen (sha1, lastseen) VALUES (?, NULL)"; |
| 62 | +my $insert_h = $dbh->prepare($q); |
| 63 | +
|
| 64 | +
|
42 | 65 | # These maybe should go into a config file later
|
43 | 66 | my %headers = (
|
44 | 67 | "From" => 'MythTV <noreply@mythtv.org>',
|
|
50 | 73 |
|
51 | 74 | foreach my $commit ( @{$payload->{"commits"}} ) {
|
52 | 75 | my $longsha = $commit->{"id"};
|
| 76 | + $select_h->execute($longsha); |
| 77 | + my ($resultsha) = $select_h->fetchrow_array; |
| 78 | + next if defined $resultsha; |
| 79 | +
|
53 | 80 | my $shortsha = substr $longsha, 0, 9;
|
54 | 81 | my $changeurl = $commit->{"url"};
|
55 | 82 | $changeurl =~ s/$longsha$/$shortsha/;
|
|
103 | 130 | my $fh = $msg->open;
|
104 | 131 | print $fh $email;
|
105 | 132 | $fh->close;
|
| 133 | +
|
| 134 | + $insert_h->execute($longsha); |
106 | 135 | }
|
107 | 136 |
|
0 commit comments