summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-04-26 17:42:59 +0100
committerFilipa Lacerda <filipa@gitlab.com>2017-04-26 17:42:59 +0100
commitbf05a7c6cbac0242fa661299cb0e3bc011adbf6e (patch)
tree573f782e7acf8e4eaea9391eaf3347d5a403bdf4
parentdc853cc1b0a1f2d7f1e1f45a36932a129920d865 (diff)
parent47eb3bb478f835d739884883850d335bae26c615 (diff)
downloadgitlab-ce-bf05a7c6cbac0242fa661299cb0e3bc011adbf6e.tar.gz
Merge branch 'zj-real-time-pipelines' into 25226-realtime-pipelines-fe
* zj-real-time-pipelines: Minimal change to represent groups for Pipeline Graph
-rw-r--r--app/serializers/base_serializer.rb4
-rw-r--r--app/serializers/jobs_serializer.rb53
-rw-r--r--app/serializers/stage_entity.rb5
-rw-r--r--lib/gitlab/ci/status/group/common.rb21
-rw-r--r--lib/gitlab/ci/status/group/factory.rb13
5 files changed, 94 insertions, 2 deletions
diff --git a/app/serializers/base_serializer.rb b/app/serializers/base_serializer.rb
index 311ee9c96be..37e5a7bf168 100644
--- a/app/serializers/base_serializer.rb
+++ b/app/serializers/base_serializer.rb
@@ -1,4 +1,6 @@
-class BaseSerializer
+class BaseSerializer
+ attr_reader :request
+
def initialize(parameters = {})
@request = EntityRequest.new(parameters)
end
diff --git a/app/serializers/jobs_serializer.rb b/app/serializers/jobs_serializer.rb
new file mode 100644
index 00000000000..efb7d82206a
--- /dev/null
+++ b/app/serializers/jobs_serializer.rb
@@ -0,0 +1,53 @@
+class JobsSerializer < BaseSerializer
+ Item = Struct.new(:name, :size, :list)
+
+ entity BuildEntity
+
+ def with_groups
+ tap { @groups = true }
+ end
+
+ def groups?
+ @groups
+ end
+
+ def represent(resource, opts = {})
+ if groups?
+ groups(resource).map do |item|
+ { name: item.name,
+ size: item.size,
+ list: super(item.list, opts),
+ status: represent_status(item.status) }
+ end
+ else
+ super(resource, opts)
+ end
+ end
+
+ private
+
+ def represent_status(list, opts = {})
+ # TODO: We don't really have a first class concept
+ # for JobsGroup that would make it possible to have status for that
+ detailed_status =
+ if group_jobs.one?
+ group_jobs.first.detailed_status(request.user)
+ else
+ Gitlab::Ci::Status::Group::Factory
+ .new(CommitStatus.where(id: group_jobs), request.user)
+ .fabricate!
+ end
+
+ StatusEntity
+ .represent(resource, opts.merge(request: @request))
+ .as_json
+ end
+
+ def groups(resource)
+ items = resource.sort_by(&:sortable_name).group_by(&:group_name)
+
+ items.map do |group_name, group_jobs|
+ Item.new(group_name, group_jobs.size, group_jobs)
+ end
+ end
+end
diff --git a/app/serializers/stage_entity.rb b/app/serializers/stage_entity.rb
index 5018966b248..35245ae978e 100644
--- a/app/serializers/stage_entity.rb
+++ b/app/serializers/stage_entity.rb
@@ -26,7 +26,10 @@ class StageEntity < Grape::Entity
format: :json)
end
- expose :builds, as: :jobs, using: BuildEntity
+ expose :jobs do |stage|
+ JobsSerializer.new(project: request.project, user: request.user)
+ .with_groups.represent(stage.statuses)
+ end
private
diff --git a/lib/gitlab/ci/status/group/common.rb b/lib/gitlab/ci/status/group/common.rb
new file mode 100644
index 00000000000..cfd4329a923
--- /dev/null
+++ b/lib/gitlab/ci/status/group/common.rb
@@ -0,0 +1,21 @@
+module Gitlab
+ module Ci
+ module Status
+ module Group
+ module Common
+ def has_details?
+ false
+ end
+
+ def details_path
+ nil
+ end
+
+ def has_action?
+ false
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/status/group/factory.rb b/lib/gitlab/ci/status/group/factory.rb
new file mode 100644
index 00000000000..d118116cfc3
--- /dev/null
+++ b/lib/gitlab/ci/status/group/factory.rb
@@ -0,0 +1,13 @@
+module Gitlab
+ module Ci
+ module Status
+ module Group
+ class Factory < Status::Factory
+ def self.common_helpers
+ Status::Group::Common
+ end
+ end
+ end
+ end
+ end
+end