MCPcopy Index your code
hub / github.com/google/go-github / DownloadContentsWithMeta

Method DownloadContentsWithMeta

github/repos_contents.go:171–206  ·  view source on GitHub ↗

DownloadContentsWithMeta is identical to DownloadContents but additionally returns the RepositoryContent of the requested file. This additional data is useful for future operations involving the requested file. For merely reading the content of a file, DownloadContents is perfectly adequate. It is

(ctx context.Context, owner, repo, filepath string, opts *RepositoryContentGetOptions)

Source from the content-addressed store, hash-verified

169//
170//meta:operation GET /repos/{owner}/{repo}/contents/{path}
171func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owner, repo, filepath string, opts *RepositoryContentGetOptions) (io.ReadCloser, *RepositoryContent, *Response, error) {
172 fileContent, _, resp, err := s.GetContents(ctx, owner, repo, filepath, opts)
173 if err != nil {
174 return nil, nil, resp, err
175 }
176
177 if fileContent == nil {
178 return nil, nil, resp, ErrContentsDirectory
179 }
180
181 if fileContent.GetType() == "submodule" {
182 return nil, fileContent, resp, ErrContentsSubmodule
183 }
184
185 content, err := fileContent.GetContent()
186 if err == nil && content != "" {
187 return io.NopCloser(strings.NewReader(content)), fileContent, resp, nil
188 }
189
190 downloadURL := fileContent.GetDownloadURL()
191 if downloadURL == "" {
192 return nil, fileContent, resp, ErrContentsNoDownloadURL
193 }
194
195 dlReq, err := http.NewRequestWithContext(ctx, "GET", downloadURL, nil)
196 if err != nil {
197 return nil, fileContent, resp, err
198 }
199
200 dlResp, err := s.client.client.Do(dlReq)
201 if err != nil {
202 return nil, fileContent, &Response{Response: dlResp}, err
203 }
204
205 return dlResp.Body, fileContent, &Response{Response: dlResp}, nil
206}
207
208// GetContents can return either the metadata and content of a single file
209// (when path references a file) or the metadata of all the files and/or

Calls 5

GetContentsMethod · 0.95
GetTypeMethod · 0.45
GetContentMethod · 0.45
GetDownloadURLMethod · 0.45
DoMethod · 0.45