Dist-Zilla-Plugin-Bitbucket

 view release on metacpan or  search on metacpan

lib/Dist/Zilla/Plugin/Bitbucket/Meta.pm  view on Meta::CPAN


extends 'Dist::Zilla::Plugin::Bitbucket';
with 'Dist::Zilla::Role::MetaProvider';

#pod =attr homepage
#pod
#pod The META homepage field will be set to the Bitbucket repository's
#pod root if this option is set to true (default).
#pod
#pod =cut

has 'homepage' => (
	is      => 'ro',
	isa     => 'Bool',
	default => 1,
);

#pod =attr bugs
#pod
#pod The META bugtracker web field will be set to the issue's page of the repository
#pod on Bitbucket, if this options is set to true (default).
#pod
#pod NOTE: Be sure to enable the issues section in the repository's
#pod Bitbucket admin page!
#pod
#pod =cut

has 'bugs' => (
	is      => 'ro',
	isa     => 'Bool',
	default => 1,
);

#pod =attr wiki
#pod
#pod The META homepage field will be set to the URL of the wiki of the Bitbucket
#pod repository, if this option is set to true (default is false).
#pod
#pod NOTE: Be sure to enable the wiki section in the repository's
#pod Bitbucket admin page!
#pod
#pod =cut

has 'wiki' => (
	is      => 'ro',
	isa     => 'Bool',
	default => 0,
);

sub metadata {
	my $self = shift;

	my $repo_name = $self->_get_repo_name;
	return {} if (!$repo_name);
	if($repo_name =~ /\/(.*)$/) {
		$repo_name = $1;
	} else {
		die "unknown repo name";
	}

	my ($login, undef) = $self->_get_credentials(1);
	return if (!$login);

	# Build the meta structure
	my $html_url = 'https://bitbucket.org/' . $login . '/' . $repo_name;
	my $meta = {
		'resources' => {
			'repository' => {
				'web' => $html_url,
				'url' => ( $self->scm eq 'git' ? 'git://git@bitbucket.org:' . $login . '/' . $repo_name . '.git' : $html_url ),
				'type' => $self->scm,
			},
		},
	};
	if ( $self->homepage and ! $self->wiki ) {
		# TODO we should use the API and fetch the current
		$meta->{'resources'}->{'homepage'} = $html_url;
	}
	if ( ! $self->homepage and $self->wiki ) {
		$meta->{'resources'}->{'homepage'} = $html_url . '/wiki/Home';
	}
	if ( $self->bugs ) {
		$meta->{'resources'}->{'bugtracker'} = {
			'web' => $html_url . '/issues'
		};
	}

	return $meta;
}

no Moose;
__PACKAGE__ -> meta -> make_immutable;
1;

__END__

=pod

=encoding UTF-8

=for :stopwords Apocalypse

=for Pod::Coverage metadata

=head1 NAME

Dist::Zilla::Plugin::Bitbucket::Meta - Add a Bitbucket repo's info to META.{yml,json}

=head1 VERSION

  This document describes v0.001 of Dist::Zilla::Plugin::Bitbucket::Meta - released November 03, 2014 as part of Dist-Zilla-Plugin-Bitbucket.

=head1 DESCRIPTION

	# in dist.ini
	[Bitbucket::Meta]

This L<Dist::Zilla> plugin adds some information about the distribution's Bitbucket
repository to the META.{yml,json} files, using the official L<CPAN::Meta>
specification.



( run in 0.919 second using v1.01-cache-2.11-cpan-39bf76dae61 )