Skip to content

Instantly share code, notes, and snippets.

@xdg
Last active April 27, 2019 17:44
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save xdg/7dd1713dda777e95567e to your computer and use it in GitHub Desktop.
Save xdg/7dd1713dda777e95567e to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# Copyright 2015 by David Golden
# Licensed under CC0 https://creativecommons.org/publicdomain/zero/1.0/
# Updated 2016-03-01:
# - more variation in organzations selected; you will want to customize this yourself
# - splits out wishlists differently/correctly
# - reports only PRs unless --all is specified
use v5.10;
use strict;
use warnings;
use utf8;
use Carp;
use Net::GitHub;
use Getopt::Lucid ':all';
use List::Util qw/max/;
my $opts = Getopt::Lucid->getopt(
[
#<<< No perltidy
Switch('all|a'),
Switch('ptg'),
#>>>
]
);
$opts->validate;
sub _git_config {
my $key = shift;
chomp( my $value = `git config --get $key` );
croak "Unknown $key" unless $value;
return $value;
}
my %WATCHLIST = map { $_ => 1 } qw(
CPAN-Common-Index
File-Temp
Parse-CPAN-Meta
Perl-OSType
Sub-Uplevel
YAML-Tiny
);
sub _ptg_watched {
my $repo = $_[0]{repository}{name};
return 1 if $WATCHLIST{$repo};
return 1 if $repo =~ /^CPAN-Meta/;
return;
}
my $github_user = _git_config("github.user");
my $github_token = _git_config("github.token");
my $gh = Net::GitHub->new( access_token => $github_token );
my @issues;
# just xdg issues
push @issues, $gh->query("/user/issues?filter=all&state=open");
while ( $gh->has_next_page ) {
push @issues, $gh->next_page;
}
# select org issues
for my $org ( qw/dagolden cpan-testers/ ) {
push @issues, $gh->query("/orgs/$org/issues?filter=all&state=open");
while ( $gh->has_next_page ) {
push @issues, $gh->next_page;
}
}
# select PTG issues
if ( $opts->get_ptg ) {
push @issues, grep { _ptg_watched($_) } $gh->query("/orgs/Perl-Toolchain-Gang/issues?filter=all&state=open");
while ( $gh->has_next_page ) {
push @issues, grep { _ptg_watched($_) } $gh->next_page;
}
}
my %dash;
for my $i (@issues) {
my $name = $i->{repository}{name};
for (qw/PR wish issue total/) {
$dash{ $name }{$_} //= 0;
}
my $labels = $i->{labels};
my $wishlist = $i->{title} =~ /wish-?list/i
|| grep { /enhancement|question|wishlist/i } map { $_->{name} } @{ $i->{labels} };
my $type =
exists $i->{pull_request} ? 'PR'
: $wishlist ? 'wish'
: 'issue';
$dash{ $name }{$type}++;
$dash{ $name }{total}++ unless $wishlist;
}
my $width = max( map { length($_) } keys %dash );
my @sorted = sort {
$dash{$b}{PR} <=> $dash{$a}{PR}
|| $dash{$b}{issue} <=> $dash{$a}{issue}
|| lc($a) cmp lc($b)
} keys %dash;
for my $k (@sorted) {
next unless $opts->get_all || $dash{$k}{PR};
printf( "%*s %3d %3d %3d\n",
$width, $k, $dash{$k}{PR}, $dash{$k}{issue}, $dash{$k}{wish}, );
}
@shlomif
Copy link

shlomif commented Feb 8, 2016

Hi @xdg!

I cannot get this program to work for me. After applying this diff:

diff --git a/github-dashboard b/github-dashboard
index bae5aed..a815373 100644
--- a/github-dashboard
+++ b/github-dashboard
@@ -7,7 +7,7 @@ use Carp;
 use Net::GitHub;
 use List::Util qw/max/;

-my $org = "dagolden";
+my $org = "shlomif";

 sub _git_config {
     my $key = shift;

I am getting this error:

shlomif@telaviv1:~/Download/unpack/prog/GitHub/f693d02b781739420dc8$ perl -d github-dashboard 

Loading DB routines from perl5db.pl version 1.49
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(github-dashboard:10):    my $org = "shlomif";
  DB<28> c
Not Found at github-dashboard line 24.
 at /usr/lib/perl5/vendor_perl/5.22.0/Net/GitHub/V3/Query.pm line 201.
        Net::GitHub::V3::Query::query(Net::GitHub::V3=HASH(0x31d5100), "/orgs/shlomif/issues?filter=all\x{26}state=open") called at github-dashboard line 24
Debugged program terminated.  Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
  DB<28> 

shlomif@telaviv1:~/Download/unpack/prog/GitHub/f693d02b781739420dc8$ perldoc -l Net::GitHub
/usr/lib/perl5/vendor_perl/5.22.0/Net/GitHub.pm
shlomif@telaviv1:~/Download/unpack/prog/GitHub/f693d02b781739420dc8$ rpm -qf /usr/lib/perl5/vendor_perl/5.22.0/Net/GitHub.pm
perl-Net-GitHub-0.780.0-1.mga6
shlomif@telaviv1:~/Download/unpack/prog/GitHub/f693d02b781739420dc8$ 

How can I fix it?

Regards,

-- Shlomi Fish

@shlomif
Copy link

shlomif commented Feb 8, 2016

Another note is that this code should have an explicit licence and preferably an open source one. And perhaps put it in a normal GitHub repository where people can file issues and pull-requests for it ("shoemaker has no shoes"/etc.).

@shlomif
Copy link

shlomif commented Feb 8, 2016

OK , I was able to fix the problem I was having by using this patch:

diff --git a/github-dashboard b/github-dashboard
index bae5aed..29a97f4 100644
--- a/github-dashboard
+++ b/github-dashboard
@@ -7,7 +7,7 @@ use Carp;
 use Net::GitHub;
 use List::Util qw/max/;

-my $org = "dagolden";
+my $org = "shlomif";

 sub _git_config {
     my $key = shift;
@@ -21,7 +21,8 @@ my $github_token = _git_config("github.token");

 my $gh = Net::GitHub->new( access_token => $github_token );

-my @issues = $gh->query("/orgs/$org/issues?filter=all&state=open");
+# my @issues = $gh->query("/orgs/$org/issues?filter=all&state=open");
+my @issues = $gh->query("/user/issues?filter=all&state=open");

 while ( $gh->has_next_page ) {
     push @issues, $gh->next_page;

Still it seems like this should be configurable.

@wollmers
Copy link

wollmers commented Feb 8, 2016

@shlomif If you use github.token you don't need user or org. You only need org if you access an org.

@xdg
Copy link
Author

xdg commented Mar 1, 2016

I've update the gist to reflect my current iteration of it. Licensed CC0

@shlomif
Copy link

shlomif commented Mar 1, 2016

@xdg : thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment