diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /app/graphql/types/ci/job_type.rb | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'app/graphql/types/ci/job_type.rb')
-rw-r--r-- | app/graphql/types/ci/job_type.rb | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/app/graphql/types/ci/job_type.rb b/app/graphql/types/ci/job_type.rb index a97e9cee4b1..e77c2a38608 100644 --- a/app/graphql/types/ci/job_type.rb +++ b/app/graphql/types/ci/job_type.rb @@ -7,6 +7,8 @@ module Types class JobType < BaseObject graphql_name 'CiJob' + present_using ::Ci::BuildPresenter + connection_type_class(Types::LimitedCountableConnectionType) expose_permissions Types::PermissionTypes::Ci::Job @@ -25,6 +27,11 @@ module Types description: 'References to builds that must complete before the jobs run.' field :pipeline, Types::Ci::PipelineType, null: true, description: 'Pipeline the job belongs to.' + + field :runner, Types::Ci::RunnerType, null: true, description: 'Runner assigned to execute the job.' + field :runner_manager, ::Types::Ci::RunnerManagerType, null: true, + description: 'Runner manager assigned to the job.', + alpha: { milestone: '15.11' } field :stage, Types::Ci::StageType, null: true, description: 'Stage of the job.' field :status, @@ -76,6 +83,8 @@ module Types description: 'Whether the job has a manual action.' field :manual_variables, ManualVariableType.connection_type, null: true, description: 'Variables added to a manual job when the job is triggered.' + field :play_path, GraphQL::Types::String, null: true, + description: 'Play path of the job.' field :playable, GraphQL::Types::Boolean, null: false, method: :playable?, description: 'Indicates the job can be played.' field :previous_stage_jobs_or_needs, Types::Ci::JobNeedUnion.connection_type, null: true, @@ -86,14 +95,18 @@ module Types description: 'Path to the ref.' field :retried, GraphQL::Types::Boolean, null: true, description: 'Indicates that the job has been retried.' - field :retryable, GraphQL::Types::Boolean, null: false, method: :retryable?, + field :retryable, GraphQL::Types::Boolean, null: false, description: 'Indicates the job can be retried.' + field :scheduled, GraphQL::Types::Boolean, null: false, method: :scheduled?, + description: 'Indicates the job is scheduled.' field :scheduling_type, GraphQL::Types::String, null: true, description: 'Type of job scheduling. Value is `dag` if the job uses the `needs` keyword, and `stage` otherwise.' field :short_sha, type: GraphQL::Types::String, null: false, description: 'Short SHA1 ID of the commit.' field :stuck, GraphQL::Types::Boolean, null: false, method: :stuck?, description: 'Indicates the job is stuck.' + field :trace, Types::Ci::JobTraceType, null: true, + description: 'Trace generated by the job.' field :triggered, GraphQL::Types::Boolean, null: true, description: 'Whether the job was triggered.' field :web_path, GraphQL::Types::String, null: true, @@ -101,10 +114,25 @@ module Types field :project, Types::ProjectType, null: true, description: 'Project that the job belongs to.' + field :can_play_job, GraphQL::Types::Boolean, + null: false, resolver_method: :can_play_job?, + description: 'Indicates whether the current user can play the job.' + + field :failure_message, GraphQL::Types::String, null: true, + description: 'Message on why the job failed.' + + def can_play_job? + object.playable? && Ability.allowed?(current_user, :play_job, object) + end + def kind - return ::Ci::Build unless [::Ci::Build, ::Ci::Bridge].include?(object.class) + return ::Ci::Build unless [::Ci::Build, ::Ci::Bridge].include?(object.build.class) + + object.build.class + end - object.class + def retryable + object.build.retryable? end def pipeline @@ -129,6 +157,10 @@ module Types end end + def trace + object.trace if object.has_trace? + end + def previous_stage_jobs_or_needs if object.scheduling_type == 'stage' Gitlab::Graphql::Lazy.with_value(previous_stage_jobs) do |jobs| @@ -157,6 +189,24 @@ module Types ::Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Stage, object.stage_id).find end + def runner + Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Runner, object.runner_id).find + end + + def runner_manager + BatchLoader::GraphQL.for(object.id).batch(key: :runner_managers) do |build_ids, loader| + plucked_build_to_runner_manager_ids = + ::Ci::RunnerManagerBuild.for_build(build_ids).pluck_build_id_and_runner_manager_id + runner_managers = ::Ci::RunnerManager.id_in(plucked_build_to_runner_manager_ids.values.uniq) + Preloaders::RunnerManagerPolicyPreloader.new(runner_managers, current_user).execute + runner_managers_by_id = runner_managers.index_by(&:id) + + build_ids.each do |build_id| + loader.call(build_id, runner_managers_by_id[plucked_build_to_runner_manager_ids[build_id]]) + end + end + end + # This class is a secret union! # TODO: turn this into an actual union, so that fields can be referenced safely! def id @@ -183,6 +233,10 @@ module Types ::Gitlab::Routing.url_helpers.project_job_path(object.project, object) end + def play_path + ::Gitlab::Routing.url_helpers.play_project_job_path(object.project, object) + end + def browse_artifacts_path ::Gitlab::Routing.url_helpers.browse_project_job_artifacts_path(object.project, object) end |