diff --git a/main.go b/main.go index d0e8d6a..9153220 100644 --- a/main.go +++ b/main.go @@ -100,19 +100,9 @@ func (c *credential) match(req *credential) bool { } if req.path != "" { - // get username or org from repo path like `username-or-org/reponame.git` - reqOrg, _, hasSep := strings.Cut(req.path, "/") - if hasSep && reqOrg != "" { - matchReqPath := strings.TrimRight(reqOrg, "/") - matchConfigPath := strings.TrimRight(c.path, "/") - match = match && matchReqPath == matchConfigPath - log.Printf("match path by username or org: req.path=%v,config.path=%v,result=%v", - matchReqPath, matchConfigPath, match) - } else { - match = match && c.path == req.path - log.Printf("match path: req.path=%v,other.path=%v,result=%v", - c.path, req.path, match) - } + match = match && strings.HasPrefix(req.path, c.path) + log.Printf("match path by username or org: req.path=%v,config.path=%v,result=%v", + req.path, c.path, match) } return match } @@ -234,11 +224,18 @@ func getCredential(req *credential, credFile string) *credential { scanner := bufio.NewScanner(file) for scanner.Scan() { line := scanner.Text() + + if strings.HasPrefix(strings.TrimSpace(line), "#") || strings.HasPrefix(strings.TrimSpace(line), "//") { + log.Printf("ignore comment : %s", line) + continue + } + cred := parseCredential(line) if cred == nil { log.Printf("err malformed credential line: %s", line) continue } + if cred.match(req) { return cred }