diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/pipelines_controller.rb | 4 | ||||
-rw-r--r-- | app/finders/pipelines_finder.rb | 9 | ||||
-rw-r--r-- | app/graphql/gitlab_schema.rb | 3 | ||||
-rw-r--r-- | app/graphql/resolvers/concerns/resolves_pipelines.rb | 23 | ||||
-rw-r--r-- | app/graphql/resolvers/merge_request_pipelines_resolver.rb | 16 | ||||
-rw-r--r-- | app/graphql/resolvers/project_pipelines_resolver.rb | 11 | ||||
-rw-r--r-- | app/graphql/types/ci/pipeline_status_enum.rb | 9 | ||||
-rw-r--r-- | app/graphql/types/ci/pipeline_type.rb | 31 | ||||
-rw-r--r-- | app/graphql/types/merge_request_type.rb | 6 | ||||
-rw-r--r-- | app/graphql/types/permission_types/ci/pipeline.rb | 11 | ||||
-rw-r--r-- | app/graphql/types/project_type.rb | 5 |
11 files changed, 124 insertions, 4 deletions
diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index 768595ceeb4..45cef123c34 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -13,7 +13,7 @@ class Projects::PipelinesController < Projects::ApplicationController def index @scope = params[:scope] @pipelines = PipelinesFinder - .new(project, scope: @scope) + .new(project, current_user, scope: @scope) .execute .page(params[:page]) .per(30) @@ -178,7 +178,7 @@ class Projects::PipelinesController < Projects::ApplicationController end def limited_pipelines_count(project, scope = nil) - finder = PipelinesFinder.new(project, scope: scope) + finder = PipelinesFinder.new(project, current_user, scope: scope) view_context.limited_counter_with_delimiter(finder.execute) end diff --git a/app/finders/pipelines_finder.rb b/app/finders/pipelines_finder.rb index 0a487839aff..a99a889a7e9 100644 --- a/app/finders/pipelines_finder.rb +++ b/app/finders/pipelines_finder.rb @@ -1,15 +1,20 @@ class PipelinesFinder - attr_reader :project, :pipelines, :params + attr_reader :project, :pipelines, :params, :current_user ALLOWED_INDEXED_COLUMNS = %w[id status ref user_id].freeze - def initialize(project, params = {}) + def initialize(project, current_user, params = {}) @project = project + @current_user = current_user @pipelines = project.pipelines @params = params end def execute + unless Ability.allowed?(current_user, :read_pipeline, project) + return Ci::Pipeline.none + end + items = pipelines items = by_scope(items) items = by_status(items) diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb index de4fc1d8e32..d9f9129d08a 100644 --- a/app/graphql/gitlab_schema.rb +++ b/app/graphql/gitlab_schema.rb @@ -2,7 +2,10 @@ class GitlabSchema < GraphQL::Schema use BatchLoader::GraphQL use Gitlab::Graphql::Authorize use Gitlab::Graphql::Present + use Gitlab::Graphql::Connections query(Types::QueryType) + + default_max_page_size 100 # mutation(Types::MutationType) end diff --git a/app/graphql/resolvers/concerns/resolves_pipelines.rb b/app/graphql/resolvers/concerns/resolves_pipelines.rb new file mode 100644 index 00000000000..9ec45378d8e --- /dev/null +++ b/app/graphql/resolvers/concerns/resolves_pipelines.rb @@ -0,0 +1,23 @@ +module ResolvesPipelines + extend ActiveSupport::Concern + + included do + type [Types::Ci::PipelineType], null: false + argument :status, + Types::Ci::PipelineStatusEnum, + required: false, + description: "Filter pipelines by their status" + argument :ref, + GraphQL::STRING_TYPE, + required: false, + description: "Filter pipelines by the ref they are run for" + argument :sha, + GraphQL::STRING_TYPE, + required: false, + description: "Filter pipelines by the sha of the commit they are run for" + end + + def resolve_pipelines(project, params = {}) + PipelinesFinder.new(project, context[:current_user], params).execute + end +end diff --git a/app/graphql/resolvers/merge_request_pipelines_resolver.rb b/app/graphql/resolvers/merge_request_pipelines_resolver.rb new file mode 100644 index 00000000000..00b51ee1381 --- /dev/null +++ b/app/graphql/resolvers/merge_request_pipelines_resolver.rb @@ -0,0 +1,16 @@ +module Resolvers + class MergeRequestPipelinesResolver < BaseResolver + include ::ResolvesPipelines + + alias_method :merge_request, :object + + def resolve(**args) + resolve_pipelines(project, args) + .merge(merge_request.all_pipelines) + end + + def project + merge_request.source_project + end + end +end diff --git a/app/graphql/resolvers/project_pipelines_resolver.rb b/app/graphql/resolvers/project_pipelines_resolver.rb new file mode 100644 index 00000000000..7f175a3b26c --- /dev/null +++ b/app/graphql/resolvers/project_pipelines_resolver.rb @@ -0,0 +1,11 @@ +module Resolvers + class ProjectPipelinesResolver < BaseResolver + include ResolvesPipelines + + alias_method :project, :object + + def resolve(**args) + resolve_pipelines(project, args) + end + end +end 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..2c12e5001d8 --- /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.to_s + 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..bbb7d9354d0 --- /dev/null +++ b/app/graphql/types/ci/pipeline_type.rb @@ -0,0 +1,31 @@ +module Types + module Ci + class PipelineType < BaseObject + expose_permissions Types::PermissionTypes::Ci::Pipeline + + 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: true + 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 triggering 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 a1f3c0dd8c0..88cd2adc6dc 100644 --- a/app/graphql/types/merge_request_type.rb +++ b/app/graphql/types/merge_request_type.rb @@ -45,5 +45,11 @@ 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 :head_pipeline, Types::Ci::PipelineType, null: true, method: :actual_head_pipeline do + authorize :read_pipeline + end + field :pipelines, Types::Ci::PipelineType.connection_type, + resolver: Resolvers::MergeRequestPipelinesResolver end end diff --git a/app/graphql/types/permission_types/ci/pipeline.rb b/app/graphql/types/permission_types/ci/pipeline.rb new file mode 100644 index 00000000000..942539c7cf7 --- /dev/null +++ b/app/graphql/types/permission_types/ci/pipeline.rb @@ -0,0 +1,11 @@ +module Types + module PermissionTypes + module Ci + class Pipeline < BasePermissionType + graphql_name 'PipelinePermissions' + + abilities :update_pipeline, :admin_pipeline, :destroy_pipeline + end + end + end +end diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb index a832e8b4bde..97707215b4e 100644 --- a/app/graphql/types/project_type.rb +++ b/app/graphql/types/project_type.rb @@ -70,5 +70,10 @@ module Types resolver: Resolvers::MergeRequestResolver do authorize :read_merge_request end + + field :pipelines, + Types::Ci::PipelineType.connection_type, + null: false, + resolver: Resolvers::ProjectPipelinesResolver end end |