1// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5var numericRE = /^\d+$/;
6var commitRE = /^(?:\d+:)?([0-9a-f]{6,40})$/; // e.g "8486:ab29d2698a47" or "ab29d2698a47"
7var gerritChangeIdRE = /^I[0-9a-f]{4,40}$/; // e.g. Id69c00d908d18151486007ec03da5495b34b05f5
8var pkgRE = /^[a-z0-9_\/]+$/;
9
10function urlForInput(t) {
11    if (!t) {
12        return null;
13    }
14
15    if (numericRE.test(t)) {
16        if (t < 150000) {
17            // We could use the golang.org/cl/ handler here, but
18            // avoid some redirect latency and go right there, since
19            // one is easy. (no server-side mapping)
20            return "https://github.com/golang/go/issues/" + t;
21        }
22        return "https://golang.org/cl/" + t;
23    }
24
25    if (gerritChangeIdRE.test(t)) {
26        return "https://golang.org/cl/" + t;
27    }
28
29    var match = commitRE.exec(t);
30    if (match) {
31        return "https://golang.org/change/" + match[1];
32    }
33
34    if (pkgRE.test(t)) {
35        // TODO: make this smarter, using a list of packages + substring matches.
36        // Get the list from godoc itself in JSON format?
37        return "https://golang.org/pkg/" + t;
38    }
39
40    return null;
41}
42