Git-Hooks

 view release on metacpan or  search on metacpan

lib/Git/Hooks/CheckJira.pm  view on Meta::CPAN

Please, check your git configuration.
EOS
        return 0;
    }

    my $errors = 0;

    foreach my $ref ($git->get_affected_refs()) {
        next unless $git->is_reference_enabled($ref);
        $errors += notify_ref($git, $ref, $visibility);
    }

    _disconnect_jira($git);

    return $errors == 0;
}

# Install hooks
my $options = {
    config  => \&_setup_config,
    destroy => \&_disconnect_jira,
};

GITHOOKS_CHECK_AFFECTED_REFS(\&check_ref, $options);
GITHOOKS_CHECK_PATCHSET(\&check_patchset, $options);
GITHOOKS_CHECK_MESSAGE_FILE(\&check_message_file, $options);

POST_RECEIVE(\&notify_affected_refs);

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Git::Hooks::CheckJira - Git::Hooks plugin which requires citation of Jira issues in commit messages

=head1 VERSION

version 4.0.0

=head1 SYNOPSIS

As a C<Git::Hooks> plugin you don't use this Perl module directly. Instead, you
may configure it in a Git configuration file like this:

  [githooks]

    # Enable the plugin
    plugin = CheckJira

    # These users are exempt from all checks
    admin = joe molly

  [githooks "checkjira"]

    # Configure the URL and the admin credentials to interact with the Jira
    # server.
    jiraurl = https://jira.example.net
    jirauser = jiradmin
    jirapass = my-secret

    # Look for Jira keys at the beginning of the commit messages title, enclosed
    # in brackets.
    matchlog = (?s)^\\[([^]]+)\\]

    # Impose restrictions on valid Jira issues
    jql = project IN (ABC, UTF, GIT) AND \
          issuetype IN (Bug, Story) AND \
          status IN ("In progress", "In testing")

    # Require that all cited Jira issues be assigned to the user pushing the
    # commits.
    by-assignee = true

    # Commits pushed to master must cite Jiras associated with the fixVersion
    # 'future'
    fixversion = refs/heads/master             future

    # Commits pushed to release branches must cite Jiras associated with the
    # fixVersion named after the same major.minor version number.
    fixversion = ^refs/heads/(\\d+\\.\\d+)\\.  ^$+

=head1 DESCRIPTION

This L<Git::Hooks> plugin hooks itself to the hooks below to guarantee that
every commit message cites at least one valid Jira issue key in its log
message, so that you can be certain that every change has a proper change
request (a.k.a. ticket) open.

=over

=item * B<commit-msg>, B<applypatch-msg>

This hook is invoked during the commit, to check if the commit message
cites valid Jira issues.

=item * B<update>

This hook is invoked multiple times in the remote repository during
C<git push>, once per branch being updated, to check if the commit
message cites valid Jira issues.

=item * B<pre-receive>

This hook is invoked once in the remote repository during C<git push>,
to check if the commit message cites valid Jira issues.

=item * B<post-receive>

This hook is invoked once in the remote repository after a successful C<git
push>. It's used to notify Jira of commits citing its issues via comments.

=item * B<ref-update>

This hook is invoked when a direct push request is received by Gerrit Code
Review, to check if the commit message cites valid Jira issues.



( run in 0.888 second using v1.01-cache-2.11-cpan-140bd7fdf52 )