File Coverage

blib/lib/Group/Git/Bitbucket.pm
Criterion Covered Total %
statement 30 50 60.0
branch 0 4 0.0
condition n/a
subroutine 10 12 83.3
pod n/a
total 40 66 60.6


line stmt bran cond sub pod time code
1             package Group::Git::Bitbucket;
2              
3             # Created on: 2013-05-04 20:18:24
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 1     1   1634 use Moo;
  1         2  
  1         8  
10 1     1   2856 use strict;
  1         2  
  1         25  
11 1     1   7 use warnings;
  1         2  
  1         33  
12 1     1   6 use version;
  1         3  
  1         10  
13 1     1   73 use Carp;
  1         3  
  1         85  
14 1     1   7 use English qw/ -no_match_vars /;
  1         2  
  1         9  
15 1     1   1266 use IO::Prompt qw/prompt/;
  1         21050  
  1         9  
16 1     1   1075 use JSON qw/decode_json/;
  1         9528  
  1         8  
17 1     1   1151 use WWW::Mechanize;
  1         170703  
  1         81  
18 1     1   15 use Path::Tiny;
  1         3  
  1         471  
19              
20             our $VERSION = version->new('0.7.6');
21              
22             extends 'Group::Git';
23              
24             sub _httpenc {
25 0     0     my ($str) = @_;
26 0           $str =~ s/(\W)/sprintf "%%%x", ord $1/egxms;
  0            
27 0           return $str;
28             }
29              
30             sub _repos {
31 0     0     my ($self) = @_;
32 0           my %repos = %{ $self->SUPER::_repos() };
  0            
33              
34 0           my ($conf) = $self->conf;
35             #EG curl --user buserbb:2934dfad https://api.bitbucket.org/1.0/user/repositories
36              
37 0           my @argv = @ARGV;
38 0           @ARGV = ();
39 0           my $mech = $self->mech;
40 0 0         my $user = _httpenc( $conf->{username} ? $conf->{username} : prompt( -prompt => 'bitbucket username : ' ) );
41 0 0         my $pass = _httpenc( $conf->{password} ? $conf->{password} : prompt( -prompt => 'bitbucket password : ', -echo => '*' ) );
42 0           my $url = "https://$user:$pass\@api.bitbucket.org/1.0/user/repositories";
43 0           @ARGV = @argv;
44              
45 0           $mech->get($url);
46 0           my $repos = decode_json $mech->content;
47 0           for my $repo ( @$repos ) {
48             $repos{$repo->{name}} = Group::Git::Repo->new(
49 0           name => path($repo->{name}),
50             url => "https://bitbucket.org/$repo->{owner}/$repo->{name}",
51             git => "git\@bitbucket.org:$repo->{owner}/$repo->{name}.git",
52             );
53             }
54              
55 0           return \%repos;
56             }
57              
58             1;
59              
60             __END__
61              
62             =head1 NAME
63              
64             Group::Git::Bitbucket - Adds reading all repositories you have access to on bitbucket.org
65              
66             =head1 VERSION
67              
68             This documentation refers to Group::Git::Bitbucket version 0.7.6.
69              
70             =head1 SYNOPSIS
71              
72             use Group::Git::Bitbucket;
73              
74             # pull (or clone missing) all repositories that joeblogs has created/forked
75             my $ggb = Group::Git::Bitbucket->new(
76             conf => {
77             username => 'joeblogs@gmail.com',
78             password => 'myverysecurepassword',
79             },
80             );
81              
82             # list all repositories
83             my $repositories = $ggb->repo();
84              
85             # do something to each repository
86             for my $repo (keys %{$repositories}) {
87             # eg do a pull
88             $ggb->pull($repo);
89             }
90              
91             =head1 DESCRIPTION
92              
93             Reads all repositories for the configured user (if none set user will be
94             prompted to enter one as well as a password)
95             Reads all repositories for the configured user. Note: if no username or password
96             is set you will be prompted to enter a username and password.
97              
98             =head1 SUBROUTINES/METHODS
99              
100             =head1 DIAGNOSTICS
101              
102             =head1 CONFIGURATION AND ENVIRONMENT
103              
104             =head1 DEPENDENCIES
105              
106             =head1 INCOMPATIBILITIES
107              
108             =head1 BUGS AND LIMITATIONS
109              
110             There are no known bugs in this module.
111              
112             Please report problems to Ivan Wills (ivan.wills@gmail.com).
113              
114             Patches are welcome.
115              
116             =head1 AUTHOR
117              
118             Ivan Wills - (ivan.wills@gmail.com)
119              
120             =head1 LICENSE AND COPYRIGHT
121              
122             Copyright (c) 2013 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
123             All rights reserved.
124              
125             This module is free software; you can redistribute it and/or modify it under
126             the same terms as Perl itself. See L<perlartistic>. This program is
127             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
128             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
129             PARTICULAR PURPOSE.
130              
131             =cut