lib/App/Beeminder/Hook.pm

filter: Statementstmt 60.6% 20 / 33 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod n/a totaltotal 63.4% 26 / 41 CC 2 SCAR 6.2
CC
2
Cov
60%
__ANON__
3.5
__ANON__
2.0
BEGIN
1.0
CRAP 1.9
« script/app.pl ↑ Summary
1 package App::Beeminder::Hook;
2 2 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use JSON::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: Integrate Github and Beeminder
8  
9 2 our $VERSION = '0.1';
10  
11 # inspired by https://github.com/solgenomics/sgn-devtools/blob/master/git/github_post_receive
12  
13 # This will eventually use WWW::Beeminder when that is ready, but for now, curl saves the day
14 2 ▶any '/hook' => sub {
Subroutine __ANON__: called CC=2 SCAR=12.5
15 2 my $p = param('payload');
16  
17 2 ▶ unless ($p) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p) 2 0 2
18 2 my $response = JSON::Any->encode( { success => 0 } );
19 2 return $response;
20 }
21  
22 0 $p = JSON::Any->new->decode( $p );
23  
24 0 debug(Dumper($p));
25  
26 0 my $repo_name = $p->{repository}{name};
27 0 my $organization = $p->{repository}{organization};
28 0 my $num_commits = @{$p->{commits}};
29 0 my $day_of_month = (localtime(time))[3];
30  
31 0 my $cmd=<<CMD;
32 curl -d 'origin=%s&datapoints_text=%s %s "%s"&sendmail=0' %s/%s/goals/%s/datapoints/create_all
33 CMD
34  
35 $cmd = sprintf($cmd, config->{beeminder_username},
36 $day_of_month,
37 $num_commits,
38 "$organization/$repo_name", # optional comment
39 config->{beeminder_api_url},
40 config->{beeminder_username},
41 config->{beeminder_goal},
42 0 );
43 0 debug "Running: $cmd";
44 0 system $cmd;
45  
46 0 my $response = JSON::Any->encode( { success => 1 } );
47 2 };
48  
49 0 ▶get '/' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 'This is App::Beeminder::Hook';
51 2 };
52  
53 2 true;
54  
55 __END__
« script/app.pl ↑ Summary