| 1 | package Git::MoreHooks::CheckCommitBase; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | # ABSTRACT: CheckCommit base file | ||
| 8 | |||
| 9 | our $VERSION = '0.019'; # VERSION: generated by DZP::OurPkgVersion | ||
| 10 | |||
| 11 | |||
| 12 | 1 | ▶ | use Git::Hooks 3.000000; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 13 | use Path::Tiny; | ||
| 14 | use Log::Any qw{$log}; | ||
| 15 | use Params::Validate qw(:all); | ||
| 16 | |||
| 17 | |||
| 18 | our $USER_HOOK; | ||
| 19 | |||
| 20 | sub import { | ||
| 21 | my ( $package, $user_hook ) = @_; | ||
| 22 | $package .= q{}; | ||
| 23 | $USER_HOOK = $user_hook; | ||
| 24 | return; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub _call_user_hook { | ||
| 28 | return &{$USER_HOOK}(@_); | ||
| 29 | } | ||
| 30 | |||
| 31 | sub pre_commit_callback { | ||
| 32 | my ($git) = @_; | ||
| 33 | my %opts = ( 'old_commit' => ':0', 'new_commit' => undef, 'gerrit-opts' => undef ); | ||
| 34 | return _call_user_hook( $git, 'pre-commit', \%opts ); | ||
| 35 | } | ||
| 36 | |||
| 37 | # This routine can act both as an update or a pre-receive hook. | ||
| 38 | sub update_callback { | ||
| 39 | $log->tracef( 'Entering update_callback(%s)', ( join q{:}, @_ ) ); | ||
| 40 | my ($git) = @_; | ||
| 41 | my %opts = ( 'old_commit' => ':0', 'new_commit' => 0, 'gerrit-opts' => undef ); | ||
| 42 | return _call_user_hook( $git, 'update', \%opts ); | ||
| 43 | } | ||
| 44 | |||
| 45 | sub pre_receive_callback { | ||
| 46 | $log->tracef( 'Entering pre_receive_callback(%s)', ( join q{:}, @_ ) ); | ||
| 47 | my ($git) = @_; | ||
| 48 | my %opts = ( 'old_commit' => ':0', 'new_commit' => 0, 'gerrit-opts' => undef ); | ||
| 49 | return _call_user_hook( $git, 'pre-receive', \%opts ); | ||
| 50 | } | ||
| 51 | |||
| 52 | sub ref_update_callback { | ||
| 53 | my ($git) = @_; | ||
| 54 | my %opts = ( 'old_commit' => ':0', 'new_commit' => 0, 'gerrit-opts' => undef ); | ||
| 55 | return _call_user_hook( $git, 'ref-update', \%opts ); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub patchset_created_callback { | ||
| 59 | my ( $git, $opts ) = @_; | ||
| 60 | my %opts = ( 'old_commit' => ':0', 'new_commit' => 0, 'gerrit-opts' => $opts ); | ||
| 61 | return _call_user_hook( $git, 'patchset-created', \%opts ); | ||
| 62 | } | ||
| 63 | |||
| 64 | sub draft_published_callback { | ||
| 65 | my ( $git, $opts ) = @_; | ||
| 66 | my %opts = ( 'old_commit' => ':0', 'new_commit' => 0, 'gerrit-opts' => $opts ); | ||
| 67 | return _call_user_hook( $git, 'draft-published', \%opts ); | ||
| 68 | } | ||
| 69 | |||
| 70 | # Install hooks | ||
| 71 | PRE_COMMIT \&pre_commit_callback; | ||
| 72 | UPDATE \&update_callback; | ||
| 73 | PRE_RECEIVE \&pre_receive_callback; | ||
| 74 | REF_UPDATE \&ref_update_callback; | ||
| 75 | PATCHSET_CREATED \&patchset_created_callback; | ||
| 76 | DRAFT_PUBLISHED \&draft_published_callback; | ||
| 77 | |||
| 78 | 1; | ||
| 79 | |||
| 80 | __END__ | ||