Search Perl 6 repos with Marchex/github-api-tools

Chris Nandor has been bugging me to use the Github tools he helped to develop for Marchex, so when I posted about Hound he showed me another way to search multiple GitHub repos at the same time. This version only works if everything is on GitHub (or your Enterprise version of that), but the Hound version can work with whatever mix of version control systems have, either local, remote, or both.

This task is really simple, so it’s not that impressive for those tools, but you can still search multiple GitHub repos. It only looks like you need a GitHub personal access token because the tools assume you’ll want to do all the other stuff too. The stuff here doesn’t actually use the GitHub API.

Now I put it all together. This is really the sort of thing that Perl 5 was made to do. Here’s a quickie Perl 5 example (and hey, last time is was Go, so I’m getting closer). This constructs the right query, submits it to GitHub, and opens your browser to the results.

#!/Users/brian/bin/perls/perl5.14.2
use v5.10;

# You might have Enterprise, so this would be different
$ENV{GITHUB_HOST}  //= 'github.com';
$ENV{GITHUB_TOKEN} //= 'vanilla nut taps'; # can be anything, but var needs to be defined

# https://github.com/Marchex/github-api-tools
my $binary = '/Users/brian/bin/perls/github_search5.14.2';

my $repos = join ' ', map { "repo:$_" } qw(
	rakudo/rakudo
	perl6/nqp
	perl6/doc
	perl6/roast
	perl6/specs
	);

@ARGV = qw(Mayor of Dunkin) unless @ARGV;
my @command = (
	$binary,
	'-O',
	'-f',
	"'$repos'",
	@ARGV
	);

say "@command";
system { $command[0] } @command;

To run it, I give it something to search:

$ search_perl6 encoding

(See that result).

But, I don't really need any Perl 5 here. Although the Marchex tools are in Perl 5, my program merely glues together a bunch of stuff then shells out. The Perl 6 version doesn't look that much different:

#!/Applications/Rakudo/bin/perl6
use v6;

# You might have Enterprise, so this would be different
%*ENV{'GITHUB_HOST'}  //= 'github.com';
%*ENV{'GITHUB_TOKEN'} //= 'gfy'; # can be anything, but var needs to be defined

# https://github.com/Marchex/github-api-tools
my $binary = '/Users/brian/bin/perls/github_search5.14.2';

my $repos = q:w{
	rakudo/rakudo
	perl6/nqp
	perl6/doc
	perl6/roast
	perl6/specs
	}.map( { "repo:$_" } ).join( ' ' );

@*ARGS = q:w/Mayor of Dunkin/ unless @*ARGS;
my @command = (
	$binary,
	'-O',
	'-f',
	"'$repos'",
	|@*ARGS  # flatten that list with |
	);

say "{@command}";
run |@command;  # From class Proc https://docs.perl6.org/type/Proc

Either way I see two benefits here. I can do it from the command line and it will automatically open my browser with the results. And, I don't have to remember how to type out the query. Since it doesn't use the GitHub API, it also doesn't count against my search rate limit. So, maybe two and a half benefits.

Leave a Reply

Your email address will not be published. Required fields are marked *