diff options
| author | Joshua Sing <joshua@hypera.dev> | 2023-11-19 02:19:34 +1100 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-02-29 18:41:27 +0000 |
| commit | 38b40c0e2b9e3a62d9a99d62fa70595a5f68e6c9 (patch) | |
| tree | bb7a19b85a177d261ff47a4fc2be127fac53389c /git-codereview/config.go | |
| parent | 0e3f2836ef3e230ced34f5550aa937610e076531 (diff) | |
| download | go-x-review-1.10.0.tar.xz | |
git-codereview: improve haveGerritInternalv1.10.0
Use url.Parse and check URL components rather than performing imprecise
string matching. This addresses a bug where git-codereview does not work
when the Git origin ends with a forward slash.
Note that the check for 'github.com' has been removed since the test for
'.googlesource.com' already excludes it.
Change-Id: I083bccdbacf2152cbfddd2407fb20afa47c8e91e
Reviewed-on: https://go-review.googlesource.com/c/review/+/543495
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Joel Sing <joel@sing.id.au>
Diffstat (limited to 'git-codereview/config.go')
| -rw-r--r-- | git-codereview/config.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/git-codereview/config.go b/git-codereview/config.go index debeb5e..cc9286c 100644 --- a/git-codereview/config.go +++ b/git-codereview/config.go @@ -6,6 +6,7 @@ package main import ( "fmt" + "net/url" "os" "path/filepath" "strings" @@ -59,20 +60,18 @@ func haveGerritInternal(gerrit, origin string) bool { if gerrit != "" { return true } - if strings.Contains(origin, "github.com") { + + u, err := url.Parse(origin) + if err != nil { return false } - if strings.HasPrefix(origin, "sso://") || strings.HasPrefix(origin, "rpc://") { + if u.Scheme == "sso" || u.Scheme == "rpc" { return true } - if !strings.Contains(origin, "https://") { - return false - } - if strings.Count(origin, "/") != 3 { + if u.Scheme != "https" { return false } - host := origin[:strings.LastIndex(origin, "/")] - return strings.HasSuffix(host, ".googlesource.com") + return strings.HasSuffix(u.Host, ".googlesource.com") } func haveGitHub() bool { |
