[Bps-public-commit] git-sync branch, master, updated. 67c6185e6bcb5655d240143ec26f782b5ba35172

jesse jesse at bestpractical.com
Fri Nov 27 13:49:28 EST 2009


The branch, master has been updated
       via  67c6185e6bcb5655d240143ec26f782b5ba35172 (commit)
      from  686a83984a5f37c358abd1d3b1ae0a39b98fe752 (commit)

Summary of changes:
 git-sync |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit 67c6185e6bcb5655d240143ec26f782b5ba35172
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Fri Nov 27 13:49:12 2009 -0500

    first part of support for adding github clones as remotes automatically

diff --git a/git-sync b/git-sync
index b2672b6..8392d5d 100755
--- a/git-sync
+++ b/git-sync
@@ -231,9 +231,9 @@ sub sync_all_github {
             unless eval { File::Path::mkpath($config{into}) };
     }
 
-    my $decoder = eval { require JSON::Any; JSON::Any->import; JSON::Any->new };
+    my $decoder = get_json_decoder();
     print colored("  GitHub sync support requires the JSON::Any module\n", "red") and return
-        if $@ or not $decoder;
+        if not $decoder;
 
     my @accounts = ref $config{github} ? @{$config{github}} : ($config{github});
     for my $acct (@accounts) {
@@ -260,10 +260,29 @@ sub sync_all_github {
                     clone($root => "git://github.com/$acct/$reponame.git" => $config{email});
                 }
             }
+            #    my @clones = get_github_clone_list($acct, $reponame);
+            #add_new_github_remotes(@clones); 
+
         }
     }
 }
 
+
+sub get_github_clone_list {
+    my $user = shift;
+    my $repo = shift;
+    my @owners;
+    my $decoder = get_json_decoder();
+    my $content = LWP::Simple::get("http://github.com/api/v2/json/repos/show/$user/$repo/network");
+    my $data    = eval { $decoder->jsonToObj($content) };
+    print colored( "  Parsing of GitHub JSON response failed! $@\n", "bold red" ) . "\n$content\n" and next
+        unless defined $data;
+    foreach my $record ( @{ $data->{network} } ) {
+        push @owners, $record->{owner} unless $record->{owner} eq $user;
+    }
+    return @owners;
+}
+
 sub sync_all_remote {
     my %config = @_;
 
@@ -474,3 +493,10 @@ sub logs {
     $logmsg =~ s/^(\S+)/"    ".colored($1,"yellow")/egm;
     return $logmsg;
 }
+
+our $JSON_DECODER = undef;
+sub get_json_decoder {
+    $JSON_DECODER ||= eval { require JSON::Any; JSON::Any->import; JSON::Any->new };
+    return $JSON_DECODER;
+
+}

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list