diff options
Diffstat (limited to 'app/graphql/types/ci')
-rw-r--r-- | app/graphql/types/ci/build_need_type.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/ci/detailed_status_type.rb | 7 | ||||
-rw-r--r-- | app/graphql/types/ci/group_type.rb | 8 | ||||
-rw-r--r-- | app/graphql/types/ci/job_token_scope_type.rb | 16 | ||||
-rw-r--r-- | app/graphql/types/ci/job_type.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/ci/pipeline_type.rb | 3 | ||||
-rw-r--r-- | app/graphql/types/ci/runner_type.rb | 36 | ||||
-rw-r--r-- | app/graphql/types/ci/stage_type.rb | 20 | ||||
-rw-r--r-- | app/graphql/types/ci/status_action_type.rb | 7 |
9 files changed, 84 insertions, 17 deletions
diff --git a/app/graphql/types/ci/build_need_type.rb b/app/graphql/types/ci/build_need_type.rb index 3bd81f8fa8f..19ff758ad1d 100644 --- a/app/graphql/types/ci/build_need_type.rb +++ b/app/graphql/types/ci/build_need_type.rb @@ -7,6 +7,8 @@ module Types class BuildNeedType < BaseObject graphql_name 'CiBuildNeed' + field :id, GraphQL::ID_TYPE, null: false, + description: 'ID of the job we need to complete.' field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the job we need to complete.' end diff --git a/app/graphql/types/ci/detailed_status_type.rb b/app/graphql/types/ci/detailed_status_type.rb index 0b643a6b676..6310a62a103 100644 --- a/app/graphql/types/ci/detailed_status_type.rb +++ b/app/graphql/types/ci/detailed_status_type.rb @@ -6,6 +6,9 @@ module Types class DetailedStatusType < BaseObject graphql_name 'DetailedStatus' + field :id, GraphQL::STRING_TYPE, null: false, + description: 'ID for a detailed status.', + extras: [:parent] field :group, GraphQL::STRING_TYPE, null: true, description: 'Group of the status.' field :icon, GraphQL::STRING_TYPE, null: true, @@ -29,6 +32,10 @@ module Types calls_gitaly: true, description: 'Action information for the status. This includes method, button title, icon, path, and title.' + def id(parent:) + "#{object.id}-#{parent.object.object.id}" + end + def action if object.has_action? { diff --git a/app/graphql/types/ci/group_type.rb b/app/graphql/types/ci/group_type.rb index d6d4252e8d7..3da183cb842 100644 --- a/app/graphql/types/ci/group_type.rb +++ b/app/graphql/types/ci/group_type.rb @@ -6,12 +6,14 @@ module Types class GroupType < BaseObject graphql_name 'CiGroup' + field :id, GraphQL::STRING_TYPE, null: false, + description: 'ID for a group.' field :name, GraphQL::STRING_TYPE, null: true, - description: 'Name of the job group.' + description: 'Name of the job group.' field :size, GraphQL::INT_TYPE, null: true, - description: 'Size of the group.' + description: 'Size of the group.' field :jobs, Ci::JobType.connection_type, null: true, - description: 'Jobs in group.' + description: 'Jobs in group.' field :detailed_status, Types::Ci::DetailedStatusType, null: true, description: 'Detailed status of the group.' diff --git a/app/graphql/types/ci/job_token_scope_type.rb b/app/graphql/types/ci/job_token_scope_type.rb new file mode 100644 index 00000000000..9f48298e1d3 --- /dev/null +++ b/app/graphql/types/ci/job_token_scope_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Types + # rubocop: disable Graphql/AuthorizeTypes + # Authorization is in the resolver based on the parent project + module Ci + class JobTokenScopeType < BaseObject + graphql_name 'CiJobTokenScopeType' + + field :projects, Types::ProjectType.connection_type, null: false, + description: 'Allow list of projects that can be accessed by CI Job tokens created by this project.', + method: :all_projects + end + end + # rubocop: enable Graphql/AuthorizeTypes +end diff --git a/app/graphql/types/ci/job_type.rb b/app/graphql/types/ci/job_type.rb index 5ed4d823aee..360ea3ba7a9 100644 --- a/app/graphql/types/ci/job_type.rb +++ b/app/graphql/types/ci/job_type.rb @@ -56,7 +56,7 @@ module Types field :short_sha, type: GraphQL::STRING_TYPE, null: false, description: 'Short SHA1 ID of the commit.' field :scheduling_type, GraphQL::STRING_TYPE, null: true, - description: 'Type of pipeline scheduling. Value is `dag` if the pipeline uses the `needs` keyword, and `stage` otherwise.' + description: 'Type of job scheduling. Value is `dag` if the job uses the `needs` keyword, and `stage` otherwise.' field :commit_path, GraphQL::STRING_TYPE, null: true, description: 'Path to the commit that triggered the job.' field :ref_name, GraphQL::STRING_TYPE, null: true, diff --git a/app/graphql/types/ci/pipeline_type.rb b/app/graphql/types/ci/pipeline_type.rb index 2eeddaca6ba..f4a6c18f73e 100644 --- a/app/graphql/types/ci/pipeline_type.rb +++ b/app/graphql/types/ci/pipeline_type.rb @@ -150,6 +150,9 @@ module Types description: 'A specific test suite in a pipeline test report.', resolver: Resolvers::Ci::TestSuiteResolver + field :ref, GraphQL::STRING_TYPE, null: true, + description: 'Reference to the branch from which the pipeline was triggered.' + def detailed_status object.detailed_status(current_user) end diff --git a/app/graphql/types/ci/runner_type.rb b/app/graphql/types/ci/runner_type.rb index 837d91ef765..9c5041b0860 100644 --- a/app/graphql/types/ci/runner_type.rb +++ b/app/graphql/types/ci/runner_type.rb @@ -6,6 +6,10 @@ module Types graphql_name 'CiRunner' authorize :read_runner + JOB_COUNT_LIMIT = 1000 + + alias_method :runner, :object + field :id, ::Types::GlobalIDType[::Ci::Runner], null: false, description: 'ID of the runner.' field :description, GraphQL::STRING_TYPE, null: true, @@ -21,22 +25,48 @@ module Types description: 'Indicates the runner is allowed to receive jobs.' field :status, ::Types::Ci::RunnerStatusEnum, null: false, description: 'Status of the runner.' - field :version, GraphQL::STRING_TYPE, null: false, + field :version, GraphQL::STRING_TYPE, null: true, description: 'Version of the runner.' field :short_sha, GraphQL::STRING_TYPE, null: true, description: %q(First eight characters of the runner's token used to authenticate new job requests. Used as the runner's unique ID.) - field :revision, GraphQL::STRING_TYPE, null: false, + field :revision, GraphQL::STRING_TYPE, null: true, description: 'Revision of the runner.' field :locked, GraphQL::BOOLEAN_TYPE, null: true, description: 'Indicates the runner is locked.' field :run_untagged, GraphQL::BOOLEAN_TYPE, null: false, description: 'Indicates the runner is able to run untagged jobs.' - field :ip_address, GraphQL::STRING_TYPE, null: false, + field :ip_address, GraphQL::STRING_TYPE, null: true, description: 'IP address of the runner.' field :runner_type, ::Types::Ci::RunnerTypeEnum, null: false, description: 'Type of the runner.' field :tag_list, [GraphQL::STRING_TYPE], null: true, description: 'Tags associated with the runner.' + field :project_count, GraphQL::INT_TYPE, null: true, + description: 'Number of projects that the runner is associated with.' + field :job_count, GraphQL::INT_TYPE, null: true, + description: "Number of jobs processed by the runner (limited to #{JOB_COUNT_LIMIT}, plus one to indicate that more items exist)." + + def job_count + # We limit to 1 above the JOB_COUNT_LIMIT to indicate that more items exist after JOB_COUNT_LIMIT + runner.builds.limit(JOB_COUNT_LIMIT + 1).count + end + + # rubocop: disable CodeReuse/ActiveRecord + def project_count + BatchLoader::GraphQL.for(runner.id).batch(key: :runner_project_count) do |ids, loader, args| + counts = ::Ci::Runner.project_type + .select(:id, 'COUNT(ci_runner_projects.id) as count') + .left_outer_joins(:runner_projects) + .where(id: ids) + .group(:id) + .index_by(&:id) + + ids.each do |id| + loader.call(id, counts[id]&.count) + end + end + end + # rubocop: enable CodeReuse/ActiveRecord end end end diff --git a/app/graphql/types/ci/stage_type.rb b/app/graphql/types/ci/stage_type.rb index 1be9e3192a9..ce3edb6c54f 100644 --- a/app/graphql/types/ci/stage_type.rb +++ b/app/graphql/types/ci/stage_type.rb @@ -6,22 +6,21 @@ module Types graphql_name 'CiStage' authorize :read_commit_status - field :name, - type: GraphQL::STRING_TYPE, - null: true, + field :id, GraphQL::ID_TYPE, null: false, + description: 'ID of the stage.' + field :name, type: GraphQL::STRING_TYPE, null: true, description: 'Name of the stage.' - field :groups, - type: Ci::GroupType.connection_type, - null: true, + field :groups, type: Ci::GroupType.connection_type, null: true, extras: [:lookahead], description: 'Group of jobs for the stage.' - field :detailed_status, Types::Ci::DetailedStatusType, - null: true, + field :detailed_status, Types::Ci::DetailedStatusType, null: true, description: 'Detailed status of the stage.' - field :jobs, Ci::JobType.connection_type, - null: true, + field :jobs, Ci::JobType.connection_type, null: true, description: 'Jobs for the stage.', method: 'latest_statuses' + field :status, GraphQL::STRING_TYPE, + null: true, + description: 'Status of the pipeline stage.' def detailed_status object.detailed_status(current_user) @@ -54,6 +53,7 @@ module Types # rubocop: disable CodeReuse/ActiveRecord def jobs_for_pipeline(pipeline, stage_ids, include_needs) results = pipeline.latest_statuses.where(stage_id: stage_ids) + results = results.preload(:project) results = results.preload(:needs) if include_needs results.group_by(&:stage_id) diff --git a/app/graphql/types/ci/status_action_type.rb b/app/graphql/types/ci/status_action_type.rb index 9f7299c0270..a06b09735b3 100644 --- a/app/graphql/types/ci/status_action_type.rb +++ b/app/graphql/types/ci/status_action_type.rb @@ -5,6 +5,9 @@ module Types class StatusActionType < BaseObject graphql_name 'StatusAction' + field :id, GraphQL::STRING_TYPE, null: false, + description: 'ID for a status action.', + extras: [:parent] field :button_title, GraphQL::STRING_TYPE, null: true, description: 'Title for the button, for example: Retry this job.' field :icon, GraphQL::STRING_TYPE, null: true, @@ -17,6 +20,10 @@ module Types field :title, GraphQL::STRING_TYPE, null: true, description: 'Title for the action, for example: Retry.' + def id(parent:) + "#{parent.parent.object.object.class.name}-#{parent.object.object.id}" + end + def action_method object[:method] end |