@@ -110,45 +110,20 @@ func (s *ActionsService) GetArtifact(ctx context.Context, owner, repo string, ar
110110func (s * ActionsService ) DownloadArtifact (ctx context.Context , owner , repo string , artifactID int64 , followRedirects bool ) (* url.URL , * Response , error ) {
111111 u := fmt .Sprintf ("repos/%v/%v/actions/artifacts/%v/zip" , owner , repo , artifactID )
112112
113- resp , err := s .getDownloadArtifactFromURL (ctx , u , followRedirects )
113+ resp , err := s .client . roundTripWithOptionalFollowRedirect (ctx , u , followRedirects )
114114 if err != nil {
115115 return nil , nil , err
116116 }
117+ defer resp .Body .Close ()
117118
118119 if resp .StatusCode != http .StatusFound {
119120 return nil , newResponse (resp ), fmt .Errorf ("unexpected status code: %s" , resp .Status )
120121 }
122+
121123 parsedURL , err := url .Parse (resp .Header .Get ("Location" ))
122124 return parsedURL , newResponse (resp ), nil
123125}
124126
125- func (s * ActionsService ) getDownloadArtifactFromURL (ctx context.Context , u string , followRedirects bool ) (* http.Response , error ) {
126- req , err := s .client .NewRequest ("GET" , u , nil )
127- if err != nil {
128- return nil , err
129- }
130-
131- var resp * http.Response
132- // Use http.DefaultTransport if no custom Transport is configured
133- req = withContext (ctx , req )
134- if s .client .client .Transport == nil {
135- resp , err = http .DefaultTransport .RoundTrip (req )
136- } else {
137- resp , err = s .client .client .Transport .RoundTrip (req )
138- }
139- if err != nil {
140- return nil , err
141- }
142- resp .Body .Close ()
143-
144- // If redirect response is returned, follow it
145- if followRedirects && resp .StatusCode == http .StatusMovedPermanently {
146- u = resp .Header .Get ("Location" )
147- resp , err = s .getDownloadArtifactFromURL (ctx , u , false )
148- }
149- return resp , err
150- }
151-
152127// DeleteArtifact deletes a workflow run artifact.
153128//
154129// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/actions/#delete-an-artifact
0 commit comments