App-GitHooks-Plugin-NotifyReleasesToSlack
view release on metacpan or search on metacpan
lib/App/GitHooks/Plugin/NotifyReleasesToSlack.pm view on Meta::CPAN
$log->info('run git');
return $remote_name;
}
=head2 notify_slack()
Display a notification in the Slack channels defined in the config file.
App::GitHooks::Plugin::NotifyReleasesToSlack::notify_slack(
$app,
$message,
);
Arguments:
=over 4
=item * $app I<(mandatory)>
An C<App::GitHooks> object.
=item * $message I<(mandatory)>
The message to display in Slack channels.
=back
=cut
sub notify_slack
{
my ( $app, $message ) = @_;
my $config = $app->get_config();
# Get the list of channels to notify
state $slack_channels =
[
split(
/\s*,\s*/,
$config->get( 'NotifyReleasesToSlack', 'slack_channels' )
)
];
# Notify Slack channels.
foreach my $channel ( @$slack_channels )
{
$log->infof( 'Notifying Slack channel %s: %s', $channel, $message );
# Prepare payload for the request.
my $request_payload =
JSON::encode_json(
{
text => $message,
channel => $channel,
}
);
# Prepare request.
my $request = HTTP::Request->new(
POST => $config->get( 'NotifyReleasesToSlack', 'slack_post_url' ),
);
$request->content( $request_payload );
# Send request to Slack.
my $user_agent = LWP::UserAgent->new();
my $response = $user_agent->request( $request );
# If the connection is down, or Slack is down, warn the user.
if ( !$response->is_success() )
{
my $error = sprintf(
"Failed to notify channel '%s' with message '%s'.\n>>> %s %s.",
$channel,
$message,
$response->code(),
$response->message(),
);
# Notify any logging systems.
$log->error( $error );
# Notify the user who is pushing tags.
print STDERR "$error\n";
}
}
return;
}
=head2 get_changelog_releases()
Retrieve a hashref of all the releases in the changelog file.
my $releases = App::GitHooks::Plugin::NotifyReleasesToSlack::get_changelog_releases(
$app
);
Arguments:
=over 4
=item * $app I<(mandatory)>
An C<App::GitHooks> object.
=back
=cut
sub get_changelog_releases
{
my ( $app ) = @_;
my $repository = $app->get_repository();
my $config = $app->get_config();
# Make sure the changelog file exists.
my $changelog_path = $config->get( 'NotifyReleasesToSlack', 'changelog_path' );
$changelog_path = $repository->work_tree() . '/' . $changelog_path;
( run in 1.707 second using v1.01-cache-2.11-cpan-5623c5533a1 )