mirror of
https://github.com/gfleury/go-bitbucket-v1.git
synced 2025-04-17 22:28:05 -05:00
Merge pull request #31 from ribaptista/master
Fixing raw file fetch method
This commit is contained in:
commit
2ed584f5d5
@ -5,6 +5,7 @@
|
|||||||
package bitbucketv1
|
package bitbucketv1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@ -365,3 +366,14 @@ func NewBitbucketAPIResponse(r *http.Response) (*APIResponse, error) {
|
|||||||
}
|
}
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewRawAPIResponse(r *http.Response) (*APIResponse, error) {
|
||||||
|
response := &APIResponse{Response: r}
|
||||||
|
raw, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Payload = raw
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
@ -4133,7 +4133,7 @@ func (a *DefaultApiService) GetContent_10(localVarOptionals map[string]interface
|
|||||||
@param "hardwrap" (bool) (Optional) Whether the markup implementation should convert newlines to breaks. If not specified, {@link MarkupService} will use the value of the <code>markup.render.hardwrap</code> property, which is <code>true</code> by default
|
@param "hardwrap" (bool) (Optional) Whether the markup implementation should convert newlines to breaks. If not specified, {@link MarkupService} will use the value of the <code>markup.render.hardwrap</code> property, which is <code>true</code> by default
|
||||||
@param "htmlEscape" (bool) (Optional) true if HTML should be escaped in the input markup, false otherwise. If not specified, {@link MarkupService} will use the value of the <code>markup.render.html.escape</code> property, which is <code>true</code> by default
|
@param "htmlEscape" (bool) (Optional) true if HTML should be escaped in the input markup, false otherwise. If not specified, {@link MarkupService} will use the value of the <code>markup.render.html.escape</code> property, which is <code>true</code> by default
|
||||||
@return */
|
@return */
|
||||||
func (a *DefaultApiService) GetContent_11(path string, localVarOptionals map[string]interface{}) (*APIResponse, error) {
|
func (a *DefaultApiService) GetContent_11(projectKey, repositorySlug, path string, localVarOptionals map[string]interface{}) (*APIResponse, error) {
|
||||||
var (
|
var (
|
||||||
localVarHTTPMethod = strings.ToUpper("Get")
|
localVarHTTPMethod = strings.ToUpper("Get")
|
||||||
localVarPostBody interface{}
|
localVarPostBody interface{}
|
||||||
@ -4144,6 +4144,8 @@ func (a *DefaultApiService) GetContent_11(path string, localVarOptionals map[str
|
|||||||
// create path and map variables
|
// create path and map variables
|
||||||
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/raw/{path}"
|
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/repos/{repositorySlug}/raw/{path}"
|
||||||
localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", fmt.Sprintf("%v", path), -1)
|
localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", fmt.Sprintf("%v", path), -1)
|
||||||
|
localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
|
||||||
|
localVarPath = strings.Replace(localVarPath, "{"+"repositorySlug"+"}", fmt.Sprintf("%v", repositorySlug), -1)
|
||||||
|
|
||||||
localVarHeaderParams := make(map[string]string)
|
localVarHeaderParams := make(map[string]string)
|
||||||
localVarQueryParams := url.Values{}
|
localVarQueryParams := url.Values{}
|
||||||
@ -4206,7 +4208,7 @@ func (a *DefaultApiService) GetContent_11(path string, localVarOptionals map[str
|
|||||||
return NewAPIResponseWithError(localVarHTTPResponse, reportError("Status: %v, Body: %s", localVarHTTPResponse.Status, bodyBytes))
|
return NewAPIResponseWithError(localVarHTTPResponse, reportError("Status: %v, Body: %s", localVarHTTPResponse.Status, bodyBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewBitbucketAPIResponse(localVarHTTPResponse)
|
return NewRawAPIResponse(localVarHTTPResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DefaultApiService
|
/* DefaultApiService
|
||||||
|
@ -2226,6 +2226,8 @@ func TestDefaultApiService_GetContent_11(t *testing.T) {
|
|||||||
client *APIClient
|
client *APIClient
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
|
projectKey string
|
||||||
|
repositorySlug string
|
||||||
path string
|
path string
|
||||||
localVarOptionals map[string]interface{}
|
localVarOptionals map[string]interface{}
|
||||||
}
|
}
|
||||||
@ -2236,14 +2238,14 @@ func TestDefaultApiService_GetContent_11(t *testing.T) {
|
|||||||
want *APIResponse
|
want *APIResponse
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Get https://stash.domain.com/rest/api/1.0/projects/%7BprojectKey%7D/repos/%7BrepositorySlug%7D/raw/: context canceled"}, true},
|
{"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Get https://stash.domain.com/rest/api/1.0/projects//repos//raw/: context canceled"}, true},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
a := &DefaultApiService{
|
a := &DefaultApiService{
|
||||||
client: tt.fields.client,
|
client: tt.fields.client,
|
||||||
}
|
}
|
||||||
got, err := a.GetContent_11(tt.args.path, tt.args.localVarOptionals)
|
got, err := a.GetContent_11(tt.args.projectKey, tt.args.repositorySlug, tt.args.path, tt.args.localVarOptionals)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("DefaultApiService.GetContent_11() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("DefaultApiService.GetContent_11() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user