diff options
author | Rémy Coutable <remy@rymai.me> | 2016-11-15 23:37:04 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-11-15 23:37:04 +0300 |
commit | 46eb0ebfd277cdbbbe68d008df6d57ef433e9a7d (patch) | |
tree | 4b78b98536a6b13882f4c34cd4cee611bc220770 /spec/requests | |
parent | d5cd0d67f1504d773500fd1605a05ed6c1320cb3 (diff) | |
parent | ff8194e0ec16092419862011d7cc048baa149c42 (diff) |
Merge branch '23584-triggering-builds-from-webhooks' into 'master'
Add ref parameter for triggering builds with gitlab webhook from other project.
Currently GitLab can trigger builds from external tools like curl.
But there is no way to trigger builds with webhook from another GitLab project.
Executing webhook like `/projects/:id/trigger/builds?token=TOKEN&ref=master` results in such message from server:
```
400 No builds created
```
Problem is the ref from request body takes precedence of the ref from query string.
System tries to trigger build for nonexistent branch instead of `master`.
This is the feature of the Grape framework used to build GitLab api.
This MR adds optional `ref` parameter into the api url:
```
/projects/:id/ref/:ref/trigger/builds?token=TOKEN
```
This will lead that the ref in the url will have precedence of the ref inside request body.
This solution provides compatibility with current API urls.
Closes #23584
See merge request !7022
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/triggers_spec.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/spec/requests/api/triggers_spec.rb b/spec/requests/api/triggers_spec.rb index 8ba2eccf66c..c890a51ae42 100644 --- a/spec/requests/api/triggers_spec.rb +++ b/spec/requests/api/triggers_spec.rb @@ -54,6 +54,13 @@ describe API::API do expect(pipeline.builds.size).to eq(5) end + it 'creates builds on webhook from other gitlab repository and branch' do + expect do + post api("/projects/#{project.id}/ref/master/trigger/builds?token=#{trigger_token}"), { ref: 'refs/heads/other-branch' } + end.to change(project.builds, :count).by(5) + expect(response).to have_http_status(201) + end + it 'returns bad request with no builds created if there\'s no commit for that ref' do post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'other-branch') expect(response).to have_http_status(400) |