func smartGithubURI()

in util/util.go [57:100]


func smartGithubURI(uid string) (string, error) {
	u, err := url.Parse(uid)
	if err != nil {
		return "", err
	}

	if u.Scheme != "git" && u.Scheme != "https" {
		return "", fmt.Errorf("invalid scheme")
	}
	u.Scheme = "https" // make it user clickable

	if u.Host != "github.com" {
		return "", fmt.Errorf("wrong hostname")
	}

	q := u.Query()
	sha1s := q["sha1"]
	if len(sha1s) != 1 {
		return "", fmt.Errorf("wrong length of sha1s")
	}
	sha1 := sha1s[0]
	if sha1 == "" {
		return "", fmt.Errorf("unknown sha1")
	}
	u.RawQuery = "" // erase it

	p := strings.TrimPrefix(u.Path, "/")
	ps := strings.Split(p, "/")
	if len(ps) < 2 {
		return "", fmt.Errorf("invalid path")
	}

	u.Path = ps[0] + "/" + ps[1] + "/blob/" + sha1 + "/" + strings.Join(ps[2:], "/")

	u.RawPath = ""       // encoded path hint (see EscapedPath method)
	u.ForceQuery = false // append a query ('?') even if RawQuery is empty

	// TODO: add support for line number ranges, eg: #L13-L42 or just #L42

	u.Fragment = ""    // fragment for references, without '#'
	u.RawFragment = "" // encoded fragment hint (see EscapedFragment method)

	return u.String(), nil
}