File Coverage

lib/App/gh/Command/Import.pm
Criterion Covered Total %
statement 21 45 46.6
branch 0 8 0.0
condition 0 9 0.0
subroutine 7 9 77.7
pod 0 2 0.0
total 28 73 38.3


line stmt bran cond sub pod time code
1             package App::gh::Command::Import;
2 1     1   2510 use warnings;
  1         3  
  1         43  
3 1     1   8 use strict;
  1         3  
  1         239  
4 1     1   8 use base qw(App::gh::Command);
  1         2  
  1         114  
5 1     1   7 use File::Basename;
  1         3  
  1         181  
6 1     1   7 use Cwd;
  1         3  
  1         72  
7 1     1   6 use App::gh::Utils;
  1         1  
  1         100  
8             require App::gh::Git;
9 1     1   7 use Carp;
  1         3  
  1         658  
10              
11             sub options {
12 0     0 0   'n|name=s' => 'name',
13             'd|description=s' => 'description',
14             'homepage=s' => 'homepage',
15             'p|private' => 'private',
16             'r|remote=s' => 'remote',
17             }
18              
19             sub run {
20 0     0 0   my ($self) = @_;
21 0           my $local_repo = App::gh->git;
22 0   0       my $remote = $self->{remote} || 'origin';
23 0           my $config = App::gh->config->current;
24 0           my $basename = basename( $local_repo->wc_path() );
25 0   0       my $reponame = $self->{name} || $basename;
26 0           my $gh_id = App::gh->config->github_id();
27              
28             # Check if remote already exists
29 0 0         if ($local_repo->config("remote.$remote.fetch")) {
30 0           croak "Remote [$remote] already exists. Try specifying another one using --remote.";
31             }
32              
33              
34             # Check if repo already exists
35 0           my $existing_gh_repo = eval { App::gh->github->repos->get( $gh_id, $reponame ) };
  0            
36 0 0         if ($existing_gh_repo) {
37             # FIXME: Update existing repo
38             # my %args = (
39             # description => ($self->{description}
40             # || $existing_gh_repo->{description} || ""),
41             # homepage => ($self->{homepage}
42             # || $existing_gh_repo->{homepage} || "" ),
43             # # Don't change visibility of existing repo
44             # # public => $self->{private} ? 0 : 1 ,
45             # );
46             # my $ret = App::gh->api->repo_set_info( $gh_id, $reponame, %args );
47             # print "Repository updated: \n";
48             }
49             else {
50             # Create new repo
51 0 0 0       App::gh->github->repos->create({
      0        
52             # "org" => "perlchina", ## the organization
53             name => $reponame,
54             description => ($self->{description} || ""),
55             homepage => ($self->{homepage} || "" ),
56             public => $self->{private} ? 0 : 1 ,
57             });
58 0           info "Repository created. \n";
59             }
60              
61 0           info "Adding GitHub repo $reponame as remote [$remote].";
62 0           $local_repo->command("remote", "add", $remote,
63             "git\@github.com:${gh_id}/${reponame}.git");
64              
65             # Only set up branch remote if it isn't already set up.
66 0 0         if (! $local_repo->config('branch.master.remote')) {
67 0           info "Setting up remote [$remote] for master branch.";
68 0           $local_repo->command('config', 'branch.master.remote', "$remote");
69 0           $local_repo->command('config', 'branch.master.merge', 'refs/heads/master');
70             }
71              
72 0           info "Pushing to remote [$remote]";
73 0           $local_repo->command("push", $remote , "master");
74 0           info "Done.\n";
75             }
76              
77             1;
78             __END__