Skip to content
Browse files

Add examples/show_commit.pl.

  • Loading branch information...
1 parent 53c9ad7 commit 49eef49db0e0ac0bf7f83d7ac2350bc9b1650d62 @plu committed Aug 2, 2011
Showing with 37 additions and 0 deletions.
  1. +37 −0 examples/show_commit.pl
View
37 examples/show_commit.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Pithub::Repos::Commits;
+
+# https://github.com/kraih/mojo/commit/ad0b3b3fcaacffe39fea34b126cd927e3f02ec78
+my $url = $ARGV[0] || die "usage: show_commit.pl <url>\n";
+
+my ($user, $repo, $sha) = $url =~ qr{https?://github.com/([^/]+)/([^/]+)/commit/([^/]+)};
+
+my $commit = Pithub::Repos::Commits->new->get(
+ user => $user,
+ repo => $repo,
+ sha => $sha,
+);
+
+unless ($commit->success) {
+ die "could not fetch the commit from Github: $url\n";
+}
+
+my $c = $commit->content;
+
+print <<EOF;
+commit $c->{sha}
+Author: $c->{commit}{author}{name} <$c->{commit}{author}{email}>
+Date: $c->{commit}{author}{date}
+
+ $c->{commit}{message}
+
+EOF
+
+foreach my $f (@{ $c->{files} }) {
+ print <<EOF;
+diff --git a/$f->{filename} b/$f->{filename}
+$f->{patch}
+EOF
+}

0 comments on commit 49eef49

Please sign in to comment.
Something went wrong with that request. Please try again.