From 8a093bda210a2b3346872ec1c212e6b2562cf390 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Mon, 25 Jul 2016 19:46:23 +0000 Subject: Bug 1282931 - update git.mozilla.org links on the fly for BMO/Bugzilla to point to github.com instead --- extensions/BMO/Extension.pm | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'extensions') diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 06dbe7c0f..ca4701748 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -709,6 +709,59 @@ sub bug_format_comment { } }); + # Update certain links to git.mozilla.org to go to github.com instead + # https://git.mozilla.org/?p=webtools/bmo/bugzilla.git;a=blob;f=Bugzilla/WebService/Bug.pm;h=d7a1d8f9bb5fdee524f2bb342a4573a63d890f2e;hb=HEAD#l657 + push(@$regexes, { + match => qr#\b(https?://git\.mozilla\.org\S+)\b#mx, + replace => sub { + my $args = shift; + my $match = $args->{matches}->[0]; + my $uri = URI->new($match); + + # Only work on BMO and Bugzilla repos + my $repo = $uri->query_param_delete("p") || ''; + if ($repo !~ /(webtools\/bmo|bugzilla)\//) { + return qq#$match#; + } + + my $text = html_quote($match); + my $action = $uri->query_param_delete("a") || ''; + my $file = $uri->query_param_delete("f") || ''; + my $frag = $uri->fragment || ''; + my $from_rev = $uri->query_param_delete("h") || ''; + my $to_rev = $uri->query_param_delete("hb") || ''; + + if ($frag) { + $frag =~ tr/l/L/; + $frag = "#$frag"; + } + + $to_rev = $from_rev if !$to_rev; + $to_rev = 'master' if $to_rev eq 'HEAD'; + $to_rev =~ s#refs/heads/(.*)$#$1#; + + $repo = 'mozilla-bteam/bmo' if $repo =~ /^webtools\/bmo\/bugzilla\.git$/; + $repo = 'bugzilla/bugzilla' if $repo =~ /^bugzilla\/bugzilla\.git$/; + $repo = 'bugzilla/bugzilla.org' if $repo =~ /^www\/bugzilla\.org\.git$/; + + if ($action eq 'tree') { + return $to_rev eq 'HEAD' + ? qq#$text [github]# + : qq#$text [github]#; + } + if ($action eq 'blob') { + return qq#$text [github]#; + } + if ($action eq 'shortlog' || $action eq 'log') { + return qq#$text [github]#; + } + if ($action eq 'commit' || $action eq 'commitdiff') { + return qq#$text [github]#; + } + return qq#$text#; + } + }); + # link to hg.m.o # Note: for grouping in this regexp, always use non-capturing parentheses. my $hgrepos = join('|', qw!(?:releases/)?comm-[\w.]+ -- cgit v1.2.3-24-g4f1b