diff options
Diffstat (limited to 'lib/api/helpers/runner.rb')
-rw-r--r-- | lib/api/helpers/runner.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb index 1c85669a626..43d841b4d82 100644 --- a/lib/api/helpers/runner.rb +++ b/lib/api/helpers/runner.rb @@ -71,6 +71,26 @@ module API header 'Job-Status', job.status forbidden!(reason) end + + def set_application_context + if current_job + Gitlab::ApplicationContext.push( + user: -> { current_job.user }, + project: -> { current_job.project } + ) + elsif current_runner&.project_type? + Gitlab::ApplicationContext.push( + project: -> do + projects = current_runner.projects.limit(2) # rubocop: disable CodeReuse/ActiveRecord + projects.first if projects.length == 1 + end + ) + elsif current_runner&.group_type? + Gitlab::ApplicationContext.push( + namespace: -> { current_runner.groups.first } + ) + end + end end end end |