summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSteve Azzopardi <steveazz@outlook.com>2018-09-04 09:51:00 +0200
committerSteve Azzopardi <steveazz@outlook.com>2018-09-12 11:00:39 +0200
commit1b388c798b01d950ad8692e34938a2a457c6ad0f (patch)
tree96471170bf1da744b6c043212a78c09df768a17d /app
parentf87809f78de9da04f38134ba5ce0cf9ddebf2f63 (diff)
downloadgitlab-ce-1b388c798b01d950ad8692e34938a2a457c6ad0f.tar.gz
Add trigger information for job API
Create new entity called TriggerVariablesEnitity for trigger variables, to aid reuseablity in the future. Update JSON schema to include trigger information in the response. Refactor rspec tests a bit to reduce duplication and for the `context` to make sense. closes https://gitlab.com/gitlab-org/gitlab-ce/issues/50989
Diffstat (limited to 'app')
-rw-r--r--app/models/ci/build.rb1
-rw-r--r--app/models/ci/trigger_request.rb2
-rw-r--r--app/serializers/build_details_entity.rb6
-rw-r--r--app/serializers/trigger_variable_entity.rb7
4 files changed, 16 insertions, 0 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index faa160ad6ba..cc1408cb397 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -40,6 +40,7 @@ module Ci
delegate :url, to: :runner_session, prefix: true, allow_nil: true
delegate :terminal_specification, to: :runner_session, allow_nil: true
delegate :gitlab_deploy_token, to: :project
+ delegate :trigger_short_token, to: :trigger_request, allow_nil: true
##
# The "environment" field for builds is a String, and is the unexpanded name!
diff --git a/app/models/ci/trigger_request.rb b/app/models/ci/trigger_request.rb
index 913936a0bcb..0b52c690e93 100644
--- a/app/models/ci/trigger_request.rb
+++ b/app/models/ci/trigger_request.rb
@@ -8,6 +8,8 @@ module Ci
belongs_to :pipeline, foreign_key: :commit_id
has_many :builds
+ delegate :short_token, to: :trigger, prefix: true, allow_nil: true
+
# We switched to Ci::PipelineVariable from Ci::TriggerRequest.variables.
# Ci::TriggerRequest doesn't save variables anymore.
validates :variables, absence: true
diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb
index b107fc26f18..6f8194d9856 100644
--- a/app/serializers/build_details_entity.rb
+++ b/app/serializers/build_details_entity.rb
@@ -59,6 +59,12 @@ class BuildDetailsEntity < JobEntity
raw_project_job_path(project, build)
end
+ expose :trigger, if: -> (*) { build.trigger_request } do
+ expose :trigger_short_token, as: :short_token
+
+ expose :trigger_variables, as: :variables, using: TriggerVariableEntity
+ end
+
private
def build_failed_issue_options
diff --git a/app/serializers/trigger_variable_entity.rb b/app/serializers/trigger_variable_entity.rb
new file mode 100644
index 00000000000..56203113631
--- /dev/null
+++ b/app/serializers/trigger_variable_entity.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class TriggerVariableEntity < Grape::Entity
+ include RequestAwareEntity
+
+ expose :key, :value, :public
+end