Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add GetReader of Artifact #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ func (a Artifact) GetData(ctx context.Context) ([]byte, error) {
return []byte(data), nil
}

// GetReader Get stream of Artifact
func (a Artifact) GetReader(ctx context.Context) (io.ReadCloser, error) {
response, err := a.Jenkins.Requester.Get(ctx, a.Path, nil, nil)
if err != nil {
response.Body.Close()
return nil, err
}

code := response.StatusCode
if code != 200 {
response.Body.Close()
Error.Printf("Jenkins responded with StatusCode: %d", code)
return nil, errors.New("Could not get File Contents")
}
return response.Body, nil
}

// Save artifact to a specific path, using your own filename.
func (a Artifact) Save(ctx context.Context, path string) (bool, error) {
data, err := a.GetData(ctx)
Expand Down
3 changes: 3 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ func (r *Requester) Do(ctx context.Context, ar *APIRequest, responseStruct inter
if errorText != "" {
return nil, errors.New(errorText)
}
if responseStruct == nil {
return response, nil
}
switch responseStruct.(type) {
case *string:
return r.ReadRawResponse(response, responseStruct)
Expand Down