Fix gerrit credential for cts roller in tools If there are multiple entries in .gitcookies, cts roller always use the first matching entry as gerrit credential which may be expired. Change to use the last matching entry instead, because the latest gerrit credential is always appended to .gitcookies. Bug: dawn:1742 Change-Id: I1c947af50fd042b6f36c405f23637de445269990 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/143560 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/tools/src/gerrit/gerrit.go b/tools/src/gerrit/gerrit.go index 2b333b1..f3641eb 100644 --- a/tools/src/gerrit/gerrit.go +++ b/tools/src/gerrit/gerrit.go
@@ -95,9 +95,12 @@ if cookies, err := ioutil.ReadFile(cookiesFile); err == nil { url := strings.TrimSuffix(strings.TrimPrefix(url, "https://"), "/") re := regexp.MustCompile(url + `/?\s+(?:FALSE|TRUE)[\s/]+(?:FALSE|TRUE)\s+[0-9]+\s+.\s+(.*)=(.*)`) - match := re.FindStringSubmatch(string(cookies)) - if len(match) == 3 { - return Credentials{match[1], match[2]} + matches := re.FindAllStringSubmatch(string(cookies), -1) + if matches != nil { + match := matches[len(matches)-1] + if len(match) == 3 { + return Credentials{match[1], match[2]} + } } } return Credentials{}