MCPcopy Create free account
hub / github.com/easyp-tech/server / getFile

Method getFile

internal/providers/github/getfiles.go:76–129  ·  view source on GitHub ↗
(
	ctx context.Context,
	owner string,
	repoName string,
	commit string,
	path string,
)

Source from the content-addressed store, hash-verified

74}
75
76func (c client) getFile(
77 ctx context.Context,
78 owner string,
79 repoName string,
80 commit string,
81 path string,
82) ([]byte, error) {
83 reqID := connectpkg.RequestIDFrom(ctx)
84
85 start := time.Now()
86 c.log.DebugContext(ctx, "github getFile start",
87 slog.String("owner", owner),
88 slog.String("repo", repoName),
89 slog.String("path", path),
90 slog.String("request_id", reqID),
91 )
92 r, _, err := c.repos.DownloadContents(
93 ctx,
94 owner,
95 repoName,
96 path,
97 &github.RepositoryContentGetOptions{Ref: commit},
98 )
99 dur := time.Since(start)
100 if err != nil {
101 c.log.LogAttrs(ctx, slog.LevelDebug, "github getFile failed",
102 slog.String("owner", owner),
103 slog.String("repo", repoName),
104 slog.String("path", path),
105 slog.String("request_id", reqID),
106 slog.Duration("duration", dur),
107 slog.String("error", err.Error()),
108 )
109 return nil, fmt.Errorf("requesting: %w", err)
110 }
111
112 defer r.Close()
113
114 data, err := io.ReadAll(r)
115 if err != nil {
116 return data, fmt.Errorf("downloading: %w", err)
117 }
118
119 c.log.LogAttrs(ctx, slog.LevelDebug, "github getFile completed",
120 slog.String("owner", owner),
121 slog.String("repo", repoName),
122 slog.String("path", path),
123 slog.String("request_id", reqID),
124 slog.Duration("duration", dur),
125 slog.Int("size", len(data)),
126 )
127
128 return data, nil
129}

Callers 1

getFilesMethod · 0.95

Calls 3

DownloadContentsMethod · 0.80
ErrorMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected