Commit c85c146a authored by Gauvain Pocentek's avatar Gauvain Pocentek Committed by Sean McGivern

Add support for token attr in project hooks API

The UI allows to define a token to validate payload on the target URL,
this patch adds the feature to the API.
parent 266fcfb1
...@@ -6,6 +6,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -6,6 +6,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Adds user project membership expired event to clarify why user was removed (Callum Dryden) - Adds user project membership expired event to clarify why user was removed (Callum Dryden)
- Trim leading and trailing whitespace on project_path (Linus Thiel) - Trim leading and trailing whitespace on project_path (Linus Thiel)
- Prevent award emoji via notes for issues/MRs authored by user (barthc) - Prevent award emoji via notes for issues/MRs authored by user (barthc)
- Adds support for the `token` attribute in project hooks API (Gauvain Pocentek)
- Adds an optional path parameter to the Commits API to filter commits by path (Luis HGO) - Adds an optional path parameter to the Commits API to filter commits by path (Luis HGO)
- Fix extra space on Build sidebar on Firefox !7060 - Fix extra space on Build sidebar on Firefox !7060
- Fix mobile layout issues in admin user overview page !7087 - Fix mobile layout issues in admin user overview page !7087
......
...@@ -1139,6 +1139,7 @@ Parameters: ...@@ -1139,6 +1139,7 @@ Parameters:
| `pipeline_events` | boolean | no | Trigger hook on pipeline events | | `pipeline_events` | boolean | no | Trigger hook on pipeline events |
| `wiki_events` | boolean | no | Trigger hook on wiki events | | `wiki_events` | boolean | no | Trigger hook on wiki events |
| `enable_ssl_verification` | boolean | no | Do SSL verification when triggering the hook | | `enable_ssl_verification` | boolean | no | Do SSL verification when triggering the hook |
| `token` | string | no | Secret token to validate received payloads |
### Edit project hook ### Edit project hook
...@@ -1164,6 +1165,7 @@ Parameters: ...@@ -1164,6 +1165,7 @@ Parameters:
| `pipeline_events` | boolean | no | Trigger hook on pipeline events | | `pipeline_events` | boolean | no | Trigger hook on pipeline events |
| `wiki_events` | boolean | no | Trigger hook on wiki events | | `wiki_events` | boolean | no | Trigger hook on wiki events |
| `enable_ssl_verification` | boolean | no | Do SSL verification when triggering the hook | | `enable_ssl_verification` | boolean | no | Do SSL verification when triggering the hook |
| `token` | string | no | Secret token to validate received payloads |
### Delete project hook ### Delete project hook
......
...@@ -50,7 +50,7 @@ module API ...@@ -50,7 +50,7 @@ module API
expose :project_id, :push_events expose :project_id, :push_events
expose :issues_events, :merge_requests_events, :tag_push_events expose :issues_events, :merge_requests_events, :tag_push_events
expose :note_events, :build_events, :pipeline_events, :wiki_page_events expose :note_events, :build_events, :pipeline_events, :wiki_page_events
expose :enable_ssl_verification expose :enable_ssl_verification, :token
end end
class BasicProjectDetails < Grape::Entity class BasicProjectDetails < Grape::Entity
......
...@@ -47,7 +47,8 @@ module API ...@@ -47,7 +47,8 @@ module API
:build_events, :build_events,
:pipeline_events, :pipeline_events,
:wiki_page_events, :wiki_page_events,
:enable_ssl_verification :enable_ssl_verification,
:token
] ]
@hook = user_project.hooks.new(attrs) @hook = user_project.hooks.new(attrs)
...@@ -82,7 +83,8 @@ module API ...@@ -82,7 +83,8 @@ module API
:build_events, :build_events,
:pipeline_events, :pipeline_events,
:wiki_page_events, :wiki_page_events,
:enable_ssl_verification :enable_ssl_verification,
:token
] ]
if @hook.update_attributes attrs if @hook.update_attributes attrs
......
...@@ -36,6 +36,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -36,6 +36,7 @@ describe API::API, 'ProjectHooks', api: true do
expect(json_response.first['pipeline_events']).to eq(true) expect(json_response.first['pipeline_events']).to eq(true)
expect(json_response.first['wiki_page_events']).to eq(true) expect(json_response.first['wiki_page_events']).to eq(true)
expect(json_response.first['enable_ssl_verification']).to eq(true) expect(json_response.first['enable_ssl_verification']).to eq(true)
expect(json_response.first['token']).to eq('S3cr3t')
end end
end end
...@@ -62,6 +63,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -62,6 +63,7 @@ describe API::API, 'ProjectHooks', api: true do
expect(json_response['pipeline_events']).to eq(hook.pipeline_events) expect(json_response['pipeline_events']).to eq(hook.pipeline_events)
expect(json_response['wiki_page_events']).to eq(hook.wiki_page_events) expect(json_response['wiki_page_events']).to eq(hook.wiki_page_events)
expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification) expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification)
expect(json_response['token']).to eq(hook.token)
end end
it "returns a 404 error if hook id is not available" do it "returns a 404 error if hook id is not available" do
...@@ -99,6 +101,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -99,6 +101,7 @@ describe API::API, 'ProjectHooks', api: true do
expect(json_response['pipeline_events']).to eq(false) expect(json_response['pipeline_events']).to eq(false)
expect(json_response['wiki_page_events']).to eq(false) expect(json_response['wiki_page_events']).to eq(false)
expect(json_response['enable_ssl_verification']).to eq(true) expect(json_response['enable_ssl_verification']).to eq(true)
expect(json_response['token']).to eq('S3cr3t')
end end
it "returns a 400 error if url not given" do it "returns a 400 error if url not given" do
...@@ -127,6 +130,7 @@ describe API::API, 'ProjectHooks', api: true do ...@@ -127,6 +130,7 @@ describe API::API, 'ProjectHooks', api: true do
expect(json_response['pipeline_events']).to eq(hook.pipeline_events) expect(json_response['pipeline_events']).to eq(hook.pipeline_events)
expect(json_response['wiki_page_events']).to eq(hook.wiki_page_events) expect(json_response['wiki_page_events']).to eq(hook.wiki_page_events)
expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification) expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification)
expect(json_response['token']).to eq(hook.token)
end end
it "returns 404 error if hook id not found" do it "returns 404 error if hook id not found" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment