Bug 1145713 - Add 302 redirects from TBPL to Treeherder/mcMerge
authorEd Morley <emorley@mozilla.com>
Sat, 21 Mar 2015 16:32:16 +0000
changeset 1516 73ad7a52c30e515418b0449c630b5d63e8e4bccf
parent 1515 5507d424a28314232997ede1eada264320752796
child 1517 44054a6338ae01fad01993503a3da94257049d38
push id877
push useremorley@mozilla.com
push dateSat, 21 Mar 2015 17:22:51 +0000
bugs1145713
Bug 1145713 - Add 302 redirects from TBPL to Treeherder/mcMerge * Redirects mcMerge to the new paas instance. * Excludes the cache directory from all rules, so we can still access the revision info / data-import logs. * Returns a 403 forbidden rather than redirecting, for things under php/, so API consumers get a more obvious failure mode. * Redirects common trees to the appropriate URL on Treeherder (for all others, redirects to the Treeherder homepage). * For the common trees, preserves/converts the pusher or revision filter params, but removes any others since they'd require overly complex mapping to their equivalents on Treeherder. * For anything else, just redirect to the Treeherder homepage.
.htaccess
--- a/.htaccess
+++ b/.htaccess
@@ -1,12 +1,102 @@
 # PHP directives set here won't apply when scripts are run from the
 # command line (eg for prefetching), so any PHP directive edits made
 # to this file should likely be made to php/config-cli.php too.
 
+<IfModule mod_rewrite.c>
+  # Redirects for TBPL end of life (bug 1054977).
+  RewriteEngine On
+  RewriteBase /
+
+  # Exclude the cache directory from all other rules, so we can still
+  # view cache/revision_info.txt & the data-import logs.
+  RewriteRule ^cache(/.*)?$ - [L]
+
+  # mcMerge is now on its own hosting, so redirect separately from TBPL:
+  # eg: https://tbpl.mozilla.org/mcmerge/?cset=2a404169de2d&tree=mozilla-central
+  RewriteRule ^mcmerge(/.*)?$ https://mcmerge.paas.allizom.org/ [R=302,L]
+
+  # Redirecting doesn't make sense for calls to TBPL's backend, so let's
+  # return 403 Forbidden, so API consumers hit a more obvious failure mode.
+  RewriteRule ^php(/.*)?$ - [F,L]
+
+  # TBPL used non-standard names for the trees, so we have to convert to the
+  # canonical repo name used by Treeherder/everywhere else. These rules could
+  # be simplified using RewriteMap to just convert many of the repo names to
+  # lowercase (though there are exceptions) but it can't be used inside an
+  # .htaccess, and it's not worth the hassle of having to get WebOps involved.
+  # So we just handle the common trees and let the rest hit the catch-all.
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Mozilla-Inbound(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=mozilla-inbound%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=B2g-Inbound(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=b2g-inbound%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Fx-Team(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=fx-team%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Try(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=try%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Mozilla-Aurora(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=mozilla-aurora%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Mozilla-Beta(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=mozilla-beta%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Mozilla-Release(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=mozilla-release%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Gaia-Try(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=gaia-try%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Thunderbird-Trunk(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=comm-central%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Thunderbird-Try(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=try-comm-central%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Thunderbird-Aurora(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=comm-aurora%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Thunderbird-Beta(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=comm-beta%2
+
+  RewriteCond %{QUERY_STRING} ^(.*)tree=Jetpack(.*)$
+  RewriteRule ^(.*)$ $1?%1repo=addon-sdk%2
+
+  # In addition, Treeherder's query params are different in virtually all cases.
+  # The repo name mappings above have already converted 'tree' to 'repo', but we
+  # still have to handle pusher/rev. Any other params will be discarded for simplicity.
+  # The [NE] flag is required to prevent Apache escaping the '#' to '%23'.
+
+  # Filtered by pusher:
+  # eg: https://tbpl.mozilla.org/?tree=Try&pusher=email@mozilla.com
+  # Any params other than the repo and pusher are discarded.
+  RewriteCond %{QUERY_STRING} repo=([^&]+).*&pusher=([^&]+)
+  RewriteRule ^(.*)$ https://treeherder.mozilla.org/#/jobs?repo=%1&author=%2 [NE,R=302,L]
+
+  # Viewing a specific revision:
+  # eg: https://tbpl.mozilla.org/?tree=Try&rev=cc63db12dafb
+  # Any params other than the repo and revision are discarded.
+  RewriteCond %{QUERY_STRING} repo=([^&]+).*&rev=([^&]+)
+  RewriteRule ^(.*)$ https://treeherder.mozilla.org/#/jobs?repo=%1&revision=%2 [NE,R=302,L]
+
+  # The standard view for a repo:
+  # eg: https://tbpl.mozilla.org/?tree=Mozilla-Inbound
+  # Any params other than the repo are discarded.
+  RewriteCond %{QUERY_STRING} repo=([^&]+)
+  RewriteRule ^(.*)$ https://treeherder.mozilla.org/#/jobs?repo=%1 [NE,R=302,L]
+
+  # For everything else just redirect with the entire query string discarded.
+  RewriteRule ^(.*)$ https://treeherder.mozilla.org/? [R=302,L]
+</IfModule>
+
 <IfModule mod_expires.c>
   ExpiresActive on
   ExpiresDefault "access plus 15 minutes"
 </IfModule>
 
 # Display errors in addition to logging them
 # (disabled in production, change for dev environments)
 php_flag display_startup_errors Off