Created
November 30, 2012 18:11
-
-
Save takus/4177475 to your computer and use it in GitHub Desktop.
generates daily report from redmine issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
binmode STDOUT, ":utf8"; | |
use Config::Pit; | |
use Redmine::API; | |
use Encode; | |
use DateTime; | |
use DateTime::Format::Strptime; | |
use Text::Xslate; | |
my $format = DateTime::Format::Strptime->new( | |
pattern => '%Y-%m-%dT%H:%S:%MZ', | |
time_zone => 'Asia/Tokyo', | |
); | |
my $config = pit_get("redmine2dailyreport", require => { | |
"name" => "your name", | |
"user_id" => "your redmine user_id", | |
"base_url" => "your redmine URL", | |
"auth_key" => "your auth_key of redmine", | |
}); | |
my $day_before = @ARGV ? $ARGV[0] : 0; | |
my $start = DateTime->now(time_zone => 'Asia/Tokyo')-> | |
subtract( days => $day_before )-> | |
set( hour => 0, minute => 0, second => 0 ); | |
my $date = $start->ymd('-'); | |
my $c = Redmine::API->new( | |
auth_key => $config->{auth_key}, | |
base_url => $config->{base_url}, | |
); | |
my @issue_ids = map {$_->{id}} @{$c->issues->issue->all( | |
updated_on => "><$date|$date", | |
limit => "100", | |
)->body->{issues}}; | |
my $issues; | |
for my $id (@issue_ids) { | |
my $i = $c->issues->issue->get( | |
$id, | |
include => 'journals', | |
)->body->{issue}; | |
my $note; | |
for my $j ( @{$i->{journals}} ) { | |
next if ( $j->{user}->{id} != $config->{user_id} ); | |
next if ( $format->parse_datetime($j->{created_on}) < $start ); | |
$note->{subject} = Encode::encode('utf8', $i->{subject}); | |
push @{$note->{notes}}, Encode::encode('utf8', $j->{notes}); | |
} | |
push @{$issues}, $note if ($note); | |
} | |
my $tx = Text::Xslate->new(type => 'text'); | |
my %vars = ( | |
date => $start->month . '/' . $start->day, | |
name => $config->{name}, | |
issues => $issues, | |
); | |
my $template = q{ | |
【日報】<: $date :> <: $name :> | |
お疲れ様です。<: $name :>です。 | |
本日の日報をお送り致します。 | |
: for $issues -> $issue { | |
# <: $issue.subject :> | |
: for $issue.notes-> $note { | |
<: $note :> | |
: } # for notes | |
: } # for issues | |
}; | |
print $tx->render_string($template, \%vars); | |
__END__ | |
=head1 NAME | |
redmine2dailyreport - generates daily report from redmine issues | |
=head1 SYNOPSIS | |
# generate today's daily report | |
$ ./redmine2dailyreport | |
# generate yesterday's daily report | |
$ ./redmine2dailyreport 1 | |
=head1 DESCRIPTION | |
This script gets issues updated today, | |
and generates daily report with issue's subject and journals. | |
=head1 AUTHOR | |
Takumi SAKAMOTO E<lt>takumi.saka@gmail.comE<gt> | |
=head1 LICENSE | |
This library is free software; you can redistribute it | |
and/or modify it under the same terms as Perl itself. | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment