Dist-Zilla-Plugin-Bitbucket
view release on metacpan or search on metacpan
lib/Dist/Zilla/Plugin/Bitbucket/Update.pm view on Meta::CPAN
#
# This file is part of Dist-Zilla-Plugin-Bitbucket
#
# This software is copyright (c) 2014 by Apocalypse.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict; use warnings;
package Dist::Zilla::Plugin::Bitbucket::Update;
$Dist::Zilla::Plugin::Bitbucket::Update::VERSION = '0.001';
our $AUTHORITY = 'cpan:APOCAL';
# ABSTRACT: Update a Bitbucket repo's info on release
use Moose;
use HTTP::Tiny 0.050;
use MIME::Base64 3.14;
use JSON::MaybeXS 1.002006 qw( encode_json decode_json );
extends 'Dist::Zilla::Plugin::Bitbucket';
with 'Dist::Zilla::Role::AfterRelease';
sub after_release {
my $self = shift;
my ($login, $pass) = $self->_get_credentials(0);
return if (!$login);
my $repo_name = $self->_get_repo_name(1);
# set the repo settings
my ($params, $headers);
$params->{'description'} = $self->zilla->abstract;
$params->{'website'} = $self->zilla->distmeta->{'resources'}{'homepage'};
# construct the HTTP request!
my $http = HTTP::Tiny->new;
$headers->{'authorization'} = "Basic " . MIME::Base64::encode_base64("$login:$pass", '');
$headers->{'content-type'} = "application/json";
# We use the v1.0 API to update
my $url = 'https://bitbucket.org/api/1.0/repositories/' . $repo_name; # TODO encode the repo_name?
$self->log( "Updating Bitbucket repository info" );
my $response = $http->request( 'PUT', $url, {
content => encode_json( $params ),
headers => $headers
});
if ( ! $response->{'success'} ) {
$self->log( ["Error: HTTP status(%s) when trying to POST => %s", $response->{'status'}, $response->{'reason'} ] );
return;
}
my $r = decode_json( $response->{'content'} );
if ( ! $r ) {
$self->log( "ERROR: Malformed response content when trying to POST" );
return;
}
if ( exists $r->{'error'} ) {
$self->log( [ "Unable to update Bitbucket repository: %s", $r->{'error'} ] );
return;
}
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=encoding UTF-8
=for :stopwords Apocalypse
=for Pod::Coverage after_release
=head1 NAME
Dist::Zilla::Plugin::Bitbucket::Update - Update a Bitbucket repo's info on release
=head1 VERSION
This document describes v0.001 of Dist::Zilla::Plugin::Bitbucket::Update - released November 03, 2014 as part of Dist-Zilla-Plugin-Bitbucket.
( run in 0.713 second using v1.01-cache-2.11-cpan-39bf76dae61 )