@@ -191,21 +191,30 @@ func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owne
191191 if err == nil && content != "" {
192192 return io .NopCloser (strings .NewReader (content )), fileContent , resp , nil
193193 }
194+ }
194195
195- if fileContent .DownloadURL == nil || * fileContent .DownloadURL == "" {
196- return nil , fileContent , resp , fmt .Errorf ("no download link found for %s" , filepath )
197- }
196+ _ , dirContents , resp , err := s .GetContents (ctx , owner , repo , dir , opts )
197+ if err != nil {
198+ return nil , nil , resp , err
199+ }
198200
199- dlReq , err := http .NewRequestWithContext (ctx , http .MethodGet , * fileContent .DownloadURL , nil )
200- if err != nil {
201- return nil , fileContent , resp , err
202- }
203- dlResp , err := s .client .client .Do (dlReq )
204- if err != nil {
205- return nil , fileContent , & Response {Response : dlResp }, err
206- }
201+ for _ , contents := range dirContents {
202+ if contents .GetName () == filename {
203+ if contents .GetDownloadURL () == "" {
204+ return nil , contents , resp , fmt .Errorf ("no download link found for %s" , filepath )
205+ }
207206
208- return dlResp .Body , fileContent , & Response {Response : dlResp }, nil
207+ dlReq , err := http .NewRequestWithContext (ctx , http .MethodGet , * contents .DownloadURL , nil )
208+ if err != nil {
209+ return nil , contents , resp , err
210+ }
211+ dlResp , err := s .client .client .Do (dlReq )
212+ if err != nil {
213+ return nil , contents , & Response {Response : dlResp }, err
214+ }
215+
216+ return dlResp .Body , contents , & Response {Response : dlResp }, nil
217+ }
209218 }
210219
211220 return nil , nil , resp , fmt .Errorf ("no file named %s found in %s" , filename , dir )
0 commit comments