Last active
October 21, 2016 19:25
-
-
Save pstray/ac085702ee1e7f364714e1d9fa7b126a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use JSON; | |
use WWW::Mechanize; | |
my $mech = WWW::Mechanize->new(); | |
my $what = shift; | |
my($user,$repo); | |
if ($what =~ m,^([\w-]+)/([\w-]+)$,) { | |
($user,$repo) = ($1,$2); | |
} | |
else { | |
die "Please supply a repo on the form user/repo\n"; | |
} | |
$mech->get("https://api.github.com/repos/$user/$repo"); | |
unless ($mech->success) { | |
printf "No responce from github api\n"; | |
exit 1; | |
} | |
my $json = decode_json $mech->content; | |
my $url = $json->{ssh_url}; | |
die "No ssh_url in metadata, exiting...\n" | |
unless $url; | |
system git => clone => $url; | |
unless (-d "$repo/.git") { | |
die "Error: no repo produced by: git clone $url\n"; | |
} | |
chdir "$repo"; | |
my $parent = $json->{parent}{ssh_url}; | |
if ($parent) { | |
system git => remote => add => upstream => $parent; | |
system git => fetch => 'upstream'; | |
} | |
printf "All ok\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment