diff options
author | franck cuny <franck@lumberjaph.net> | 2010-02-10 11:08:21 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-02-10 11:08:21 +0100 |
commit | 68cd6b70d8ce737ffa12bab2be4f6eaf6f1599a4 (patch) | |
tree | 2208dfd26b3837a098ba7f601069917d8d81951c /lib | |
parent | prepare repos (diff) | |
parent | update to create graph (diff) | |
download | github-explorer-68cd6b70d8ce737ffa12bab2be4f6eaf6f1599a4.tar.gz |
fix
Diffstat (limited to 'lib')
-rw-r--r-- | lib/githubexplorer.pm | 12 | ||||
-rw-r--r-- | lib/githubexplorer/Network.pm | 34 | ||||
-rw-r--r-- | lib/githubexplorer/Repository.pm | 1 | ||||
-rw-r--r-- | lib/githubexplorer/Schema/Result/Fork.pm | 17 |
4 files changed, 50 insertions, 14 deletions
diff --git a/lib/githubexplorer.pm b/lib/githubexplorer.pm index 67e9e25..4fc5aa5 100644 --- a/lib/githubexplorer.pm +++ b/lib/githubexplorer.pm @@ -6,7 +6,8 @@ use githubexplorer::Schema; use githubexplorer::Gexf; use IO::All; -with qw/githubexplorer::Profile githubexplorer::Repository/; +with qw/githubexplorer::Profile githubexplorer::Repository +githubexplorer::Network/; has seed => ( isa => 'ArrayRef', @@ -72,4 +73,13 @@ sub gen_graph { $xml > io('crawl.gexf'); } +sub graph_repo { + my $self = shift; + $self->_connect unless $self->has_schema; + my $repos = $self->schema->resultset('Repositories')->search({fork => 0}); + while ( my $r = $repos->next ) { + $self->fetch_network($r); + } +} + 1; diff --git a/lib/githubexplorer/Network.pm b/lib/githubexplorer/Network.pm new file mode 100644 index 0000000..e3c4765 --- /dev/null +++ b/lib/githubexplorer/Network.pm @@ -0,0 +1,34 @@ +package githubexplorer::Network; +use 5.010; +use Moose::Role; +use Net::GitHub::V2::Repositories; +use YAML::Syck; + +sub fetch_network { + my ( $self, $repos ) = @_; + + my $api_repos = Net::GitHub::V2::Repositories->new( + owner => $repos->id_profile->login, + repo => $repos->name, + login => $self->api_login, + token => $self->api_token, + ); + + my $edges = $api_repos->network(); + foreach my $edge (@$network) { + next if $edge->{owner} eq $repos->id_profile->login; + my $profile = $self->schema->resultset('Profiles') + ->find( { login => $edge->{owner} } ); + next if !$profile; + + my $relation = $self->schema->resultset('Fork')->find_or_create( + { + profile => $profile->id, + repos => $repos->id + } + ); + } + sleep(1); +} + +1; diff --git a/lib/githubexplorer/Repository.pm b/lib/githubexplorer/Repository.pm index 90adcd0..617e091 100644 --- a/lib/githubexplorer/Repository.pm +++ b/lib/githubexplorer/Repository.pm @@ -2,7 +2,6 @@ package githubexplorer::Repository; use 5.010; use Moose::Role; use Net::GitHub::V2::Repositories; -use YAML::Syck; use Try::Tiny; sub fetch_repositories { diff --git a/lib/githubexplorer/Schema/Result/Fork.pm b/lib/githubexplorer/Schema/Result/Fork.pm index 195c1f9..2a798eb 100644 --- a/lib/githubexplorer/Schema/Result/Fork.pm +++ b/lib/githubexplorer/Schema/Result/Fork.pm @@ -6,23 +6,16 @@ __PACKAGE__->load_components(qw/Core/); __PACKAGE__->table('fork'); __PACKAGE__->add_columns( - profile_origin => { data_type => 'int', }, - profile_dest => { data_type => 'int' }, - repo_origin => { data_type => 'int' }, - repo_dest => { data_type => 'int' }, + profile => { data_type => 'int', }, + repos => { data_type => 'int' }, ); -__PACKAGE__->set_primary_key( - qw/repo_origin repo_dest profile_origin profile_dest/ ); +__PACKAGE__->set_primary_key(qw/repos profile/); -__PACKAGE__->belongs_to( 'profile_origin', - 'githubexplorer::Schema::Result::Profiles' ); -__PACKAGE__->belongs_to( 'profile_dest', +__PACKAGE__->belongs_to( 'profile', 'githubexplorer::Schema::Result::Profiles' ); -__PACKAGE__->belongs_to( 'repo_origin', - 'githubexplorer::Schema::Result::Repositories' ); -__PACKAGE__->belongs_to( 'repo_dest', +__PACKAGE__->belongs_to( 'repos', 'githubexplorer::Schema::Result::Repositories' ); 1; |