MCPcopy Index your code
hub / github.com/dagger/dagger / ParseRefString

Function ParseRefString

core/modulerefs.go:56–116  ·  view source on GitHub ↗
(
	ctx context.Context,
	statFS StatFS,
	refString string,
	refPin string,
)

Source from the content-addressed store, hash-verified

54}
55
56func ParseRefString(
57 ctx context.Context,
58 statFS StatFS,
59 refString string,
60 refPin string,
61) (_ *ParsedRefString, rerr error) {
62 ctx, span := Tracer(ctx).Start(ctx, fmt.Sprintf("parseRefString: %s", refString), telemetry.Internal())
63 defer telemetry.EndWithCause(span, &rerr)
64
65 kind := FastModuleSourceKindCheck(refString, refPin)
66 switch kind {
67 case ModuleSourceKindLocal:
68 return &ParsedRefString{
69 Kind: kind,
70 Local: &ParsedLocalRefString{
71 ModPath: refString,
72 },
73 }, nil
74 case ModuleSourceKindGit:
75 parsedGitRef, err := ParseGitRefString(ctx, refString)
76 if err != nil {
77 return nil, fmt.Errorf("failed to parse git ref string: %w", err)
78 }
79 return &ParsedRefString{
80 Kind: kind,
81 Git: &parsedGitRef,
82 }, nil
83 }
84
85 // First, we stat ref in case the mod path github.com/username is a local directory
86 if _, stat, err := statFS.Stat(ctx, refString); err != nil {
87 slog.Debug("parseRefString stat error", "error", err)
88 } else if stat.IsDir() {
89 return &ParsedRefString{
90 Kind: ModuleSourceKindLocal,
91 Local: &ParsedLocalRefString{
92 ModPath: refString,
93 },
94 }, nil
95 }
96
97 // Parse scheme and attempt to parse as git endpoint
98 parsedGitRef, err := ParseGitRefString(ctx, refString)
99 switch {
100 case err == nil:
101 return &ParsedRefString{
102 Kind: ModuleSourceKindGit,
103 Git: &parsedGitRef,
104 }, nil
105 case errors.As(err, &gitEndpointError{}):
106 // couldn't connect to git endpoint, fallback to local
107 return &ParsedRefString{
108 Kind: ModuleSourceKindLocal,
109 Local: &ParsedLocalRefString{
110 ModPath: refString,
111 },
112 }, nil
113 default:

Callers 5

moduleSourceMethod · 0.92
localModuleSourceMethod · 0.92
ResolveDepToSourceFunction · 0.85
TestParseRefStringFunction · 0.85

Calls 8

DebugFunction · 0.92
ParseGitRefStringFunction · 0.85
InternalMethod · 0.80
TracerFunction · 0.70
StartMethod · 0.65
StatMethod · 0.65
IsDirMethod · 0.45

Tested by 1

TestParseRefStringFunction · 0.68