Commit fdf49f97 authored by Markus Freitag's avatar Markus Freitag Committed by Sander van Harmelen

Implement DownloadSingleArtifactsFile (#459)

* Implement DownloadSingleArtifactsFile

* Fix bad variable name

* Fix function docstring

* Make jobID an int var

* Use QueryEscape for consistency

* Dont escape filepath

* Fix typo
parent feb856f4
...@@ -197,6 +197,40 @@ func (s *JobsService) DownloadArtifactsFile(pid interface{}, refName string, job ...@@ -197,6 +197,40 @@ func (s *JobsService) DownloadArtifactsFile(pid interface{}, refName string, job
return artifactsBuf, resp, err return artifactsBuf, resp, err
} }
// DownloadSingleArtifactsFile download a file from the artifacts from the
// given reference name and job provided the job finished successfully.
// Only a single file is going to be extracted from the archive and streamed
// to a client.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/jobs.html#download-a-single-artifact-file
func (s *JobsService) DownloadSingleArtifactsFile(pid interface{}, jobID int, artifactPath string, options ...OptionFunc) (io.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf(
"projects/%s/jobs/%d/artifacts/%s",
url.QueryEscape(project),
jobID,
artifactPath,
)
req, err := s.client.NewRequest("GET", u, nil, options)
if err != nil {
return nil, nil, err
}
artifactBuf := new(bytes.Buffer)
resp, err := s.client.Do(req, artifactBuf)
if err != nil {
return nil, resp, err
}
return artifactBuf, resp, err
}
// GetTraceFile gets a trace of a specific job of a project // GetTraceFile gets a trace of a specific job of a project
// //
// GitLab API docs: // GitLab API docs:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment