summaryrefslogtreecommitdiffstats
path: root/bin/git
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-04-13 01:34:52 -0500
committerJesse Luehrs <doy@tozt.net>2013-04-13 01:35:11 -0500
commit779f281b31c3aa4f6051e52e3a5f984966b81023 (patch)
tree273e8e11871b21721fe12ab17dd8d807860ca9a1 /bin/git
parentd094bb0d95ecb9936e222428440205b2ac5b61af (diff)
downloadconf-779f281b31c3aa4f6051e52e3a5f984966b81023.tar.gz
conf-779f281b31c3aa4f6051e52e3a5f984966b81023.zip
script to grab all of my github repositories
Diffstat (limited to 'bin/git')
-rwxr-xr-xbin/git/git-github-mirror57
1 files changed, 57 insertions, 0 deletions
diff --git a/bin/git/git-github-mirror b/bin/git/git-github-mirror
new file mode 100755
index 0000000..b3d38a2
--- /dev/null
+++ b/bin/git/git-github-mirror
@@ -0,0 +1,57 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.010;
+
+use Getopt::Long;
+use HTTP::Request;
+use JSON;
+use LWP::UserAgent;
+use Pithub;
+use Term::ReadKey;
+
+GetOptions(
+ "mirror" => \(my $mirror),
+ "all" => \(my $all),
+);
+
+sub git {
+ my ($cmd) = @_;
+ `git $cmd`;
+ return $? == 0;
+}
+
+my ($user) = @ARGV;
+die "user required" unless defined $user;
+
+print "Password: ";
+Term::ReadKey::ReadMode(2);
+chomp(my $pass = <STDIN>);
+Term::ReadKey::ReadMode(0);
+print "\n";
+
+my $ua = LWP::UserAgent->new;
+my $req = HTTP::Request->new(
+ POST => 'https://api.github.com/authorizations',
+);
+$req->content('{}');
+$req->authorization_basic($user, $pass);
+my $res = $ua->request($req);
+if (!$res->is_success) {
+ require Data::Dumper; die Data::Dumper::Dumper($res);
+}
+my $token = JSON::decode_json($res->content)->{token};
+
+my $ph = Pithub->new(token => $token, ua => $ua, auto_pagination => 1);
+my $rows = $ph->repos->list(user => $user);
+while (my $row = $rows->next) {
+ next unless $all || !$row->{fork};
+ if (!-e $row->{name}) {
+ print "Cloning $row->{name}\n";
+ my $opts = $mirror ? "--mirror" : "";
+ git "clone $opts $row->{ssh_url}";
+ }
+ else {
+ print "Skipping $row->{name}\n";
+ }
+}