Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/Bot/BasicBot/Pluggable/Module/GitHub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use base 'Bot::BasicBot::Pluggable::Module';
# want.

use strict;
use Net::GitHub::V2;
use Net::GitHub::V3;

our $VERSION = '0.04';

Expand Down Expand Up @@ -42,19 +42,18 @@ sub ng {
return $ng;
}

my %ngparams = (
owner => $user,
repo => $project,
);
my %ngparams;
# If authentication is needed, add that in too:
if (my $auth = $self->auth_for_project("$user/$project")) {
my ($auth_user, $token) = split /:/, $auth, 2;
$ngparams{login} = $auth_user;
$ngparams{token} = $token;
$ngparams{pass} = $token;
$ngparams{always_Authorization} = 1;
}

return $net_github{"$user/$project"} = Net::GitHub::V2->new(%ngparams);

my $ng = Net::GitHub::V3->new(%ngparams);
$ng->set_default_user_repo($user, $project);
return $net_github{"$user/$project"} = $ng;
}


Expand Down
35 changes: 22 additions & 13 deletions lib/Bot/BasicBot/Pluggable/Module/GitHub/EasyLinks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ sub said {

return unless $pri == 2;

# If the message was from the bot (for e.g. another module announcing the
# title of an URL we just said, etc), go no further, to avoid loops
return if $mess->{who} eq $self->bot->nick;

# Loop through matching things in the message body, assembling quick links
# ready to return.
Expand All @@ -54,15 +57,15 @@ sub said {

my $project = $+{project} || $self->github_project($mess->{channel});
return unless $project;

# Search through all the projects to see if the search word matches
$project = $self->search_projects($mess->{channel}, $+{search})
|| $project;

# Get the Net::GitHub::V2 object we'll be using. (If we don't get one,
# Get the Net::GitHub::V3 object we'll be using. (If we don't get one,
# for some reason, we can't do anything useful.)
my $ng = $self->ng($project) or return;

# First, extract what kind of thing we're looking at, and normalise it a
# little, then go on to handle it.
my $thing = $+{thing};
Expand All @@ -78,7 +81,7 @@ sub said {
# Right, handle it in the approriate way
if ($thing =~ /Issue|GH/i) {
warn "Handling issue $thingnum";
my $issue = $ng->issue->view($thingnum);
my $issue = $ng->issue->issue($thingnum);
if (exists $issue->{error}) {
push @return, $issue->{error};
next match;
Expand All @@ -95,25 +98,31 @@ sub said {
# TODO: send a pull request to add support for fetching details of
# pull requests to Net::GitHub::V2, so we can handle PRs on private
# repos appropriately.
my $pull_url = "https://github.com/$project/pull/$thingnum";
my $title = URI::Title::title($pull_url);
push @return, "Pull request $thingnum ($title) - $pull_url";
my $pull = $ng->pull_request->pull($thingnum);
my $status = $pull->{merged} ? 'merged' : 'open';
push @return,
sprintf "Pull request $thingnum is %s (%s by %s) - %s",
$status,
$pull->{title},
$pull->{user}{login},
$pull->{html_url};
}

# If it was a commit:
if ($thing eq 'commit') {
warn "Handling commit $thingnum";
my $commit = $ng->commit->show($thingnum);
warn "Got an NG object: $ng";
my $commit = $ng->repos->commit($thingnum);
if ($commit && !exists $commit->{error}) {
my $title = ( split /\n+/, $commit->{message} )[0];
my $url = $commit->{url};
my $title = ( split /\n+/, $commit->{commit}{message} )[0];
my $url = $commit->{html_url};
my $author = $commit->{commit}{author}{name};

# Currently, the URL given doesn't include the host, but that
# might perhaps change in future, so play it safe:
$url = "https://github.com$url" unless $url =~ /^http/;
push @return, sprintf "Commit $thingnum (%s) - %s",
$title,
$url;
push @return, sprintf "Commit $thingnum (%s by %s) - %s",
$title, $author, $url;
} else {
# We purposefully don't show a message on IRC here, as we guess
# what might be a SHA, so we could be annoying saying that we
Expand Down