Skip to content

Commit

Permalink
Merge pull request #44 from yanick/master
Browse files Browse the repository at this point in the history
Make 'list' command work with API v3.  thanks @tyru and @yanick
  • Loading branch information
c9s committed Nov 3, 2012
2 parents 5e356f9 + 8e50edb commit 61e49d7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
6 changes: 4 additions & 2 deletions lib/App/gh.pm
Expand Up @@ -26,8 +26,10 @@ sub github {
my $github_id = $class->config->github_id;
my $github_password = $class->config->github_password;

die('Please configure your github.user') unless $github_id;
die('Please configure your github.password') unless $github_password;
die "Please configure your github.user in .gitconfig (see App::gh pod)\n"
unless $github_id;
die "Please configure your github.password in .gitconfig (See App::gh pod)\n"
unless $github_password;

return $GITHUB ||= Net::GitHub->new( # Net::GitHub::V3
login => $github_id,
Expand Down
7 changes: 5 additions & 2 deletions lib/App/gh/Command/List.pm
Expand Up @@ -27,9 +27,12 @@ sub run {
$acc =~ s{/$}{};

# TODO: use api class.
my $repolist = App::gh->api->user_repos( $acc );
my $query = App::gh->github->repos;
my @repolist = $query->list_user($acc);
push @repolist, $query->next_page while $query->has_next_page;

my @lines = ();
for my $repo ( @$repolist ) {
for my $repo ( @repolist ) {
my $repo_name = $repo->{name};

# name-only
Expand Down
56 changes: 28 additions & 28 deletions lib/App/gh/Config.pm
Expand Up @@ -3,46 +3,46 @@ use warnings;
use strict;
use File::HomeDir ();
use File::Spec;

sub _parse_options {
my $part = shift;
my $options;
while( $part =~ /^\s*(.+?)\s*=\s*(.*?)\s*$/gm ) {
my ($name,$value) = ($1,$2);
$options->{ $name } = $value;
}
return $options;
}
use File::Basename qw(dirname);




my %_parse_memoize;
# XXX: use Config::Tiny to parse ini format config.
sub parse {
my ( $class, $file ) = @_;

# read file
open FH , "<" , $file;
local $/;
my $content = <FH>;
close FH;
# Return cached result.
$file = File::Spec->rel2abs($file);
return $_parse_memoize{$file} if exists $_parse_memoize{$file};

# TODO: simply parse config.... better choice ?
my @parts = split /(?=\[.*?\])/,$content;
my %config;
for my $part ( @parts ) {
if( $part =~ /^\[(\w+)\s+["'](\w+)["']\]/g ) {
my ($o1 , $o2 ) = ($1, $2);
$config{ $o1 } ||= {};
$config{ $o1 }->{ $o2 }
= _parse_options( $part );
}
elsif( $part =~ /^\[(.*?)\]/g ) {
my $key = $1;
my $options = _parse_options( $part );
$config{ $key } = $options;
for my $line (split "\n", qx(git config --list -f '$file')) {
# $line = foo.bar.baz=value
if (my ($key, $value) = ($line =~ m/^([^=]+)=(.*)/)) {
my $h = \%config;
if ($key eq 'include.path') {
my $path = File::Spec->file_name_is_absolute($value) ? $value : File::Spec->rel2abs($value, dirname($file));
%config = (%config, %{ $class->parse($path) });
# Uncomment this to get rid of "include.path" in %config
#next;
}
my @keys = split /\./, $key;
next unless @keys;
# Create empty hashref.
# %config = (foo => {bar => ($h = {})})
for (@keys[0..$#keys-1]) {
$h->{$_} = {} unless exists $h->{$_};
$h = $h->{$_};
}
# $config{foo}{bar}{baz} = $value;
$h->{$keys[-1]} = $value;
}
}

# Cache result not to invoke 'git' command frequently.
$_parse_memoize{$file} = \%config;
return \%config;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/App/gh/Utils.pm
Expand Up @@ -74,7 +74,7 @@ sub print_list {
if ( $ENV{WRAP} && ( $column_w + 3 + length( join(" ",@$arg)) ) > $screen_width ) {
# wrap description
my $string =
color('bold white') .
color('bold') .
$title .
color('reset') .
" " x $padding . " - " . join(" ",@$arg) . "\n";
Expand Down Expand Up @@ -107,7 +107,7 @@ sub print_list {
print "\n" if $wrapped;
}
else {
print color 'bold white';
print color 'bold';
print $title;
print color 'reset';
print " " x $padding;
Expand Down

0 comments on commit 61e49d7

Please sign in to comment.