| 1 | package App::gh::Command::Recent; | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | use base qw(App::gh::Command); | ||
| 5 | use App::gh::Utils; | ||
| 6 | use URI; | ||
| 7 | use Text::Wrap; | ||
| 8 | use HTML::Strip; | ||
| 9 | use IO::Pager; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | App::gh::Command::Recent - show recent status. | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | sub options { | ||
| 18 | ( "c|color" => "color" ) | ||
| 19 | } | ||
| 20 | |||
| 21 | sub run { | ||
| 22 | my ($self) = shift; | ||
| 23 | |||
| 24 | |||
| 25 | eval { require XML::Atom::Feed; }; | ||
| 26 | die 'Please install XML::Atom::Feed to enable this command.' if $@; | ||
| 27 | |||
| 28 | |||
| 29 | my $user = App::gh->config->github_id(); | ||
| 30 | my $token = App::gh->config->github_token(); | ||
| 31 | my $feed_uri = "https://github.com/$user.private.atom?token=$token"; | ||
| 32 | my $feed = XML::Atom::Feed->new(URI->new( $feed_uri )) | ||
| 33 | or die XML::Atom::Feed->error; | ||
| 34 | |||
| 35 | |||
| 36 | local $STDOUT = new IO::Pager *STDOUT; | ||
| 37 | $Text::Wrap::columns = 90; | ||
| 38 | |||
| 39 | for my $entry ( $feed->entries ) { | ||
| 40 | my $link = $entry->link->href; | ||
| 41 | my $author = $entry->author->name; | ||
| 42 | my $email = $entry->author->email; | ||
| 43 | |||
| 44 | my $html = $entry->content->body; | ||
| 45 | |||
| 46 | $html =~ s{<a href="(.*?)".*?>(.*?)</a>}{$2 : $1 }g; | ||
| 47 | |||
| 48 | my $h = HTML::Strip->new( emit_spaces => 1 ); | ||
| 49 | my $text = $h->parse( $html ); | ||
| 50 | $h->eof; | ||
| 51 | $text =~ s{\s+|\n+}{ }smg; | ||
| 52 | $text =~ s{(?=committed)}{\n\n}g; | ||
| 53 | # $text =~ s{(committed.*?http\S+)}{$1\n }g; | ||
| 54 | |||
| 55 | my $title = $entry->title; | ||
| 56 | if( $self->{color} ) { | ||
| 57 | print "\e[1;32m* " , $title , "\e[0m\n"; | ||
| 58 | } | ||
| 59 | else { | ||
| 60 | print "* " . $title . "\n"; | ||
| 61 | } | ||
| 62 | |||
| 63 | print " Link: $link\n"; | ||
| 64 | print " Author: $author\n"; | ||
| 65 | $text =~ s{^\s*}{}; | ||
| 66 | print wrap( " ", " ", $text ) , "\n\n"; | ||
| 67 | } | ||
| 68 | |||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | 1; |