godoc/redirect: update the rules for /cl/ redirect

If id is a number greater than 150k, then it is a Rietveld CL, otherwise
treat it as a Gerrit change id.

Also add support for /cl/ID/, because go commit 0edafefc36 uses this
form.

Change-Id: I46575e3284faaa727e346b34bbc46ab248cf12b3
Signed-off-by: Shenghou Ma <minux@golang.org>
Reviewed-on: https://go-review.googlesource.com/1283
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Shenghou Ma 2014-12-09 21:25:00 -05:00 committed by Andrew Gerrand
parent 71d0144635
commit 4d81e11d78

View File

@ -177,17 +177,19 @@ func clHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
id := r.URL.Path[len(prefix):] id := r.URL.Path[len(prefix):]
// support /cl/152700045/, which is used in commit 0edafefc36.
id = strings.TrimSuffix(id, "/")
if !validId.MatchString(id) { if !validId.MatchString(id) {
http.Error(w, "Not found", http.StatusNotFound) http.Error(w, "Not found", http.StatusNotFound)
return return
} }
target := "" target := ""
// the first CL in rietveld is about 152046, so if id is less than // the first CL in rietveld is about 152046, so only treat the id as
// 150000, treat it as a Gerrit change id. // a rietveld CL if it is larger than 150000.
if n, _ := strconv.Atoi(id); strings.HasPrefix(id, "I") || n < 150000 { if n, err := strconv.Atoi(id); err == nil && n > 150000 {
target = "https://go-review.googlesource.com/#/q/" + id
} else {
target = "https://codereview.appspot.com/" + id target = "https://codereview.appspot.com/" + id
} else {
target = "https://go-review.googlesource.com/r/" + id
} }
http.Redirect(w, r, target, http.StatusFound) http.Redirect(w, r, target, http.StatusFound)
} }