Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Loading