Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Starting new module's git repo.

Getting it under version control; nowhere near ready to release, yet.
  • Loading branch information...
commit 0750b9b4d4022d779ed230a572983dbde51b2a7b 0 parents
@bigpresh authored
13 Changes
@@ -0,0 +1,13 @@
+Revision history for Bot-BasicBot-Pluggable-Module-GitHub
+
+0.01 2011-05-03
+ First version. These are modules I've been using in #dancer on
+ irc.perl.org, and I figured it would be helpful to package them up and
+ release them to CPAN.
+
+ I have further plans to implement, including a module to handle GitHub
+ hooks by spawning a super-basic web server on a configured port which
+ would receive JSON payloads from GitHub's hooks and do the appropriate
+ thing (announcing commits/changed issues/pull requests/etc)
+
+
11 MANIFEST
@@ -0,0 +1,11 @@
+Changes
+MANIFEST
+Makefile.PL
+README
+lib/Bot/BasicBot/Pluggable/Module/GitHub.pm
+lib/Bot/BasicBot/Pluggable/Module/GitHub/EasyLinks.pm
+lib/Bot/BasicBot/Pluggable/Module/GitHub/PullRequests.pm
+t/00-load.t
+t/manifest.t
+t/pod-coverage.t
+t/pod.t
20 Makefile.PL
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'Bot::BasicBot::Pluggable::Module::GitHub',
+ AUTHOR => q{David Precious <davidp@preshweb.co.uk>},
+ VERSION_FROM => 'lib/Bot/BasicBot/Pluggable/Module/GitHub.pm',
+ ABSTRACT_FROM => 'lib/Bot/BasicBot/Pluggable/Module/GitHub.pm',
+ ($ExtUtils::MakeMaker::VERSION >= 6.3002
+ ? ('LICENSE'=> 'perl')
+ : ()),
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'Bot::BasicBot::Pluggable::Module' => 0,
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'Bot-BasicBot-Pluggable-Module-GitHub-*' },
+);
50 README
@@ -0,0 +1,50 @@
+Bot-BasicBot-Pluggable-Module-GitHub
+
+A module for Bot::BasicBot::Pluggable IRC bots, providing GitHub related IRC
+utilities.
+
+See the individual modules within the distribution for details on what features
+each one provides.
+
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the
+perldoc command.
+
+ perldoc Bot::BasicBot::Pluggable::Module::GitHub
+
+You can also look for information at:
+
+ RT, CPAN's request tracker
+ http://rt.cpan.org/NoAuth/Bugs.html?Dist=Bot-BasicBot-Pluggable-Module-GitHub
+
+ AnnoCPAN, Annotated CPAN documentation
+ http://annocpan.org/dist/Bot-BasicBot-Pluggable-Module-GitHub
+
+ CPAN Ratings
+ http://cpanratings.perl.org/d/Bot-BasicBot-Pluggable-Module-GitHub
+
+ Search CPAN
+ http://search.cpan.org/dist/Bot-BasicBot-Pluggable-Module-GitHub/
+
+
+LICENSE AND COPYRIGHT
+
+Copyright (C) 2011 David Precious
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See http://dev.perl.org/licenses/ for more information.
+
12 ignore.txt
@@ -0,0 +1,12 @@
+blib*
+Makefile
+Makefile.old
+Build
+Build.bat
+_build*
+pm_to_blib*
+*.tar.gz
+.lwpcookies
+cover_db
+pod2htm*.tmp
+Bot-BasicBot-Pluggable-Module-GitHub-*
113 lib/Bot/BasicBot/Pluggable/Module/GitHub.pm
@@ -0,0 +1,113 @@
+package Bot::BasicBot::Pluggable::Module::GitHub;
+use base 'Bot::BasicBot::Pluggable::Module::GitHub';
+
+# This module is intended to be used as a base by the B::B::P::M::GitHub::*
+# modules, and provides some shared functionality (reading the default project
+# for a channel from the bot's store, etc).
+#
+# It should not be loaded directly by the bot; load the desired modules you
+# want.
+
+use warnings;
+use strict;
+
+our $VERSION = '0.01';
+
+
+sub github_project {
+ my ($self, $channel) = @_;
+
+ my $projects = $self->get('user_github_project')
+ or return false;
+
+ # The user may have provided channel-specific projects definitions in the
+ # format:
+ # '#channel1:user/repo;#channel2:user/repo'
+ return $projects if ($projects !~ /:/);
+
+ # Or, they may have simply provided a project name which should apply to
+ # all channels the bot is in.
+ my %repo_for_channel = map {
+ split /[:]/
+ } split /[;,]/, $projects;
+ return %repo_for_channel{$channel};
+}
+
+
+
+
+=head1 NAME
+
+Bot::BasicBot::Pluggable::Module::GitHub - GitHub-related modules for IRC bots running Bot::BasicBot::Pluggable
+
+=head1 MODULES
+
+The following modules are included - see the documentation for each for details
+on how to use them.
+
+=over 4
+
+=item L<Bot::BasicBot::Pluggable::Module::GitHub::PullRequests>
+
+Monitor pull requests for GitHub projects.
+
+=item L<Bot::BasicBot::Pluggable::Module::GitHub::EasyLinks>
+
+Provide quick URLs to view issues/pull requests etc.
+
+=back
+
+=head1 Loading modules
+
+See the L<Bot::BasicBot::Pluggable> documentation for how to load these modules
+into your bot.
+
+Do not load this module directly; load the modules named above individually.
+This module is intended only to provide a base for the other modules, including
+shared functionality and common documentation.
+
+
+=head1 Configuring the default project repo
+
+The modules above need to know what GitHub project repository they should refer
+to.
+
+You can configure a project which applies to all channels the bot is in, or
+configure a different project for each channel if the bot is in multiple
+channels.
+
+The easiest way to change the setting is using the
+L<Bot::BasicBot::Pluggable::Module::Vars> module - with that module loaded,
+authenticate with the bot (see L<Bot::BasicBot::Pluggable::Module::Auth>) then
+send the bot a command like:
+
+ set github_project githubusername/githubprojectname
+
+For example, for this project:
+
+ set gitpub_project bigpresh/Bot-BasicBot-Pluggable-Module-GitHub
+
+Alternatively, you can change the C<user_github_project> setting directly in the
+bot's store; see the L<Bot::BasicBot::Pluggable::Store> documentation.
+
+
+=head1 AUTHOR
+
+David Precious C<<davidp@preshweb.co.uk>>
+
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2011 David Precious.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of either: the GNU General Public License as published
+by the Free Software Foundation; or the Artistic License.
+
+See http://dev.perl.org/licenses/ for more information.
+
+
+=cut
+
+
+1; # End of Bot::BasicBot::Pluggable::Module::GitHub
64 lib/Bot/BasicBot/Pluggable/Module/GitHub/EasyLinks.pm
@@ -0,0 +1,64 @@
+# A quick Bot::BasicBot::Pluggable module to provide easy links when someone
+# mentions an issue / pull request / commit.
+#
+# Use the vars module to configure the project in question. (So, this will only
+# really be of use to a bot in a single-project-related channel.)
+#
+# David Precious <davidp@preshweb.co.uk>
+
+package Bot::BasicBot::Pluggable::Module::GitHubLinks;
+use strict;
+use base 'Bot::BasicBot::Pluggable::Module';
+use LWP::Simple ();
+use JSON;
+
+sub help {
+ return <<HELPMSG;
+Provide convenient links to GitHub issues/pull requests/commits etc.
+
+If someone says e.g. "Issue 42", the bot will helpfully provide an URL to view
+that issue directly.
+
+The project these relate to must be configured using the vars module to set the
+'default project' setting (or directly set user_default_project in the bot's
+store).
+
+HELPMSG
+}
+
+
+sub said {
+ my ($self, $mess, $pri) = @_;
+
+ return unless $pri == 2;
+
+ if ($mess->{body} =~ /^!pr (?: \s+ (\S+))?/xi) {
+ my $check_project = $1;
+ $check_project ||= get_default_project(
+ $self->get('user_github_project'), $mess->{channel}
+ );
+ if (!$check_project) {
+ $self->reply(
+ $mess,
+ "No GitHub project defined"
+ );
+ return 1;
+ }
+ for my $project (split /,/, $check_project) {
+ my $prs = $self->_get_pull_request_count($project);
+ $self->say(
+ channel => $mess->{channel},
+ body => "Open pull requests for $project : $prs",
+ );
+ }
+ return 1; # "swallow" this message
+ }
+ return 0; # This message didn't interest us
+}
+
+
+
+
+
+1;
+
79 lib/Bot/BasicBot/Pluggable/Module/GitHub/PullRequests.pm
@@ -0,0 +1,79 @@
+# A quick Bot::BasicBot::Pluggable module to fetch a count of open pull requests
+# for a GitHub project.
+#
+# David Precious <davidp@preshweb.co.uk>
+
+package Bot::BasicBot::Pluggable::Module::GitHubPullRequests;
+use strict;
+use base 'Bot::BasicBot::Pluggable::Module';
+use LWP::Simple ();
+use JSON;
+
+sub help {
+ return <<HELPMSG;
+Monitors outstanding pull requests on a GitHub project.
+
+Allows use of a !pr command to fetch the current count of open pull requests
+including a tally by user.
+
+Usage: !pr user/project, or just !pr for the default project, configured by
+setting the 'github_project' setting using the Vars module (or by directly
+setting the user_github_project setting in the bot's store).
+HELPMSG
+}
+
+
+sub said {
+ my ($self, $mess, $pri) = @_;
+
+ return unless $pri == 2;
+
+ if ($mess->{body} =~ /^!pr (?: \s+ (\S+))?/xi) {
+ my $check_projects = $1;
+ $check_projects ||= $self->get('user_github_project');
+ if (!$check_projects) {
+ $self->reply(
+ $mess,
+ "No project(s) to check; either specify"
+ . " a project, e.g. '!pr username/project', or use the Vars"
+ . " module to configure the github_project setting for this"
+ . " module to set the default project to check."
+ );
+ return 1;
+ }
+ for my $project (split /,/, $check_projects) {
+ my $prs = $self->_get_pull_request_count($project);
+ $self->say(
+ channel => $mess->{channel},
+ body => "Open pull requests for $project : $prs",
+ );
+ }
+ return 1; # "swallow" this message
+ }
+ return 0; # This message didn't interest us
+}
+
+
+sub _get_pull_request_count {
+ my ($self, $project) = @_;
+ my $url = "http://github.com/api/v2/json/pulls/" . $project;
+ my $json = LWP::Simple::get($url)
+ or return "Unknown - error fetching $url";
+ my $pulls = JSON::from_json($json)
+ or return "Unknown - error parsing API response";
+
+ my %pulls_by_author;
+ $pulls_by_author{$_}++
+ for map { $_->{issue_user}{login} } @{ $pulls->{pulls} };
+ my $msg = scalar @{ $pulls->{pulls} } . " pull requests open (";
+ $msg .= join(", ",
+ map { "$_:$pulls_by_author{$_}" }
+ sort { $pulls_by_author{$b} <=> $pulls_by_author{$a} }
+ keys %pulls_by_author
+ );
+ $msg .= ")";
+ return $msg;
+}
+
+1;
+
14 t/00-load.t
@@ -0,0 +1,14 @@
+#!perl -T
+
+# Just make sure they compile, at least.
+
+use Test::More tests => 3;
+
+BEGIN {
+ use_ok( 'Bot::BasicBot::Pluggable::Module::GitHub');;
+ use_ok( 'Bot::BasicBot::Pluggable::Module::GitHub::EasyLinks');
+ use_ok( 'Bot::BasicBot::Pluggable::Module::GitHub::PullRequests');
+
+}
+
+diag( "Testing Bot::BasicBot::Pluggable::Module::GitHub $Bot::BasicBot::Pluggable::Module::GitHub::VERSION, Perl $], $^X" );
36 t/01-parse-config.t
@@ -0,0 +1,36 @@
+#!perl -T
+
+# Test the config setting parsing.
+# Bless the object into a different package which overrides fetching from the
+# store.
+package MockBot;
+sub get {
+ return shift->{_fake_config_setting};
+};
+
+
+package main;
+
+use Test::More tests => 4;
+use Bot::BasicBot::Pluggable::Module::GitHub;
+
+my $plugin = Bot::BasicBot::Pluggable::Module::GitHub->new;
+bless $plugin => 'MockBot';
+
+# First, if we provide an overall project for all channels, we should get it
+# back for a random channel:
+$plugin->{_fake_config_setting} = 'user/repo';
+is($plugin_>github_project('#fake'), 'user/repo',
+ "Configuring repo for all channels works");
+
+# Now, if we configure different projects for different channels, make sure they
+# work:
+$plugin->{_fake_config_setting} = '#chan1:user1/repo1;#chan2:user2/repo2');
+is($plugin->_github_project('#chan1', 'user1/repo1',
+ "Per-channel repo works");
+is($plugin->_github_project('#chan2', 'user2/repo2',
+ "Per-channel repo works");
+is ($plugin->_github_project('#fake', undef,
+ "Per-channel repo returns nothing for non-matching channel");
+
+
13 t/manifest.t
@@ -0,0 +1,13 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+unless ( $ENV{RELEASE_TESTING} ) {
+ plan( skip_all => "Author tests not required for installation" );
+}
+
+eval "use Test::CheckManifest 0.9";
+plan skip_all => "Test::CheckManifest 0.9 required" if $@;
+ok_manifest();
18 t/pod-coverage.t
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod::Coverage
+my $min_tpc = 1.08;
+eval "use Test::Pod::Coverage $min_tpc";
+plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
+ if $@;
+
+# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
+# but older versions don't recognize some common documentation styles
+my $min_pc = 0.18;
+eval "use Pod::Coverage $min_pc";
+plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
+ if $@;
+
+all_pod_coverage_ok();
12 t/pod.t
@@ -0,0 +1,12 @@
+#!perl -T
+
+use strict;
+use warnings;
+use Test::More;
+
+# Ensure a recent version of Test::Pod
+my $min_tp = 1.22;
+eval "use Test::Pod $min_tp";
+plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
+
+all_pod_files_ok();
Please sign in to comment.
Something went wrong with that request. Please try again.