summary refs log tree commit diff
path: root/eg/github.pl
blob: 4053d673dbabb699eb7e553653bc4235909c70b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use strict;
use warnings;

use Net::HTTP::Spore;
use Getopt::Long;

use Config::GitLike::Git;
use Git::Repository;

GetOptions(
    'spec=s' => \my $specification,
    'name=s' => \my $name,
    'desc=s' => \my $desc,
);

print ">> creating repository $name on github\n";

my $c = Config::GitLike::Git->new();
$c->load;

my $login = $c->get(key => 'github.user');
my $token = $c->get(key => 'github.token');

my $github = Net::HTTP::Spore->new_from_spec($specification);
$github->enable('Format::JSON');
$github->enable(
    'Auth::Basic',
    username => $login . '/token',
    password => $token,
);

my $remote = "git\@github.com:" . $login . "/" . $name . ".git";

my $res = $github->create_repo(format => 'json', payload => {name => $name, description => $desc});

print ">> repository $remote created\n";

my $r = Git::Repository->create(init => $name);
my @cmd = ('remote', 'add', 'origin', $remote);
$r->run(@cmd);

print ">> repository cloned to $name\n";
print ">> done!\n";