Backlogの未完了タスクを取得する「Plagger::Plugin::CustomFeed::Backlog」をこさえた
最近Subversionにも対応したプロジェクト管理ツールBacklog、弊社でも活用しております(Tracと使い分けてます)。
せっかくAPIが公開されているし、弊社の中からも「関わるプロジェクトが多くなった際に少しでもタスクを追っかけやすくしたい」と要望も挙がっていたので、Plaggerに落としこむ事にしました。
Backlogの中の人がAPIを叩きやすいようWebService::Backlogというモジュールを用意してくれていたおかげで、大変楽ちんに作れました。
なかなか手抜きしてるところがありますが、ひとまず公開します!
Plagger/Plugin/CustomFeed/Backlog.pm
package Plagger::Plugin::CustomFeed::Backlog;
use strict;
use base qw( Plagger::Plugin );
use WebService::Backlog;
sub register {
my($self, $context) = @_;
$context->register_hook(
$self,
'subscription.load' => &load,
);
}
sub load {
my($self, $context) = @_;
$self->{backlog} = WebService::Backlog->new(
space => $self->conf->{space},
username => $self->conf->{username},
password => $self->conf->{password},
);
my $feed = Plagger::Feed->new;
$feed->aggregator(sub { $self->aggregate(@_) });
$context->subscription->add($feed);
}
sub aggregate {
my($self, $context, $args) = @_;
my $feed = Plagger::Feed->new;
my $projects = $self->{backlog}->getProjects;
my $ignore_status_id = $self->conf->{ignore_status_id} || 4;
$feed->type('backlog');
$feed->title($self->conf->{space} . ' Backlog');
$feed->author($self->conf->{space});
foreach my $project(@{$projects}){
my $users = $self->{backlog}->getUsers($project->id);
my $user_id;
foreach (@{$users}){
if ($_->name eq $self->conf->{username}){
$user_id = $_->id;
}
}
my $issue = $self->{backlog}->findIssue({
projectId => $project->id,
assignerId => $user_id,
});
foreach my $buff (@{$issue}){
next if $buff->status->id == $ignore_status_id;
my $entry = Plagger::Entry->new;
$entry->title($project->name . " : " . $buff->summary);
$entry->link($buff->url);
$entry->author($buff->created_user->name);
$entry->date($buff->updated_on);
$entry->body($buff->description);
$feed->add_entry($entry);
}
}
$context->update->add($feed);
}
1;
__END__
使いかたは、
- module: CustomFeed::Backlog
config:
space: 登録してるスペース名
username: ユーザー名
password: パスワード
ignore_status_id: 表示したくないステータスID(これは改善の余地アリ)
表示したくないステータスIDは今のところ、
未対応 : 1 処理中 : 2 処理済み : 3 完了 : 4
となっています。まぁひとまず完了タスクはいらんだろうという事で手を抜きました。
後はFilter::***とか、Publish::***とか、好きに加工してください。
複数のBacklogプロジェクトから情報を取得してRSS化とかに力を発揮するかな?
シンプルなサンプルYAMLも載せておきますね。
global:
timezone: Asia:Tokyo
log:
level: info
plugins:
- module: CustomFeed::Backlog
config:
space: space1
username: USERNAME
password: PASSWORD
- module: CustomFeed::Backlog
config:
space: space2
username: USERNAME
password: PASSWORD
- module: Publish::Feed
config:
format: RSS
dir: /foo/bar/
filename: my_%t.rss
これで/foo/bar/にmy_space1.rssとmy_space2.rssが作成され、中身が自分にAssignedされたTODOが入ったitemです。



