Skip to content

Commit 154d679

Browse files
jimmykarilydmgarland
authored andcommitted
Add Content-Type: "application/json" on webhooks POST requests
As described on the Bitbucket documentation this is the way to go when there are nested objects. https://confluence.atlassian.com/display/bitbucket/version+2#Version2-Supportedcontenttypes Add Content-Type: "application/json" header to keys endpoint too
1 parent 241485d commit 154d679

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

lib/bitbucket_rest_api/repos.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Repos < API
1616
:Download => 'download',
1717
:Webhooks => 'webhooks',
1818
:PullRequest => 'pull_request',
19-
:DefaultReviewers => 'default_reviewers'
19+
:DefaultReviewers => 'default_reviewers',
2020
:Components => 'components'
2121

2222
DEFAULT_REPO_OPTIONS = {
@@ -93,6 +93,10 @@ def components
9393
@components ||= ApiFactory.new 'Repos::Components'
9494
end
9595

96+
def webhooks
97+
@webhooks ||= ApiFactory.new 'Repos::Webhooks'
98+
end
99+
96100
# List branches
97101
#
98102
# = Examples

lib/bitbucket_rest_api/repos/keys.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def create(user_name, repo_name, params={})
4242
filter! VALID_KEY_PARAM_NAMES, params
4343
assert_required_keys(VALID_KEY_PARAM_NAMES, params)
4444

45-
post_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params)
45+
options = { headers: { "Content-Type" => "application/json" } }
46+
post_request("/1.0/repositories/#{user}/#{repo.downcase}/deploy-keys/", params, options)
4647
end
4748

4849
# Edit a key

lib/bitbucket_rest_api/repos/webhooks.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def create(user_name, repo_name, params = {})
3434
'events'
3535
)
3636

37-
post_request("/2.0/repositories/#{user_name}/#{repo_name}/hooks", params)
37+
38+
options = { headers: { "Content-Type" => "application/json" } }
39+
post_request("/2.0/repositories/#{user_name}/#{repo_name}/hooks", params, options)
3840
end
3941

4042
def list(user_name, repo_name)
@@ -67,10 +69,11 @@ def edit(user_name, repo_name, hook_uuid, params = {})
6769
'events'
6870
)
6971

72+
73+
options = { headers: { "Content-Type" => "application/json" } }
7074
put_request(
7175
"/2.0/repositories/#{user_name}/#{repo_name}/hooks/#{hook_uuid}",
72-
params
73-
)
76+
params, options)
7477
end
7578

7679
def delete(user_name, repo_name, hook_uuid)

spec/bitbucket_rest_api/repos/keys_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
:post,
3232
'/1.0/repositories/mock_username/mock_repo/deploy-keys/',
3333
{ 'key' => 'mock_ssh_key', 'label' => 'mock_label' },
34-
{}
34+
{ headers: {"Content-Type"=>"application/json"} }
3535
)
3636
end
3737

spec/bitbucket_rest_api/repos/webhooks_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
:post,
113113
'/2.0/repositories/mock_username/mock_repo/hooks',
114114
post_put_params,
115-
{}
115+
{ headers: { "Content-Type" => "application/json" } }
116116
)
117117

118118
subject.create(
@@ -218,7 +218,7 @@
218218
:put,
219219
'/2.0/repositories/mock_username/mock_repo/hooks/mock_uuid',
220220
post_put_params,
221-
{}
221+
{ headers: { "Content-Type" => "application/json" } }
222222
)
223223

224224
subject.edit(

0 commit comments

Comments
 (0)