Skip to content

Commit 5273250

Browse files
authored
Merge pull request #61 from tomcruise81/bugfix/hook-bodies
Option to include request body for enabling hooks
2 parents 412cc33 + 1713871 commit 5273250

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

default_api.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (a *DefaultApiService) AddUserToGroups(name string, groups []string) (*APIR
137137
)
138138

139139
localVarPostBody = map[string]interface{}{
140-
"user": name,
140+
"user": name,
141141
"groups": groups,
142142
}
143143

@@ -2394,17 +2394,24 @@ func (a *DefaultApiService) EnableHook(projectKey, repositorySlug, hookKey strin
23942394
@param "contentLength" (int32)
23952395
@return */
23962396
func (a *DefaultApiService) EnableHook_4(projectKey, repositorySlug, hookKey string, localVarOptionals map[string]interface{}) (*APIResponse, error) {
2397+
return a.EnableHook_4_WithOptions(projectKey, hookKey, localVarOptionals, nil)
2398+
}
2399+
2400+
/* DefaultApiService
2401+
For certain hooks (like "com.atlassian.bitbucket.server.bitbucket-bundled-hooks:requiredApproversMergeHook"), a request body with "requiredCount" and an integer value is necessary.
2402+
2403+
@param localVarPostBody (nil or map[string]interface{})
2404+
@return */
2405+
func (a *DefaultApiService) EnableHook_4_WithOptions(projectKey, hookKey string, localVarOptionals map[string]interface{}, localVarPostBody interface{}) (*APIResponse, error) {
23972406
var (
23982407
localVarHTTPMethod = strings.ToUpper("Put")
2399-
localVarPostBody interface{}
24002408
localVarFileName string
24012409
localVarFileBytes []byte
24022410
)
24032411

24042412
// create path and map variables
24052413
localVarPath := a.client.cfg.BasePath + "/api/1.0/projects/{projectKey}/settings/hooks/{hookKey}/enabled"
24062414
localVarPath = strings.Replace(localVarPath, "{"+"projectKey"+"}", fmt.Sprintf("%v", projectKey), -1)
2407-
localVarPath = strings.Replace(localVarPath, "{"+"repositorySlug"+"}", fmt.Sprintf("%v", repositorySlug), -1)
24082415
localVarPath = strings.Replace(localVarPath, "{"+"hookKey"+"}", fmt.Sprintf("%v", hookKey), -1)
24092416

24102417
localVarHeaderParams := make(map[string]string)
@@ -2435,6 +2442,7 @@ func (a *DefaultApiService) EnableHook_4(projectKey, repositorySlug, hookKey str
24352442
if localVarTempParam, localVarOk := localVarOptionals["contentLength"].(int32); localVarOk {
24362443
localVarHeaderParams["Content-Length"] = parameterToString(localVarTempParam, "")
24372444
}
2445+
24382446
r, err := a.client.prepareRequest(a.client.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
24392447
if err != nil {
24402448
return nil, err

default_api_test.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestDefaultApiService_AddUserToGroups(t *testing.T) {
124124
client *APIClient
125125
}
126126
type args struct {
127-
name string
127+
name string
128128
groups []string
129129
}
130130
tests := []struct {
@@ -1849,6 +1849,45 @@ func TestDefaultApiService_EnableHook_4(t *testing.T) {
18491849
}
18501850
}
18511851

1852+
func TestDefaultApiService_EnableHook_4_WithOptions(t *testing.T) {
1853+
type fields struct {
1854+
client *APIClient
1855+
}
1856+
type args struct {
1857+
projectKey string
1858+
hookKey string
1859+
localVarOptionals map[string]interface{}
1860+
localVarPostBody map[string]interface{}
1861+
}
1862+
tests := []struct {
1863+
name string
1864+
fields fields
1865+
args args
1866+
want *APIResponse
1867+
wantErr, integrationTest bool
1868+
}{
1869+
{"networkErrorContextExceeded", fields{client: generateConfigFake()}, args{}, &APIResponse{Message: "Put https://stash.domain.com/rest/api/1.0/projects//settings/hooks//enabled: context canceled"}, true, false},
1870+
}
1871+
for _, tt := range tests {
1872+
if tt.integrationTest != runIntegrationTests {
1873+
continue
1874+
}
1875+
t.Run(tt.name, func(t *testing.T) {
1876+
a := &DefaultApiService{
1877+
client: tt.fields.client,
1878+
}
1879+
got, err := a.EnableHook_4_WithOptions(tt.args.projectKey, tt.args.hookKey, tt.args.localVarOptionals, tt.args.localVarPostBody)
1880+
if (err != nil) != tt.wantErr {
1881+
t.Errorf("DefaultApiService.EnableHook_4_WithOptions() error = %v, wantErr %v", err, tt.wantErr)
1882+
return
1883+
}
1884+
if !reflect.DeepEqual(got, tt.want) {
1885+
t.Errorf("DefaultApiService.EnableHook_4_WithOptions() = %v, want %v", got, tt.want)
1886+
}
1887+
})
1888+
}
1889+
}
1890+
18521891
func TestDefaultApiService_FindGroupsForUser(t *testing.T) {
18531892
type fields struct {
18541893
client *APIClient

0 commit comments

Comments
 (0)