GitHub-RSS

 view release on metacpan or  search on metacpan

scripts/generate-rss.pl  view on Meta::CPAN


sub verbatim_section( $s ) {
    my $res = encode_entities($s);
    $res =~ s! ! !g;
    return "<code>$res</code>";
}

my @comments =
    map {

    my $entry = XML::Feed::Entry->new('RSS');
    $entry->id( $_->{id} );
    $entry->title( "Comment by $_->{user}->{login}" );
    $entry->link( $_->{html_url} );

    my $issue = $gh->issue( $_->{issue_number} );

    my $header = <<HTML;
<header>
<a href="$issue->{html_url}">$issue->{title}</a> in <a href="https://github.com/$github_user/$github_repo">$github_user/$github_repo</a>
</header>
HTML
    my $footer = <<HTML;
<footer>
<hr />
Created by <a href="https://github.com/Corion/GitHub-RSS">GitHub::RSS</a>
</footer>
HTML

    # Convert from md to html, url-encode
    my $content = $_->{body} || '';
    $content =~ s!\\(.)!$1!g; # unquote, because Github sends us quotemeta'd content?!
    $content =~ s![\x00-\x08\x0B\x0C\x0E-\x1F]!.!g;

    # render ```...``` into verbatim code:
    $content =~ s!^\`\`\`(.*?)\`\`\`!verbatim_section($1)!msge;

    my $body = Text::Markdown->new->markdown( $content );
    $entry->content( join "", $header, $body, $footer );
    $entry->author( $_->{user}->{login} );

    if( $_->{updated_at} ) {
        my $modified = DateTime::Format::ISO8601->parse_datetime(
            $_->{updated_at}
        );
        $entry->modified( $modified );
    };

    my $created = DateTime::Format::ISO8601->parse_datetime(
        $_->{created_at}
    );
    $entry->issued( $created );

    $feed->add_entry( $entry );
}
 $gh->issues_and_comments(
    #Perl => 'perl5'
    $since,
    );

sub update_file( $fn, $content ) {
    my $needs_update = ! -e $fn;
    if( ! $needs_update ) {
        open my $old, '<', $fn
            or die "Couldn't read old content from '$fn': $!";
        binmode $old, ':utf8';
        local $/;
        my $old_content = <$old>;
        $needs_update = $old_content ne $content;
    };

    if( $needs_update ) {
        open my $fh, '>', $fn
            or die "Couldn't create '$fn': $!";
        binmode $fh, ':utf8';
        print {$fh} $content;
    };
}

update_file( $output_file, $feed->as_xml );

=head1 LIVE DEMO

This RSS feed is live at L<https://corion.net/github-rss/Perl-perl5-issues.rss>
if you just want to read the Perl 5 issues as RSS feed.

=cut



( run in 0.405 second using v1.01-cache-2.11-cpan-e1769b4cff6 )