summary refs log tree commit diff
path: root/lib/githubexplorer
diff options
context:
space:
mode:
Diffstat (limited to 'lib/githubexplorer')
-rw-r--r--lib/githubexplorer/Profile.pm36
-rw-r--r--lib/githubexplorer/Repositorie.pm46
-rw-r--r--lib/githubexplorer/Schema/Result/Repositories.pm1
3 files changed, 52 insertions, 31 deletions
diff --git a/lib/githubexplorer/Profile.pm b/lib/githubexplorer/Profile.pm
index 47a0582..7966d79 100644
--- a/lib/githubexplorer/Profile.pm
+++ b/lib/githubexplorer/Profile.pm
@@ -3,32 +3,38 @@ use 5.010;
 use Moose::Role;
 use Net::GitHub::V2::Users;
 
+has banned_profiles =>
+    ( isa => 'ArrayRef', is => 'ro', default => sub { [qw/gitpan/] } );
+
 sub fetch_profile {
     my ( $self, $login, $depth ) = @_;
 
-    return if $depth > 3;
+    return if grep {$_ =~ /$login/i} @{$self->banned_profiles};
+
+    return if $depth > 2;
     my $profile = $self->_profile_exists($login);
 
     say "fetch profile for $login ($depth)...";
-    sleep(1);
     my $github = Net::GitHub::V2::Users->new(
         owner => $login,
         login => $self->api_login,
         token => $self->api_token,
     );
-    sleep(2);
+    sleep(1);
 
     if ( !$profile ) {
         $profile = $self->_create_profile( $login, $github->show, $depth );
-        if ( $self->with_repo ) {
-            foreach my $repo ( @{ $github->list } ) {
-                $self->fetch_repo( $profile, $repo->{name} );
-            }
-        }
         sleep(1);
     }
+    if ( $self->with_repo ) {
+        $self->fetch_repositories( $profile, $github->list );
+    }
+
     my $followers   = $github->followers();
+    sleep(1);
+    my $following   = $github->following();
     my $local_depth = $depth + 1;
+
     foreach my $f (@$followers) {
         my $p = $self->fetch_profile( $f, $local_depth );
         next unless $p;
@@ -40,9 +46,23 @@ sub fetch_profile {
             }
         );
     }
+
+    foreach my $f (@$following) {
+        my $p = $self->fetch_profile( $f, $local_depth );
+        next unless $p;
+        $self->schema->txn_do(
+            sub {
+                $self->schema->resultset('Follow')
+                    ->find_or_create(
+                    { id_following => $p->id, id_follower => $profile->id } );
+            },
+
+        );
+    }
     $profile;
 }
 
+
 sub _profile_exists {
     my ( $self, $login ) = @_;
     my $profile
diff --git a/lib/githubexplorer/Repositorie.pm b/lib/githubexplorer/Repositorie.pm
index 6d777b8..bfb8076 100644
--- a/lib/githubexplorer/Repositorie.pm
+++ b/lib/githubexplorer/Repositorie.pm
@@ -3,31 +3,31 @@ use 5.010;
 use Moose::Role;
 use Net::GitHub::V2::Repositories;
 
-sub fetch_repo {
-    my ( $self, $profile, $repo_name ) = @_;
+sub fetch_repositories {
+    my ( $self, $profile, $repo_list ) = @_;
+
+    foreach my $repo (@$repo_list) {
+        next if $self->_repo_exists( $profile, $repo->{name} );
+        say "-> check " . $profile->login . "'s ".$repo->{name};
+        # my $github = Net::GitHub::V2::Repositories->new(
+        #     owner => $profile->login,
+        #     repo  => $repo->{name},
+        #     login => $self->api_login,
+        #     token => $self->api_token,
+        # );
 
-    return if $self->_repo_exists( $profile, $repo_name );
-
-    say "-> check " . $profile->login . "'s $repo_name";
-    sleep(1);
-    my $github = Net::GitHub::V2::Repositories->new(
-        owner => $profile->login,
-        repo  => $repo_name,
-        login => $self->api_login,
-        token => $self->api_token,
-    );
-    sleep(1);
-    my $langs = $github->languages();
-    sleep(1);
-    return unless grep {/perl/i} keys %$langs;
-    my $repo_desc = $github->show();
-    sleep(1);
-    $profile->perl_total_bytes( $profile->perl_total_bytes + $langs->{Perl} );
-    $self->schema->txn_do( sub { $profile->update } );
-    $self->_create_repo( $profile, $repo_desc );
-    sleep(1);
+  # my $langs = $github->languages();
+  # sleep(1);
+  # return unless grep {/perl/i} keys %$langs;
+  # my $repo_desc = $github->show();
+  # sleep(1);
+  # $profile->perl_total_bytes( $profile->perl_total_bytes + $langs->{Perl} );
+  # $self->schema->txn_do( sub { $profile->update } );
+        $self->_create_repo( $profile, $repo );
+    }
 }
 
+
 sub _repo_exists {
     my ( $self, $profile, $repo_name ) = @_;
     return
@@ -44,7 +44,7 @@ sub _create_repo {
         my $repo_insert = {
             id_profile => $profile->id,
             map { $_ => $repo_desc->{$_} }
-                (qw/description name homepage url watchers forks/)
+                (qw/description name homepage url watchers forks fork/)
         };
         $self->schema->txn_do(
             sub {
diff --git a/lib/githubexplorer/Schema/Result/Repositories.pm b/lib/githubexplorer/Schema/Result/Repositories.pm
index 641305f..2bd7136 100644
--- a/lib/githubexplorer/Schema/Result/Repositories.pm
+++ b/lib/githubexplorer/Schema/Result/Repositories.pm
@@ -12,6 +12,7 @@ __PACKAGE__->add_columns(
     url         => { data_type => 'varchar', is_nullable       => 1 },
     watchers    => { data_type => 'int' },
     forks       => { data_type => 'int' },
+    fork        => { data_type => 'bool' },
     id_profile  => { data_type => 'int',     is_foreign_key    => 1 },
 );