diff options
| author | franck cuny <franck@lumberjaph.net> | 2011-06-13 16:33:23 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2011-06-13 16:33:23 +0200 |
| commit | 871336c030209b46ae6b124a702677363487f9a8 (patch) | |
| tree | 86f234d42c68b26a7aeb9cc373667127ad661e19 /lib/GitHub/Collector/Command/lang.pm | |
| parent | use template_toolkit and add infos about colors (diff) | |
| download | stargit-871336c030209b46ae6b124a702677363487f9a8.tar.gz | |
import github::collector
Signed-off-by: franck cuny <franck@lumberjaph.net>
Diffstat (limited to 'lib/GitHub/Collector/Command/lang.pm')
| -rw-r--r-- | lib/GitHub/Collector/Command/lang.pm | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/GitHub/Collector/Command/lang.pm b/lib/GitHub/Collector/Command/lang.pm new file mode 100644 index 0000000..8ab6c20 --- /dev/null +++ b/lib/GitHub/Collector/Command/lang.pm @@ -0,0 +1,72 @@ +package GitHub::Collector::Command::lang; + +use Moose; +use boolean; + +extends qw(MooseX::App::Cmd::Command); + +with qw( + GitHub::Collector::Role::Logger + GitHub::Collector::Role::Context + GitHub::Collector::Role::MongoDB +); + +sub execute { + my $self = shift; + + $self->log("start to tag user using langs"); + + my $profiles = $self->db_profiles->find({ language => undef } ); + + while (my $profile = $profiles->next){ + $self->_tag_profile_by_lang($profile); + } + + $self->log("done tagging users"); +} + +sub _tag_profile_by_lang { + my ( $self, $profile ) = @_; + + my $languages = {}; + + $self->_repos( $languages, $profile->{login} ); + $self->_contribs( $languages, $profile->{login} ); + + my $lang = ( + sort { $languages->{$b} <=> $languages->{$a} } + keys %$languages + )[0]; + + $lang = "none "if ( !$lang ); + + $self->log( "pour " . $profile->{login} . " on a " . $lang ); + $self->db_profiles->update( + { login => $profile->{login}, }, + { '$set' => { language => $lang } } + ); +} + +sub _repos { + my ( $self, $languages, $login ) = @_; + + my $repositories = $self->db_repositories->find( { owner => $login } ); + + while ( my $repo = $repositories->next ) { + $languages->{ $repo->{lang} }++ if $repo->{lang}; + } +} + +sub _contribs { + my ( $self, $languages, $login ) = @_; + + my $contribs = $self->db_contributors->find( { contributor => $login } ); + + while ( my $contrib = $contribs->next ) { + my $repo = $self->db_repositories->find_one( + { uniq_name => $contrib->{project} } ); + $languages->{ $repo->{lang} }++ if $repo->{lang}; + } +} + +1; |
