Skip to content

add irc links if included in metadata #1287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2014
Merged
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
2 changes: 2 additions & 0 deletions lib/MetaCPAN/Web/Controller/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ sub view : Private {
$c->res->last_modified( $out->{date} );

my $contribs = $self->groom_contributors( $c, $out );
my $irc = $self->groom_irc( $c, $out );

$c->stash( $c->model('API::Favorite')->find_plussers($distribution) );

Expand All @@ -124,6 +125,7 @@ sub view : Private {
files => \@view_files,

contributors => $contribs,
irc => $irc,

# TODO: Put this in a more general place.
# Maybe make a hash for feature flags?
Expand Down
46 changes: 46 additions & 0 deletions lib/MetaCPAN/Web/Role/ReleaseInfo.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package MetaCPAN::Web::Role::ReleaseInfo;

use Moose::Role;
use URI;
use URI::Escape qw(uri_escape uri_unescape);
use URI::QueryParam;

# TODO: are there other controllers that do (or should) include this?

Expand Down Expand Up @@ -111,4 +114,47 @@ sub groom_contributors {
return \@contribs;
}

sub groom_irc {
my ( $self, $c, $release ) = @_;

my $irc = $release->{metadata}{resources}{x_IRC};
my $irc_info = ref $irc ? {%$irc} : { url => $irc };

if ( !$irc_info->{web} && $irc_info->{url} ) {
my $url = URI->new( $irc_info->{url} );
my $scheme = $url->scheme;
if ( $scheme && ( $scheme eq 'irc' || $scheme eq 'ircs' ) ) {
my $ssl = $scheme eq 'ircs';
my $host = $url->authority;
$host =~ s/:(\d+)$//;
my $port = $1;
$host =~ s/^(.*)@//;
my $user = $1;
my $path = uri_unescape( $url->path );
$path =~ s{^/}{};
my $channel
= $path || $url->fragment || $url->query_param('channel');
$channel =~ s/^(?![#~!+])/#/;
$channel = uri_escape($channel);

if ( $host eq 'freenode.net' ) {
$irc_info->{web}
= "https://webchat.freenode.net/?randomnick=1&prompt=1&channels=${channel}";
}
else {
my $server = $host
. (
$ssl ? q{:+} . ( $port || 6697 )
: $port ? ":$port"
: q{}
);
$irc_info->{web}
= "https://chat.mibbit.com/?channel=${channel}&server=${server}";
}
}
}

return $irc_info;
}

1;
7 changes: 6 additions & 1 deletion root/inc/release-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<li>
<div><a href="http://cpants.charsbar.org/dist/overview/<% release.distribution %>">Kwalitee</a></div>
</li>
<% IF irc.web %>
<li>
<div><a href="<% irc.web %>">Chat with Maintainers</a></div>
</li>
<% END %>
<% IF release.license %>
<li>License: <% release.license.join(', ') %></li>
<% END %>
Expand All @@ -69,4 +74,4 @@
<option value="<% version.author; '/'; version.name; '/'; module.path %>"><% version.version _ (version.maturity == 'developer' ? ' DEV' : '') %> (<%version.author %> on <% version.date.dt_date_common %>)
</option>
<% END %>
<% END; END %>
<% END; END %>