summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-06-26 18:31:05 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-06-26 18:31:05 +0200
commit0782eef9db6786509a678e30a51ae43e19aacc75 (patch)
treed336ad11cf1762e9ecb0e05ede24b5f47c8f2b55
parent627236c9edd7f085ec5070ef7fcfbcbfc9b6de78 (diff)
downloadgitlab-ce-bvl-graphql-pipeline-lists.tar.gz
WIP: add pipelines to graphqlbvl-graphql-pipeline-lists
-rw-r--r--app/graphql/types/ci/pipeline_status_enum.rb9
-rw-r--r--app/graphql/types/ci/pipeline_type.rb29
-rw-r--r--app/graphql/types/merge_request_type.rb2
-rw-r--r--spec/support/helpers/graphql_helpers.rb14
4 files changed, 51 insertions, 3 deletions
diff --git a/app/graphql/types/ci/pipeline_status_enum.rb b/app/graphql/types/ci/pipeline_status_enum.rb
new file mode 100644
index 00000000000..5f98e7ed6d9
--- /dev/null
+++ b/app/graphql/types/ci/pipeline_status_enum.rb
@@ -0,0 +1,9 @@
+module Types
+ module Ci
+ class PipelineStatusEnum < BaseEnum
+ ::Ci::Pipeline.all_state_names.each do |state_symbol|
+ value state_symbol.to_s.upcase, value: state_symbol
+ end
+ end
+ end
+end
diff --git a/app/graphql/types/ci/pipeline_type.rb b/app/graphql/types/ci/pipeline_type.rb
new file mode 100644
index 00000000000..4523853ff99
--- /dev/null
+++ b/app/graphql/types/ci/pipeline_type.rb
@@ -0,0 +1,29 @@
+module Types
+ module Ci
+ class PipelineType < BaseObject
+ graphql_name 'Pipeline'
+
+ field :id, GraphQL::ID_TYPE, null: false
+ field :iid, GraphQL::ID_TYPE, null: false
+
+ field :sha, GraphQL::STRING_TYPE, null: false
+ field :before_sha, GraphQL::STRING_TYPE, null: false
+ field :status, PipelineStatusEnum, null: false
+ field :duration,
+ GraphQL::INT_TYPE,
+ null: true,
+ description: "Duration of the pipeline in seconds"
+ field :coverage,
+ GraphQL::FLOAT_TYPE,
+ null: true,
+ description: "Coverage percentage"
+ field :created_at, Types::TimeType, null: false
+ field :updated_at, Types::TimeType, null: false
+ field :started_at, Types::TimeType, null: true
+ field :finished_at, Types::TimeType, null: true
+ field :committed_at, Types::TimeType, null: true
+
+ # TODO: Add user as a type
+ end
+ end
+end
diff --git a/app/graphql/types/merge_request_type.rb b/app/graphql/types/merge_request_type.rb
index d5d24952984..1edadb2aae0 100644
--- a/app/graphql/types/merge_request_type.rb
+++ b/app/graphql/types/merge_request_type.rb
@@ -43,5 +43,7 @@ module Types
field :upvotes, GraphQL::INT_TYPE, null: false
field :downvotes, GraphQL::INT_TYPE, null: false
field :subscribed, GraphQL::BOOLEAN_TYPE, method: :subscribed?, null: false
+
+ field :actual_head_pipeline, Types::Ci::PipelineType, null: true
end
end
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index 0930b9da368..10f123a7dc1 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -59,10 +59,10 @@ module GraphqlHelpers
# We can't guess arguments, so skip fields that require them
next if field.arguments.any?
- if scalar?(field)
- name
- else
+ if nested_fields?(field)
"#{name} { #{all_graphql_fields_for(field_type(field))} }"
+ else
+ name
end
end.compact.join("\n")
end
@@ -85,10 +85,18 @@ module GraphqlHelpers
json_response['data']
end
+ def nested_fields?(field)
+ !scalar?(field) && !enum?(field)
+ end
+
def scalar?(field)
field_type(field).kind.scalar?
end
+ def enum?(field)
+ field_type(field).kind.enum?
+ end
+
def field_type(field)
if field.type.respond_to?(:of_type)
field.type.of_type