Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Mar 17, 2015
1 parent 57b34b8 commit 90c3877
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ By default access is restricted to known GitHub WebHook IPs.
## Synchronize with a GitHub repository

The following application automatically pulls the master branch of a GitHub
repository into a local working directory `$work_tree`.
repository into a local working directory.

use Git::Repository;
use Plack::App::GitHub::WebHook;
Expand All @@ -78,16 +78,21 @@ repository into a local working directory `$work_tree`.
my $work_tree = "/some/path";

Plack::App::GitHub::WebHook->new(
events => ['pull'],
events => ['pull','ping'],
safe => 1,
hook => [
sub { $_[0]->{ref} eq "refs/heads/$branch" },
sub {
my ($payload, $method) = @_;
$method eq 'ping' or $payload->{ref} eq "refs/heads/$branch";
},
sub {
my ($payload, $method) = @_;
return 1 if $method eq 'ping';
if ( -d "$work_tree/.git") {
Git::Repository->new( work_tree => $work_tree )
->run( 'pull', origin => $branch );
} else {
my $origin = $_[0]->{repository}->{clone_url};
my $origin = $payload->{repository}->{clone_url};
Git::Repository->run( clone => $origin, -b => $branch, $work_tree );
}
1;
Expand Down
13 changes: 9 additions & 4 deletions lib/Plack/App/GitHub/WebHook.pm
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ By default access is restricted to known GitHub WebHook IPs.
=head2 Synchronize with a GitHub repository
The following application automatically pulls the master branch of a GitHub
repository into a local working directory C<$work_tree>.
repository into a local working directory.
use Git::Repository;
use Plack::App::GitHub::WebHook;
Expand All @@ -172,16 +172,21 @@ repository into a local working directory C<$work_tree>.
my $work_tree = "/some/path";
Plack::App::GitHub::WebHook->new(
events => ['pull'],
events => ['pull','ping'],
safe => 1,
hook => [
sub { $_[0]->{ref} eq "refs/heads/$branch" },
sub {
my ($payload, $method) = @_;
$method eq 'ping' or $payload->{ref} eq "refs/heads/$branch";
},
sub {
my ($payload, $method) = @_;
return 1 if $method eq 'ping';
if ( -d "$work_tree/.git") {
Git::Repository->new( work_tree => $work_tree )
->run( 'pull', origin => $branch );
} else {
my $origin = $_[0]->{repository}->{clone_url};
my $origin = $payload->{repository}->{clone_url};
Git::Repository->run( clone => $origin, -b => $branch, $work_tree );
}
1;
Expand Down

0 comments on commit 90c3877

Please sign in to comment.