Skip to content

Commit 6c50003

Browse files
committed
Merge branch 'prefer-assign_to' into feature/runner-lock-on-project
* prefer-assign_to: Give 409 Conflict whenever the runner was already enabled We're checking return value rather than rescuing exceptions Prefer Runner#assign_to instead of creating directly
2 parents fd285f7 + f74f423 commit 6c50003

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ v 8.9.0 (unreleased)
4040
- Added artifacts:when to .gitlab-ci.yml - this requires GitLab Runner 1.3
4141
- Todos will display target state if issuable target is 'Closed' or 'Merged'
4242
- Fix bug when sorting issues by milestone due date and filtering by two or more labels
43+
- POST to API /projects/:id/runners/:runner_id would give 409 if the runner was already enabled for this project
4344
- Add support for using Yubikeys (U2F) for two-factor authentication
4445
- Link to blank group icon doesn't throw a 404 anymore
4546
- Remove 'main language' feature

app/models/ci/runner.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def set_default_values
6363
def assign_to(project, current_user = nil)
6464
self.is_shared = false if shared?
6565
self.save
66-
project.runner_projects.create!(runner_id: self.id)
66+
project.runner_projects.create(runner_id: self.id).persisted?
6767
end
6868

6969
def display_name

lib/api/runners.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,12 @@ class Runners < Grape::API
9696

9797
runner = get_runner(params[:runner_id])
9898
authenticate_enable_runner!(runner)
99-
Ci::RunnerProject.create(runner: runner, project: user_project)
10099

101-
present runner, with: Entities::Runner
100+
if runner.assign_to(user_project)
101+
present runner, with: Entities::Runner
102+
else
103+
conflict!("Runner was already enabled for this project")
104+
end
102105
end
103106

104107
# Disable project's runner

spec/requests/api/runners_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def update_runner(id, user, args)
379379
expect do
380380
post api("/projects/#{project.id}/runners", user), runner_id: specific_runner.id
381381
end.to change{ project.runners.count }.by(0)
382-
expect(response.status).to eq(201)
382+
expect(response.status).to eq(409)
383383
end
384384

385385
it 'should not enable locked runner' do

0 commit comments

Comments
 (0)