Skip to content

Commit 3fbc8f6

Browse files
committed
Move the PURL's mirror name and qualifiers out of Enumerate
Enumerate went over the cognitive complexity limit after main added the Julia uuid qualifier.
1 parent 76b2f57 commit 3fbc8f6

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

‎internal/mirror/source.go‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,7 @@ func (s *PURLSource) Enumerate(ctx context.Context, fn func(PackageVersion) erro
6868
return fmt.Errorf("parsing PURL %q: %w", purlStr, err)
6969
}
7070

71-
ecosystem := handlerEcosystem(p.Type)
72-
name := p.Name
73-
if ecosystem == "conda" {
74-
name = condaName(p.Namespace, p.Name, p.Qualifier("channel"))
75-
} else if p.Namespace != "" {
76-
name = p.Namespace + "/" + p.Name
77-
}
78-
qualifiers := fileQualifiers(ecosystem, p.Qualifiers.Map())
79-
if ecosystem == "julia" {
80-
qualifiers = map[string]string{"uuid": p.Qualifier("uuid")}
81-
}
71+
ecosystem, name, qualifiers := mirrorTarget(p)
8272

8373
// Images are never expanded to all tags, and conda packages without
8474
// a channel aren't listed; both fail when they are mirrored.
@@ -114,6 +104,23 @@ func (s *PURLSource) Enumerate(ctx context.Context, fn func(PackageVersion) erro
114104
return nil
115105
}
116106

107+
// mirrorTarget returns the ecosystem, name and file qualifiers a PURL is
108+
// mirrored under.
109+
func mirrorTarget(p *purl.PURL) (ecosystem, name string, qualifiers map[string]string) {
110+
ecosystem = handlerEcosystem(p.Type)
111+
name = p.Name
112+
if ecosystem == "conda" {
113+
name = condaName(p.Namespace, p.Name, p.Qualifier("channel"))
114+
} else if p.Namespace != "" {
115+
name = p.Namespace + "/" + p.Name
116+
}
117+
qualifiers = fileQualifiers(ecosystem, p.Qualifiers.Map())
118+
if ecosystem == "julia" {
119+
qualifiers = map[string]string{"uuid": p.Qualifier("uuid")}
120+
}
121+
return ecosystem, name, qualifiers
122+
}
123+
117124
// SBOMSource extracts package versions from CycloneDX or SPDX SBOM data.
118125
type SBOMSource struct {
119126
Data []byte

0 commit comments

Comments
 (0)