Permalink
Browse files

[25] Implemented option to use github links in RSS feed

Signed-off-by: DoesntMatter <jaed1@gmx.net>
  • Loading branch information...
DoesntMatter committed Jan 22, 2012
1 parent 9b2bdc9 commit b002aa9971e0dbec8faefdb02edae855d9f842a8
Showing with 55 additions and 5 deletions.
  1. +10 −2 gitlog_to_rss.pl
  2. +33 −0 headers/generic.ph
  3. +12 −3 headers/rss.ph
View
@@ -28,7 +28,7 @@
require "headers/rss.ph";
my %options;
my $gitlog;
my ($gitlog, $giturl);
#
# Get options
@@ -42,6 +42,7 @@
"title=s",
"desc=s",
"link=s",
"github",
"prompt",
"help|?",
);
@@ -74,6 +75,9 @@
if ($options{'title'} and $options{'title'} ne '') {
$RSS::rss{'desc'} = $options{'desc'};
}
if ($options{'github'}) {
$giturl = GENERIC::GetGithubUrl($options{'repo'});
}
}
else {
$options{'repo'} = GENERIC::GetInput("Please enter repository path: ", 1);
@@ -85,6 +89,10 @@
$RSS::rss{'title'} = GENERIC::GetInput("Please enter RSS title: ");
$RSS::rss{'desc'} = GENERIC::GetInput("Please enter RSS description: ");
$RSS::rss{'link'} = GENERIC::GetInput("Please enter RSS link: ");
$options{'github'} = GENERIC::GetInput("Please confirm github usage (0|1): ");
if ($options{'github'}) {
$giturl = GENERIC::GetGithubUrl($options{'repo'});
}
}
#
@@ -97,6 +105,6 @@
exit;
}
RSS::CreateRSS(HTML::Entities::encode($gitlog), $options{'outfile'}, \%RSS::rss);
RSS::CreateRSS(HTML::Entities::encode($gitlog), $options{'outfile'}, \%RSS::rss, $giturl);
exit;
View
@@ -61,6 +61,39 @@ sub CheckRepo {
return 1;
}
sub GetGithubUrl {
my $repo = shift || return undef;
my $cmd = "git remote -v";
my $urlbase = "https://github.com";
my (@elements, @url, @part);
my ($result, $append);
$result = qx/$cmd/;
if ($result =~ /^(origin)/) {
@elements = split(/\s+/, $result);
if ($elements[1] =~ /\/(.*)\//) {
# Read-Only
# git://github.com/DoesntMatter/GitlogParser.git
# HTTP
# https://DoesntMatter@github.com/DoesntMatter/GitlogParser.git
@url = split(/\//, $elements[1]);
$append = join("/", $urlbase, $url[3], $url[4]);
return substr($append, 0, -4); # Cut off .git ending
}
elsif ($elements[1] =~ /:(.*)\//) {
# SSH
# git@github.com:DoesntMatter/GitlogParser.git
@url = split(/\//, $elements[1]);
@part = split(/:/, $url[0]);
$append = join("/", $urlbase, $part[1], $url[1]);
return substr($append, 0, -4); # Cut off .git ending
}
}
return undef;
}
sub ParseGitLog {
my $repo = shift || return undef;
my $count = shift;
View
@@ -54,6 +54,7 @@ Options:
Default: "RSS 2.0 feed description"
--link LINK Link of your RSS Feed
Default: http://dev-blog.doesntmatter.de
--github Links your commits to github
--prompt Prompt for input and do not use options
--help Show this output
HELP
@@ -65,8 +66,11 @@ sub CreateRSS {
my $gitlog = shift || return undef;
my $file = shift || return undef;
my $rss = shift || return undef;
my $github = shift;
my @items = GENERIC::SplitCommits($gitlog, "\n&gt;");
my $weblink = "https://github.com";
my $itemlink = $rss{'link'};
my $commit;
# Header
open(FILE, ">$file");
@@ -75,7 +79,7 @@ sub CreateRSS {
<channel>
<title>$rss{'title'}</title>
<link>$rss{'link'}</link>
<link>$itemlink</link>
<description>$rss{'desc'}</description>
";
close(FILE);
@@ -92,13 +96,18 @@ sub CreateRSS {
# $items[$i][6] Body
$items[$i][6] =~ s/\n/<br><br>/; # Better formatting
if ($github) {
$itemlink = $commit = join("/", $github, "commit", $items[$i][1]);
$items[$i][1] = "<a href=\"$commit\">$items[$i][1]</a>";
$items[$i][3] = "<a href=\"$weblink/$items[$i][3]\">$items[$i][3]</a>";
}
print FILE "
<item>
<title>$items[$i][5]</title>
<link>$rss{'link'}</link>
<link>$itemlink</link>
<description><![CDATA[
<a href=\"$weblink/$items[$i][3]\">$items[$i][3]</a> &lt;$items[$i][4]&gt; committed $items[$i][1]<br><br>
$items[$i][3] &lt;$items[$i][4]&gt; committed $items[$i][1]<br><br>
$items[$i][5]<br><br>
$items[$i][6]
]]></description>

0 comments on commit b002aa9

Please sign in to comment.