123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- use Encode;
- use JSON;
- use POE;
- my $dolink = sub { BotPlugin::call('templink', 'make', shift); };
- my %repo_providers = (
- github => {
- shortlog => "https://github.com/{key}/commits/{ref}",
- commit => "https://github.com/{key}/commit/{ref}",
- blob => "https://github.com/{key}/blob/{ref}/{path}",
- tree => "https://github.com/{key}/tree/{ref}/{path}",
- main => "https://github.com/{key}",
- },
- gitlab => {
- shortlog => "https://gitlab.com/{key}/commits/{ref}",
- commit => "https://gitlab.com/{key}/commit/{ref}",
- blob => "https://gitlab.com/{key}/blob/{ref}/{path}",
- tree => "https://gitlab.com/{key}/tree/{ref}/{path}",
- main => "https://gitlab.com/{key}",
- },
- bitbucket => {
- # Bitbucket doesn't have a nice generic shortlog by base
- # commit, show commit instead
- shortlog => "https://bitbucket.org/{key}/commits/{ref}",
- commit => "https://bitbucket.org/{key}/commits/{ref}",
- blob => "https://bitbucket.org/{key}/src/{ref}/{path}",
- tree => "https://bitbucket.org/{key}/src/{ref}/{path}",
- main => "https://bitbucket.org/{key}",
- },
- kernel => {
- shortlog => "https://git.kernel.org/cgit/{key}.git/log/?h={ref}",
- commit => "https://git.kernel.org/cgit/{key}.git/commit/?id={ref}",
- blob => "https://git.kernel.org/cgit/{key}.git/tree/{path}?h={ref}",
- tree => "https://git.kernel.org/cgit/{key}.git/tree/{path}?h={ref}",
- main => "https://git.kernel.org/cgit/{key}.git",
- },
- repo => {
- shortlog => "http://repo.or.cz/w/{key}/shortlog/{ref}",
- commit => "http://repo.or.cz/w/{key}/commit/{ref}",
- blob => "http://repo.or.cz/w/{key}/blob/{ref}:/{path}",
- tree => "http://repo.or.cz/w/{key}/tree/{ref}:/{path}",
- main => "http://repo.or.cz/w/{key}",
- },
- notabug => {
- shortlog => "https://notabug.org/{key}/commits/{ref}",
- commit => "https://notabug.org/{key}/commit/{ref}",
- blob => "https://notabug.org/{key}/src/{ref}/{path}",
- tree => "https://notabug.org/{key}/src/{ref}/{path}",
- main => "https://notabug.org/{key}",
- },
- );
- {
- irc_on_raw_anymsg => sub {
- my $ev = $_[ARG0];
- BotIrc::check_ctx(wisdom_auto_redirect => 1) or return 1;
- my $text = $ev->{params}[1];
- $text =~ s/git::(\S+)/git:github:git\/git:$1/g;
- $text =~ s/git\[(\S+)\s+(\S+?)\]\s*(\S+)/git:$1:$2:$3/g;
- while ($text =~ /git:(\S+)/ig) {
- my $query = $1;
- $query =~ s/^"(.+?)"$/$1/;
- my ($type, $key, $spec) = split(/:/, $query, 3);
- next unless exists $repo_providers{$type};
- my $prov = $repo_providers{$type};
- my $ref = 'HEAD';
- my $path;
- my $commit;
- if ($spec =~ s/^([^:]*)://) {
- $ref = $1 unless $1 eq '';
- } elsif (defined $spec) {
- $ref = $spec;
- $path = []; # sticky undef
- } else {
- $ref = [];
- $path = [];
- }
- unless (ref $ref) {
- $commit = 1 if $ref =~ /^[0-9a-fA-F]{4,}$/;
- $commit = 1 if $ref =~ s/\^\{commit\}$|\^c$//;
- $commit = 0 if $ref =~ s/\^\{log\}$|\^l$//;
- }
- $path = $spec unless ref $path;
- undef $path if ref $path;
- my $mode = defined $path ? 'blob' : 'shortlog';
- $mode = 'tree' if defined $path && $path =~ m#(?:^|/)$#;
- $mode = 'main' if ref $ref;
- $mode = 'commit' if $mode eq 'shortlog' and $commit;
- my $frag;
- ($path, $frag) = split(/#/, ($path||''), 2);
- $frag ||= '';
- $frag = "#$frag" if $frag;
- my $url = $repo_providers{$type}{$mode};
- $url =~ s/\{key\}/$key/;
- $url =~ s/\{ref\}/$ref/;
- $url =~ s/\{path\}/$path/;
- BotIrc::send_wisdom("Git web link: $url$frag");
- }
- return 0;
- },
- };
|