func extractGitHubURL()

in cmd/redirector/github.go [27:49]


func extractGitHubURL(u *url.URL) (repoRef, error) {
	var rr gitHubRepoRef
	path := cleanupPath(u.Path)
	parts := strings.SplitN(path, "/", 3)

	if len(parts) < 2 {
		return rr, errors.New("url is not sufficient to infer the repository name")
	}
	rr.user, rr.repo = parts[0], parts[1]

	if len(parts) > 2 {
		subPath := parts[2]
		group := ghSubpages.FindStringSubmatch(subPath)
		if len(group) == 0 {
			return rr, errors.New("only tree/ and blob/ urls on the repositories are supported")
		}
		if group[2] != "" {
			rr.ref = group[2]
		}
		rr.dir = strings.TrimLeft(group[3], "/")
	}
	return rr, nil
}