Skip to content

Commit b03c3e7

Browse files
authored
Merge pull request #87 from truszkowski/add-boostMatches-parameter
feat: added boostMatches parameter for GetBranches
2 parents a3031aa + eaa1163 commit b03c3e7

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

default_api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,6 +3503,9 @@ func (a *DefaultApiService) GetBranches(project, repository string, localVarOpti
35033503
if err := typeCheckParameter(localVarOptionals["start"], "int", "start"); err != nil {
35043504
return nil, err
35053505
}
3506+
if err := typeCheckParameter(localVarOptionals["boostMatches"], "bool", "boostMatches"); err != nil {
3507+
return nil, err
3508+
}
35063509

35073510
if localVarTempParam, localVarOk := localVarOptionals["limit"].(int); localVarOk {
35083511
localVarQueryParams.Add("limit", parameterToString(localVarTempParam, ""))
@@ -3522,6 +3525,9 @@ func (a *DefaultApiService) GetBranches(project, repository string, localVarOpti
35223525
if localVarTempParam, localVarOk := localVarOptionals["orderBy"].(string); localVarOk {
35233526
localVarQueryParams.Add("orderBy", parameterToString(localVarTempParam, ""))
35243527
}
3528+
if localVarTempParam, localVarOk := localVarOptionals["boostMatches"].(bool); localVarOk {
3529+
localVarQueryParams.Add("boostMatches", parameterToString(localVarTempParam, ""))
3530+
}
35253531
// to determine the Content-Type header
35263532
localVarHTTPContentTypes := []string{"application/json"}
35273533

default_api_test.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,6 +2388,133 @@ func TestDefaultApiService_GetBranches(t *testing.T) {
23882388
}
23892389
}
23902390

2391+
func TestDefaultApiService_GetBranchesWithBoostMatches(t *testing.T) {
2392+
getBranch := func(res *APIResponse) (branch string) {
2393+
if res.Values == nil {
2394+
return ""
2395+
}
2396+
values, ok := res.Values["values"]
2397+
if !ok {
2398+
return ""
2399+
}
2400+
valuesArray, ok := values.([]interface{})
2401+
if !ok || len(valuesArray) == 0 {
2402+
return ""
2403+
}
2404+
value, ok := valuesArray[0].(map[string]interface{})
2405+
if !ok {
2406+
return ""
2407+
}
2408+
2409+
return value["displayId"].(string)
2410+
}
2411+
2412+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2413+
w.Header().Set("Content-Type", "application/json")
2414+
switch r.RequestURI {
2415+
case "/api/1.0/projects/PROJECT/repos/REPO/branches?boostMatches=true&filterText=foo&orderBy=ALPHABETICAL":
2416+
_, err := io.WriteString(w, `{
2417+
"size": 1,
2418+
"limit": 100,
2419+
"isLastPage": true,
2420+
"values": [
2421+
{
2422+
"id": "refs/heads/foo",
2423+
"displayId": "foo",
2424+
"type": "BRANCH",
2425+
"latestCommit": "8d51122def5632836d1cb1026e879069e10a1e13",
2426+
"latestChangeset": "8d51122def5632836d1cb1026e879069e10a1e13",
2427+
"isDefault": true
2428+
}
2429+
],
2430+
"start": 0
2431+
}`)
2432+
if err != nil {
2433+
t.Errorf("DefaultApiService.GetBranches() error = i/o error %v", err)
2434+
}
2435+
case "/api/1.0/projects/PROJECT/repos/REPO/branches?filterText=foo&orderBy=ALPHABETICAL":
2436+
_, err := io.WriteString(w, `{
2437+
"size": 1,
2438+
"limit": 100,
2439+
"isLastPage": true,
2440+
"values": [
2441+
{
2442+
"id": "refs/heads/_foo_bar",
2443+
"displayId": "_foo_bar",
2444+
"type": "BRANCH",
2445+
"latestCommit": "8d51122def5632836d1cb1026e879069e10a1e13",
2446+
"latestChangeset": "8d51122def5632836d1cb1026e879069e10a1e13",
2447+
"isDefault": true
2448+
}
2449+
],
2450+
"start": 0
2451+
}`)
2452+
if err != nil {
2453+
t.Errorf("DefaultApiService.GetBranches() error = i/o error %v", err)
2454+
}
2455+
default:
2456+
t.Errorf("DefaultApiService.GetBranches() error = unhandled request %s", r.RequestURI)
2457+
}
2458+
}))
2459+
defer ts.Close()
2460+
2461+
client := NewAPIClient(
2462+
context.TODO(),
2463+
NewConfiguration(ts.URL),
2464+
)
2465+
type fields struct {
2466+
client *APIClient
2467+
}
2468+
type args struct {
2469+
project string
2470+
repository string
2471+
localVarOptionals map[string]interface{}
2472+
}
2473+
tests := []struct {
2474+
name string
2475+
fields fields
2476+
args args
2477+
wantBranch string
2478+
wantErr, integrationTest bool
2479+
}{
2480+
{"withBoostMatches", fields{client: client}, args{
2481+
project: "PROJECT", repository: "REPO",
2482+
localVarOptionals: map[string]interface{}{
2483+
"boostMatches": true,
2484+
"filterText": "foo",
2485+
"orderBy": "ALPHABETICAL",
2486+
}}, "foo", false, false},
2487+
{"withoutBoostMatches", fields{client: client}, args{
2488+
project: "PROJECT", repository: "REPO",
2489+
localVarOptionals: map[string]interface{}{
2490+
"filterText": "foo",
2491+
"orderBy": "ALPHABETICAL",
2492+
}}, "_foo_bar", false, false},
2493+
}
2494+
for _, tt := range tests {
2495+
if tt.integrationTest != runIntegrationTests {
2496+
continue
2497+
}
2498+
t.Run(tt.name, func(t *testing.T) {
2499+
a := &DefaultApiService{
2500+
client: tt.fields.client,
2501+
}
2502+
got, err := a.GetBranches(tt.args.project, tt.args.repository, tt.args.localVarOptionals)
2503+
if (err != nil) != tt.wantErr {
2504+
t.Errorf("DefaultApiService.GetBranches() error = %v, wantErr %v", err, tt.wantErr)
2505+
return
2506+
}
2507+
if got != nil {
2508+
got.Response = nil
2509+
}
2510+
gotBranch := getBranch(got)
2511+
if !reflect.DeepEqual(gotBranch, tt.wantBranch) {
2512+
t.Errorf("DefaultApiService.GetBranches() = branch: %v, want branch: %v", gotBranch, tt.wantBranch)
2513+
}
2514+
})
2515+
}
2516+
}
2517+
23912518
func TestDefaultApiService_GetBranchesPagination(t *testing.T) {
23922519
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
23932520
w.Header().Set("Content-Type", "application/json")

0 commit comments

Comments
 (0)