Skip to content

Instantly share code, notes, and snippets.

@xdg
Last active April 27, 2019 17:44
Show Gist options
  • 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

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