Merge branch 'gpocentek/gitlab-ce-api-webhook-token' into 'master'
This MR adds support for the `token` attribute in the project hook API. Feature requested on a dependant project: https://github.com/gpocentek/python-gitlab/issues/170 See merge request !7220
This commit is contained in:
commit
2023511753
|
@ -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 Markdown styling inside reference links (Jan Zdráhal)
|
- Fix Markdown styling inside reference links (Jan Zdráhal)
|
||||||
- Fix extra space on Build sidebar on Firefox !7060
|
- Fix extra space on Build sidebar on Firefox !7060
|
||||||
|
|
|
@ -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; this will not be returned in the response |
|
||||||
|
|
||||||
### Edit project hook
|
### Edit project hook
|
||||||
|
|
||||||
|
@ -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; this will not be returned in the response |
|
||||||
|
|
||||||
### Delete project hook
|
### Delete project hook
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
: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
|
||||||
|
|
|
@ -88,6 +88,7 @@ describe API::API, 'ProjectHooks', api: true do
|
||||||
expect do
|
expect do
|
||||||
post api("/projects/#{project.id}/hooks", user), url: "http://example.com", issues_events: true
|
post api("/projects/#{project.id}/hooks", user), url: "http://example.com", issues_events: true
|
||||||
end.to change {project.hooks.count}.by(1)
|
end.to change {project.hooks.count}.by(1)
|
||||||
|
|
||||||
expect(response).to have_http_status(201)
|
expect(response).to have_http_status(201)
|
||||||
expect(json_response['url']).to eq('http://example.com')
|
expect(json_response['url']).to eq('http://example.com')
|
||||||
expect(json_response['issues_events']).to eq(true)
|
expect(json_response['issues_events']).to eq(true)
|
||||||
|
@ -99,6 +100,24 @@ 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).not_to include('token')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "adds the token without including it in the response" do
|
||||||
|
token = "secret token"
|
||||||
|
|
||||||
|
expect do
|
||||||
|
post api("/projects/#{project.id}/hooks", user), url: "http://example.com", token: token
|
||||||
|
end.to change {project.hooks.count}.by(1)
|
||||||
|
|
||||||
|
expect(response).to have_http_status(201)
|
||||||
|
expect(json_response["url"]).to eq("http://example.com")
|
||||||
|
expect(json_response).not_to include("token")
|
||||||
|
|
||||||
|
hook = project.hooks.find(json_response["id"])
|
||||||
|
|
||||||
|
expect(hook.url).to eq("http://example.com")
|
||||||
|
expect(hook.token).to eq(token)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a 400 error if url not given" do
|
it "returns a 400 error if url not given" do
|
||||||
|
@ -129,6 +148,19 @@ describe API::API, 'ProjectHooks', api: true do
|
||||||
expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification)
|
expect(json_response['enable_ssl_verification']).to eq(hook.enable_ssl_verification)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "adds the token without including it in the response" do
|
||||||
|
token = "secret token"
|
||||||
|
|
||||||
|
put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: "http://example.org", token: token
|
||||||
|
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
expect(json_response["url"]).to eq("http://example.org")
|
||||||
|
expect(json_response).not_to include("token")
|
||||||
|
|
||||||
|
expect(hook.reload.url).to eq("http://example.org")
|
||||||
|
expect(hook.reload.token).to eq(token)
|
||||||
|
end
|
||||||
|
|
||||||
it "returns 404 error if hook id not found" do
|
it "returns 404 error if hook id not found" do
|
||||||
put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org'
|
put api("/projects/#{project.id}/hooks/1234", user), url: 'http://example.org'
|
||||||
expect(response).to have_http_status(404)
|
expect(response).to have_http_status(404)
|
||||||
|
|
Loading…
Reference in New Issue