diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-12-29 12:52:25 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-12-29 13:41:13 +0000 |
| commit | 9fce9e44cb18ac5d0a14e0ca8968b630324ff110 (patch) | |
| tree | f2ed378f9bbed5f36b9568c1b983f2f970326a9d | |
| parent | a3b5ade1a4211009e5cc092cccf94458bc9f2b97 (diff) | |
pkg/vcs: reduce cyclomatic complexity link func
| -rw-r--r-- | pkg/vcs/vcs.go | 110 |
1 files changed, 63 insertions, 47 deletions
diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index b7197a7d6..95167d2e9 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -396,63 +396,79 @@ func link(url, hash, file string, line, typ int) string { return link(url+"/fuchsia", hash, file, line, typ) } if strings.HasPrefix(url, "https://github.com/") { - url = strings.TrimSuffix(url, ".git") - switch typ { - case 1: - return url + "/tree/" + hash - case 2: - return url + "/commits/" + hash - case 3: - return url + "/blob/" + hash + "/" + file + "#L" + fmt.Sprint(line) - default: - return url + "/commit/" + hash - } + return linkGithub(url, hash, file, line, typ) } if strings.HasPrefix(url, "https://git.kernel.org/pub/scm/") || strings.HasPrefix(url, "git://git.kernel.org/pub/scm/") { - url = strings.TrimPrefix(url, "git") - url = strings.TrimPrefix(url, "https") - url = "https" + url - switch typ { - case 1: - return url + "/tree/?id=" + hash - case 2: - return url + "/log/?id=" + hash - case 3: - return url + "/tree/" + file + "?id=" + hash + "#n" + fmt.Sprint(line) - default: - return url + "/commit/?id=" + hash - } + return linkKernelOrg(url, hash, file, line, typ) } for _, cgitHost := range []string{"git.kernel.dk", "git.breakpoint.cc"} { if strings.HasPrefix(url, "https://"+cgitHost) || strings.HasPrefix(url, "git://"+cgitHost) { - url = strings.TrimPrefix(strings.TrimPrefix(url, "git://"), "https://") - url = strings.TrimPrefix(url, cgitHost) - url = "https://" + cgitHost + "/cgit" + url - switch typ { - case 1: - return url + "/tree/?id=" + hash - case 2: - return url + "/log/?id=" + hash - case 3: - return url + "/tree/" + file + "?id=" + hash + "#n" + fmt.Sprint(line) - default: - return url + "/commit/?id=" + hash - } + return linkCgit(cgitHost, url, hash, file, line, typ) } } if strings.HasPrefix(url, "https://") && strings.Contains(url, ".googlesource.com") { - switch typ { - case 1: - return url + "/+/" + hash + "/" - case 2: - return url + "/+log/" + hash - case 3: - return url + "/+/" + hash + "/" + file + "#" + fmt.Sprint(line) - default: - return url + "/+/" + hash + "^!" - } + return linkGoogleSource(url, hash, file, line, typ) } return "" } + +func linkGithub(url, hash, file string, line, typ int) string { + url = strings.TrimSuffix(url, ".git") + switch typ { + case 1: + return url + "/tree/" + hash + case 2: + return url + "/commits/" + hash + case 3: + return url + "/blob/" + hash + "/" + file + "#L" + fmt.Sprint(line) + default: + return url + "/commit/" + hash + } +} + +func linkKernelOrg(url, hash, file string, line, typ int) string { + url = strings.TrimPrefix(url, "git") + url = strings.TrimPrefix(url, "https") + url = "https" + url + switch typ { + case 1: + return url + "/tree/?id=" + hash + case 2: + return url + "/log/?id=" + hash + case 3: + return url + "/tree/" + file + "?id=" + hash + "#n" + fmt.Sprint(line) + default: + return url + "/commit/?id=" + hash + } +} + +func linkCgit(cgitHost, url, hash, file string, line, typ int) string { + url = strings.TrimPrefix(strings.TrimPrefix(url, "git://"), "https://") + url = strings.TrimPrefix(url, cgitHost) + url = "https://" + cgitHost + "/cgit" + url + switch typ { + case 1: + return url + "/tree/?id=" + hash + case 2: + return url + "/log/?id=" + hash + case 3: + return url + "/tree/" + file + "?id=" + hash + "#n" + fmt.Sprint(line) + default: + return url + "/commit/?id=" + hash + } +} + +func linkGoogleSource(url, hash, file string, line, typ int) string { + switch typ { + case 1: + return url + "/+/" + hash + "/" + case 2: + return url + "/+log/" + hash + case 3: + return url + "/+/" + hash + "/" + file + "#" + fmt.Sprint(line) + default: + return url + "/+/" + hash + "^!" + } +} |
