MCPcopy Index your code
hub / github.com/cli/cli / normalizeReference

Function normalizeReference

pkg/cmd/attestation/artifact/artifact.go:30–55  ·  view source on GitHub ↗
(reference string, pathSeparator rune)

Source from the content-addressed store, hash-verified

28}
29
30func normalizeReference(reference string, pathSeparator rune) (normalized string, artifactType artifactType, err error) {
31 switch {
32 case strings.HasPrefix(reference, "oci://"):
33 return reference[6:], ociArtifactType, nil
34 case strings.HasPrefix(reference, "file://"):
35 uri, err := url.ParseRequestURI(reference)
36 if err != nil {
37 return "", 0, fmt.Errorf("failed to parse reference URI: %v", err)
38 }
39 var path string
40 if pathSeparator == '/' {
41 // Unix paths use forward slashes like URIs, so no need to modify
42 path = uri.Path
43 } else {
44 // Windows paths should be normalized to use backslashes
45 path = strings.ReplaceAll(uri.Path, "/", string(pathSeparator))
46 // Remove leading slash from Windows paths if present
47 if strings.HasPrefix(path, string(pathSeparator)) {
48 path = path[1:]
49 }
50 }
51 return filepath.Clean(path), fileArtifactType, nil
52 }
53 // Treat any other reference as a local file path
54 return filepath.Clean(reference), fileArtifactType, nil
55}
56
57func NewDigestedArtifactForRelease(digest string, digestAlg string) (artifact *DigestedArtifact) {
58 return &DigestedArtifact{

Callers 3

TestNormalizeReferenceFunction · 0.85
NewDigestedArtifactFunction · 0.85
TestNormalizeReferenceFunction · 0.85

Calls 2

ErrorfMethod · 0.65
CleanMethod · 0.45

Tested by 2

TestNormalizeReferenceFunction · 0.68
TestNormalizeReferenceFunction · 0.68